#ironbeard_integration-questions
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/1448697272501141668
๐ 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.
- ironbeard_code, 21 hours ago, 37 messages
Hi ๐ maybe it got cut off, but I don't see a question here. What are you looking for assistance with?
oh, it did: one second
Checkout Flow
- Endpoint: /checkout/signup/
- GET: Display email+password form
- POST: Create User in db, redirect to next
- Endpoint: /checkout/info/
- GET: Display contact info form
- POST: Create Customer on Stripe, redirect to next
- Endpoint: /checkout/payment/
- GET: Create SetupIntent, pass client secret to frontend
- frontend: call stripe.elements(clientSecret=..., currency='usd', appearance: ...)
- POST:
- preventDefault on form submit,
- call elements.confirmSetup with confirmParams = {return_url: 'https://www.example.com/checkout/review/'}
- Endpoint: /checkout/review/
- GET: Create Subscriptions (possibly two) with customer.
- Questions: What do I do with the setup_intent and setup_intent_client_secret that got passed as URL params? Do I pass these to stripe.Subscription.create? I don't want to charge yet.
- POST: (User has confirmed the review and charges should happen). What do I do on the backend to actually pay for the Subscriptions?
- GET: Create Subscriptions (possibly two) with customer.
Questions are in the GET and POST of the final endpoint
You don't pass the Setup Intent information to the Subscription. You'd use the resulting Payment Method that the Setup Intent created. If you only want to use the Payment Method for the current Subscription(s) you're creating, then you probably want to set it as the default_payment_method when creating the Subscription.
If you don't want to charge right away, then you'll want to use payment_behavior set to default_incomplete.
https://docs.stripe.com/api/subscriptions/create#create_subscription-payment_behavior
After review you can confirm the Payment Intent for the first Invoice's payment to attempt the charge.
Okay, so how do I get the payment method id from a setup intent?
After you confirm the Setup Intent, it's payment_method field gets populated with the ID of the generated Payment Method.
๐ค
form.addEventListener('submit', async (event) => {
event.preventDefault();
const { error } = await stripe.confirmSetup({
elements,
confirmParams: {
return_url: window.location.origin + "{{ next_url }}",
}
})
if (error) {
console.log(error)
} else {
// Your customer will be redirected to your `return_url`. For some payment
// methods like iDEAL, your customer will be redirected to an intermediate
// site first to authorize the payment, then redirected to the `return_url`.
}
})
I'm calling confirmSetup on the front end, right? and it redirects to the next step. Is there something in the return value of stripe.confirmSetup that allows me to send the payment method id to my backend?
(where form var is the <form> that contains the PaymentElement)
Hm, I don't think so, because the redirect will happen before you get anything back from confirmSetup. Will you have the ID of the Setup Intent handy? You could pass that and have your backend retrieve the Setup Intent to find its payment_method.
(oh, I can call stripe.SetupIntent.retrieve(setup_intent_id) on my backend, which contains a payment_method key)
yeah, gotcha. The redirect does include the setup_intent_id in the URL params.
Ah, even better! (I was too slow spinning up a test to confirm that theory ๐ )
So the last bit would be:
- Endpoint: /checkout/review/
- GET:
- payment_method_id = stripe.SetupIntent.retrieve(setup_intent_id).payment_method
- create Subscriptions with
payment_behavior: default_incompleteanddefault_payment_method: payment_method_idon backend - display summary on front end
- POST:
- on the backend, how do I confirm the PaymentIntent? or do I do it on the front end?
- GET:
I would do it client-side, so if anything needs to be completed by the customer (like a 3DS challenge) they can handle that.
Wait
you already did that
sorry, my brain failed me for a moment
Yeah, confirm server-side:
https://docs.stripe.com/api/payment_intents/confirm
with off_session set to true
Do you already know how to get to the ID of that intent?
Actually, on the review page I want to display payment method info, so on the /checkout/review/ GET, can I do si = stripe.SetupIntent.retrieve(setup_intent_id, expand=['payment_method'])?
And then create the Subscriptions on the backend with the info from the expanded payment_method. Display all this to the user on the front end.
When I create the Subscription, I can do expand=[latest_invoice.payment_intent] and store that locally so that when the customer clicks "Submit" I can call PaymentIntent.confirm.
You should be able to expand the payment_method to get some details back, but you won't need (or be able) to pass those details when creating the Subscription. You will still just use the Payment Method ID.
Hm, I'm thinking through whether I would rework this completely to use Confirmation Tokens instead, if you want payment method info as well. Don't think they're a good fit here, they won't handle any customer action that are needed like Setup Intents do.
I just ned the details of the payment_method to show the customer on the review page (like last 4, etc)
Actually. I could wait until the confirm of /review/ to create the Subscriptions and don't do default_incomplete, right? Then I wouldn't need to separately confirm the PaymentIntent
lemme post a new flow one sec
Oh, good idea, as long as you don't need info from the Subscription for the review page.
Checkout Flow
- 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: ...)
- POST:
- preventDefault on form submit,
- elements.confirmSetup with confirmParams = {return_url: ...} (API call #3, JavaScript)
- Endpoint: /checkout/review/
- GET:
- si = stripe.SetupIntent.confirm(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 default_payment_method. Do NOT specify default_incomplete. (API call #5, Python)
- This should automatically confirm the payment intent, right?
- Redirect to /checkout/done
- GET:
yeah, the info from the subscription is probably all saved in my cart really. The items, cost, etc.
although, I suppose in the case of someone upgrading, I might want the latest invoice to display since it shows prorations ๐ค but that would be a different situation since the Customer would already have a Subscription.
Endpoint: /checkout/review/
GET:
si = stripe.SetupIntent.confirm(setup_intent_id, expand=['payment_method']) (API call #4, Python)
Should be stripe.SetupIntent.retrieve since the intent was already confirmed.
This should automatically confirm the payment intent, right?
Yup, defaultpayment_behaviorisallow_incomplete, which immediately attempts payment and returns anincompleteSubscription if the first payment requires customer action.
When creating the Subscriptions, I'd also suggest using off_session set to true.
great, thanks! You've always been very helpful. Hope you have a wonderful day!
Thanks, I hope you do the same!
ironbeard_integration-questions