stripe-payments

Stripe immediate payment on each quantity update


We are using Stripe as the payment gateway, and we have a yearly plan i.e .billing cycle of the plan is 1 year.

Within the billing cycle, the user can update opt for more seats which will result in increasing the quantity for the subscribed plan.

Subscription subscription = Subscription.retrieve(paymentDetails.getSubscriptionId());
int currentQuentity = subscription.getQuantity();
Map<String, Object> updateParams = new HashMap<String, Object>();
updateParams.put("quantity", (currentQuentity + changeInQuantity));
subscription.update(updateParams);

So for any update stripe refunds(if quantity reduces) and charges(if quantity increases) at the end of billing cycle prorated.

In our business logic, we need immediate payment (charges or refunds) on each quantity update rather then on end of billing cycle. Is there any way in the stripe to achieve so.


Solution

  • To charge immediately after subscription update, you need to create an invoice just after the subscription update. This will result in an immediate charge

    To create invoice you can simply call:

    Stripe.apiKey = "sk_test_BQokikJOvBiI2HlWgH4UWQfQ2";
    
    Map<String, Object> invoiceParams = new HashMap<String, Object>();
    invoiceParams.put("customer", "cus_D2XUIsncG7YUX");
    
    Invoice.create(invoiceParams);
    

    Ref (https://stripe.com/docs/api#update_subscription):

    enter image description here