#nerder_api
1 messages ¡ Page 1 of 1 (latest)
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1352268411312406603
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- nerder_webhooks, 6 days ago, 29 messages
hey there, taking a look at this request
Ok, so this is erroring because you specified payment_behavior: "error_if_incomplete",
and the error message indicates how you can complete the payment:
code: "subscription_payment_intent_requires_action",
message: "Payment for this subscription requires additional user action before it can be completed successfully. Payment can be completed using the PaymentIntent associated with `subscription.latest_invoice`. Additional information is available here: https://stripe.com/docs/billing/subscriptions/overview#requires-action",
Yes, I just wanted to understand a bit how this flow is supposed to work
I'll intercept this error in the client and then prompt the user to authenticated the payment using the client secret of the last invoice?
So you would retrieve the subscription's latest invoice payment intent and you would use the client_secret there to handle the payment in your app with Stripe.js, using for example stripe.handleNextAction()
Assuming the payment intent is in the requires_action state for a card 3ds flow, it would trigger the 3ds authentication sequence
You can try this out in test mode using our "always authenticate" test card
4000002760003184
https://docs.stripe.com/testing#authentication-and-setup
- The customer will attempt to upgrade their subscription and the API will fail with a 402 with the code
subscription_payment_intent_requires_action - I'll catch this exception in my backend and I'll return the
client_secretcontained intosubscription.latest_invoice - The frontend will take the
client_secretand invokehandleNextAction - The customer is prompted the 3DS secure screen to authorize this payment
- When the payment completed the subscription is updated
- We handle
invoice.paidand update the subscription accordingly in our DB
Is this the correct course of action?
Only small question, subscription.latest_invoice is referring to which subscription? The existing?
Yes that sounds like the right sequence, but i strongly recommend testing this in test mode to validate you get the results you're expecting.
Of course
Yes, this is referring to retrieving the subscription you updated
You can optionally use expansion to get the invoice & payment intent in one request:
expand[]=latest_invoice.payment_intent when you retrieve the subscription
https://stripe.com/docs/expand
Nice
Ok so updating my TODO:
- The customer will attempt to upgrade their subscription and the API will fail with a 402 with the code
subscription_payment_intent_requires_action - I'll catch this exception in my backend and and I fetch the active subscription using
expand: [latest_invoice.payment_intent]to retrieve theclient_secretfrom it - The frontend will take the
client_secretand invokehandleNextAction - The customer is prompted the 3DS secure screen to authorize this payment
- When the payment completed the subscription is updated
- We handle
invoice.paidand update the subscription accordingly in our DB
Your error_if_incomplete might be blocking the subscription from actually changing, so I think you'll need to update that to either allow_incomplete or pending_if_incomplete to get to the payment authentication step
https://docs.stripe.com/api/subscriptions/update#update_subscription-payment_behavior
Because they way you have it now, the error blocks a new invoice from being generated
Note that using the pending flow, which defers the actual subscription changes like it sounds like you want, has some restrictions on parameters you can pass
umm ok
The default behaviour would be to update the subscription immediately, and the new invoice is in a requires_action state that you need to resolve
so basically i need to use the pending_if_incomplete so that the prorated amount generate an invoice and the subscription changes
but then if the payment does not resolve how do I revert back?
if you using the pending updates approach, the subscription is not actually changed until payment succeeds
If you want to cancel the pending change, you can void the open invoice: https://docs.stripe.com/billing/subscriptions/pending-updates#canceling-changing
If you dont use the pending updates approach, then the subscription will update and reverting the change is something you'll need to reconcile manually, with another subscription update