#nerder_api

1 messages ¡ Page 1 of 1 (latest)

trail smeltBOT
#

👋 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.

quick wave
#

hey there, taking a look at this request

tranquil locust
#

hey

#

thx

quick wave
#

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",
tranquil locust
#

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?

quick wave
#

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()

tranquil locust
#

oh ok

#

what handleNextAction do?

quick wave
#

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

tranquil locust
#

ok!

#

So let me rephrase to see if I've understand correctly

quick wave
tranquil locust
#
  1. The customer will attempt to upgrade their subscription and the API will fail with a 402 with the code subscription_payment_intent_requires_action
  2. I'll catch this exception in my backend and I'll return the client_secret contained into subscription.latest_invoice
  3. The frontend will take the client_secret and invoke handleNextAction
  4. The customer is prompted the 3DS secure screen to authorize this payment
  5. When the payment completed the subscription is updated
  6. We handle invoice.paid and 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?

quick wave
#

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.

tranquil locust
#

Of course

quick wave
#

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

tranquil locust
#

Nice

#

Ok so updating my TODO:

  1. The customer will attempt to upgrade their subscription and the API will fail with a 402 with the code subscription_payment_intent_requires_action
  2. I'll catch this exception in my backend and and I fetch the active subscription using expand: [latest_invoice.payment_intent] to retrieve the client_secret from it
  3. The frontend will take the client_secret and invoke handleNextAction
  4. The customer is prompted the 3DS secure screen to authorize this payment
  5. When the payment completed the subscription is updated
  6. We handle invoice.paid and update the subscription accordingly in our DB
quick wave
#

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

tranquil locust
#

umm ok

quick wave
#

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

tranquil locust
#

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?

quick wave
#

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