#ironbeard_code

1 messages ¡ Page 1 of 1 (latest)

hot pollenBOT
#

👋 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/1449038816710230167

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

glad oasis
#
  1. The docs say "If iDEAL or Afterpay/Clearpay fail to authorize the payment, Stripe redirects the user to your return_url, and the SetupIntent has a status of requires_payment_method. In this case, attempt to recollect payment from the user." Question: If my return_url goes to the "Review your order" page, does this mean I should check the SetupIntent to see if it has requires_payment_method and redirect back to the step that collects payment info (e.g. the step that displays the PaymentElement) so they can try another method? Is it clear to the customer an error occured?
#
  1. The docs also say "The stripe.confirmSetup might take several seconds to complete. During that time, disable your form from being resubmitted and show a waiting indicator, such as a spinner. If you receive an error result, show this error to the user, re-enable the form, and hide the waiting indicator." Question: do I really need to wrap a <form> around the PaymentElement? The form isn't actually being used to submit any data to my server, since .confirmSetup() just does a redirect. This step of the process is for adding a PaymentMethod to the Customer object that was created in the previous step; I see no reason for this endpoint to accept a POST. 🤔
agile cypress
#

Hi there! For the return_url, your approach sounds correct. The return_url should have the SetupIntent ID in the query params so you can check the requires_payment_method, and if it's required, you can either redirect or add a link for the user to collect payment info with an explanation. The implementation is up to you.

For wrapping the PaymentElement in a form, I believe the docs are simply stating that the ability to submit needs to be disabled. So if it's in a form, you would disable the form to make sure a user can't submit multiple times during the async process. If you don't use a form, then you need to make sure whatever button is disabled, whether through your HTML or through JS.

glad oasis
#

Gotcha, but if I want confirmSetup to handle any extra steps (that are frankly out of my abilities to handle), I have to let it handle the redirect right? There's no way to somehow submit setupintent or payment method info in a form POST after .confirmSetup() has been run, right?

agile cypress
#

Can you clarify your use case a bit? What is your intended flow, and what extra steps are you concerned about?

glad oasis
#
  • Endpoint: /checkout/signup/
    • GET: Display email+password form
    • POST: Create User in db, redirect
  • Endpoint: /checkout/info/
    • GET: Display contact info form
    • POST: Create Customer on Stripe (API call #1, Python), redirect
  • Endpoint: /checkout/payment/
    • GET: Create SetupIntent on Stripe (API call #2, Python), pass client secret to frontend
    • Front End:
      • call stripe.elements(clientSecret=..., currency='usd', appearance: ...)
      • let customer fill in
      • no form, just have a button that has an onclick that runs elements.confirmSetup with confirmParams = {return_url: ...} (API call #3, JavaScript)
  • Endpoint: /checkout/review/
    • GET:
      • si = stripe.SetupIntent.retrieve(setup_intent_id, expand=['payment_method']) (API call #4, Python)
      • save PaymentMethod summary info in local db, send to front end for reviewing
    • POST:
      • Create Subscriptions (possibly two) with customer and payment_behavior=allow_incomplete, off_session=True, default_payment_method. (API call #5, Python)
      • Redirect to /checkout/done
#

The "extra steps" are like 3D Secure or anything that Stripe needs to do to confirm the payment method with the customer before continuing, like redirect to a bank website (i don't know anything about this stuff, I'm just letting stripe handle the extra auth).

#

I guess I'm thinking "no reason to have a form on /checkout/payment/ or allow POST there if I can't actually obtain PaymentMethod data (like card_last4, payment_method_id, etc) to fill in a form to POST to the server.. since stripe is just doing a redirect to return_url.

I think I need to use the setupintent id from the return_url GET to retrieve the setupintent (with expand=['payment_method'] to get payment method details to show the customer on the "Review Order" page

agile cypress
#

Gotcha. You're correct, Stripe handles those steps (redirecting to the bank website, 3DS, etc.). You are sometimes responsible for responding to things like 3DS failures depending on the situation (this doc describes that specific situation https://docs.stripe.com/billing/subscriptions/overview#requires-action).

I think I need to use the setupintent id from the return_url GET to retrieve the setupintent (with expand=['payment_method'] to get payment method details to show the customer on the "Review Order" page

Yes, this is correct.

glad oasis
#

so on a GET of /checkout/review/ (typically come as a result of return_url), I fetch the (confirmed) SetupIntent+PaymentMethod an examine setup_intent.status. Is it only requires_payment_method that I need to handle specifically, or are there other values that I should handle with this flow

agile cypress
#

That should be it. Most payment methods don't require a redirect for authorization, so it's only the ones that do (like iDeal, Afterpay/Clearpay, etc.) needs to check the setup intent from the return_url. For payment methods that don't require a redirect, the error will be returned directly, which you would handle differently:
https://docs.stripe.com/js/setup_intents/confirm_setup

If the authorization fails, the Promise resolves with an {error} object that describes the failure. If the error type is either card_error or validation_error, directly display the error message in error.message to your user. If the error type is `invalid_request_error, you might have an invalid request or 3DS authentication failures.

glad oasis
#

Gotcha! I think my last question is: do Bank Transfer or ACH Credit require a redirect?

agile cypress
glad oasis
#

dope. thanks so much, y'all are the best! ❤️

agile cypress
#

No problem, glad to help out!

glad oasis
#

ughhh wait sorry.

So if I'm not accepting any PMs that require redirect, then if I don't pass return_url, can I obtain paymentmethod info (payment_method_id, etc) from the result of stripe JS call to .confirmIntent() (and POST that to my server, so I don't have to make an additional query on the GET of /checkout/review to obtain the setup intent (with expanded PaymentMethod)

#

(I didn't realize that the popup login for ACH bank transfers is different than a redirect).

agile cypress
#

That sounds right. If you do this, you need to set the redirect parameter to if_required
https://docs.stripe.com/js/setup_intents/confirm_setup#confirm_setup_intent-options-redirect

By default, stripe.confirmSetup will always redirect to your return_url after a successful confirmation. If you set redirect: "if_required", then stripe.confirmSetup will only redirect if your user chooses a redirect-based payment method.

Note: Setting if_required requires that you handle successful confirmations for redirect-based and non-redirect based payment methods separately. When a non-redirect based payment method is successfully confirmed, stripe.confirmSetup will resolve with a {setupIntent} object.

glad oasis
#

but what kind of object does confirmSetup() return in that instance? does it include PM info?

#

oh duh

#

sorry, does the setupIntent object contain PM info?

agile cypress
glad oasis
#

so I couldn't expand it, correct?

#

(to get e.g. card_last4 or some other summary info to store in my db to show on the /checkout/review/ page)

agile cypress
glad oasis
#

❤️ you're the best.

agile cypress
#

(I actually just figured that out now, didn't know about it before)

glad oasis
#

hooray for learning! Okay, time to get busy. Have a great day!