1

I have implemented Stripe in a Laravel project. I want to charge the customers monthly but each of them will have to pay different amount. I'm sending them an invoice separately through another system, they will have to enter their invoice number, amount and pay on my website.

Now to charge customers a variable amount, I've come across a solution here: https://support.stripe.com/questions/how-can-i-create-plans-that-dont-have-a-fixed-price

I have form where a customer will enter his invoice number, other details and the amount he wants to pay. Now how can I use this information in stripe form and create a stripe customer like this? I'm not able to get this to work.

Jazzbot
  • 385
  • 1
  • 4
  • 18

3 Answers3

4

The best way to i see to handle variable subscription amount is to create a base plan on stripe for example freePlan and assign an amount of 1 to it.

So if you want to handle variable subcription amount "that is in your case" you will subscribe to this freePlan then increase that amount 1 by your subcription quantity(amount).

For example you want to charge 2 users $10 and $15 respectively. you will

// Let get first user
$user = User::find(1);

// subscribe to free plan which has an amount of one(1)
// and increment the quantity by 10 so in this case he/she will pay 
// $10 every month
$user->subscription('freePlan')->incrementQuantity(10); 

// Lets do same for user 2 
$user = User::find(2);

// subscribe to free plan which has an amount of one(1)
// and increment the quantity by 15 so in this case he/she will pay 
// $15 every month
$user->subscription('freePlan')->incrementQuantity(15); 

or you can choose to use an already created plan example basicPlan or businessPlan and increase or decrease the quantity

// Let say basicPlan is $30 so increasing it by 5 will be 150
$user->subscription('basicPlan')->incrementQuantity(15); 

This link points to stripe on how to set quantities https://stripe.com/docs/subscriptions/guide#setting-quantities

This is link points to laravel on how to increment or decrement quantities https://laravel.com/docs/5.2/billing#subscription-quantity

oseintow
  • 7,221
  • 3
  • 26
  • 31
  • 1
    Changing the quantity on a free plan does nothing: zero times any quantity still equals zero! You'd need to set the plan's amount to a base value like $1 or $0.01 to use that quantity "trick". – Ywain Mar 09 '16 at 16:31
  • Sure i guess you are right. But did it work for you. – oseintow Mar 09 '16 at 16:32
  • I created a plan for $1, followed your method and incremented quantity by 5. I did `$user->subscription('planName')->create($token)` and then `$user->subscription()->increment(5);` (I'm using Laravel 4). Now it is doing increment in quantity but the problem is, its only charging $1 for current month's subscription, does increment afterwards and shows it as due amount for next month. So in this case $1 is charged, $4 (5-1) is due for this month, so next month's due amount will be $9. See this screenshot for stripe invoices: http://awesomescreenshot.com/0515p4on58 – Jazzbot Mar 09 '16 at 16:41
1

It sounds like you simply want to charge the customer for a given amount. You don't need to use Stripe's plans or subscriptions for that, you should simply create a charge.

If you want to collect the customer's card details once and be able to charge them repeatedly without having to ask them to provide their card details again, you should first create a customer using the card token, then create a charge with the customer ID in the customer parameter.

You should check out this tutorial: https://stripe.com/docs/charges#saving-credit-card-details-for-later

Ywain
  • 16,854
  • 4
  • 51
  • 67
  • If I create the customer first, and then charge him the amount what will happen after a month? Will I have to manually charge him after a month? I want the customers to be charged monthly for the amount they've entered. Its just like a monthly subscription plan, just the customers will have to enter the amount they want to pay. So a monthly subscription plan with variable amounts basically. – Jazzbot Mar 09 '16 at 13:11
  • So you want the customer to choose the amount once, then be billed for that amount until the subscription is canceled, is that correct? If so, the simplest way would be to create one plan per customer and subscribe them to their specific plan. I can update my answer with more specific information if you can confirm that's your usecase. – Ywain Mar 09 '16 at 16:29
  • Yes, that is what I'm looking for. Each customer will be billed every month with the amount he chooses until he cancels the subscription. – Jazzbot Mar 09 '16 at 16:45
0

Ok, so I've worked around a solution for this problem. Instead of using Stripe's Quantity or QuantityIncrement() what I've did is created a separate plan for each customer.

Now Laravel Cashier doesn't allow us to create stripe plan programmatically. However, this solution has helped me do this. Although I had to make few changes to get this working in Laravel but I've got this working finally after playing around.

Community
  • 1
  • 1
Jazzbot
  • 385
  • 1
  • 4
  • 18