Jazzbot
Jazzbot

Reputation: 385

Laravel - Stripe Subscription based on Quantity / variable subscription amount

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.

Upvotes: 1

Views: 2597

Answers (3)

Jazzbot
Jazzbot

Reputation: 385

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.

Upvotes: 0

oseintow
oseintow

Reputation: 7421

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

Upvotes: 4

Ywain
Ywain

Reputation: 17553

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

Upvotes: 1

Related Questions