Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a PaymentIntent for a proration caused by a Subscription plan update, before actually modifying the subscription

My subscriptions are set to 'always_invoice' when someone changes subscription plans.

I can easily change the users subscription using their default payment method, and have Stripe automatically charge the card on file. However, during the 'change subscription plans' ​flow I would like to be able to present the user with a PaymentElement form in case they want to make this payment a one-off, with a brand new card.

I need a PaymentIntent clientSecret value to do this, but I can't for the life of me figure out how to get one in this specific situation. The PaymentIntent needs the exact proration calculation stripe makes when you call retrieveUpcomming(invoice) or updateSubscription(). retreiveUpcomming doesn't generate a paymentIntent for obvious reasons, and updateSubscription() is actually trying to modify my subscription before the user has confirmed their new payment method. Even if I turn on 'pending_if_incomplete', stripe is still going to charge the default payment method.

Any help would be much appreciated!

like image 812
douliman Avatar asked Oct 16 '25 04:10

douliman


1 Answers

You'll want to set payment_behavior: default_incomplete [1] when you update the Subscription to not automatically confirm the payment that is created as a result of the update. This should create a new Invoice and an underlying Payment Intent (which you'll use in your PaymentElement form) that you can confirm separately while collecting the new payment information.

One thing you'll want to remember is that after confirmation is successful you'll need to make an additional call to update the Customer and set the new default Payment Method at invoice_settings[default_payment_method] [2] or set it directly on the Subscription at default_payment_method [3].

like image 147
karbi Avatar answered Oct 18 '25 00:10

karbi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!