#adr_best-practices
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/1326140530282987571
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Can you share your Stripe.js code?
what would be relevant for the question?
this is how we confirm the payment intent:
const confirmationResult = await stripe.confirmPayment({
elements,
clientSecret,
confirmParams: {
//we need to set this, but we won't redirect upon successful confirmation
return_url: 'https://www.1stdibs.com/',
},
redirect: 'if_required',
});
and this is the relevant elements configuration:
{
paymentMethodTypes: ['card', 'us_bank_account'],
mode: 'payment',
amount,
currency,
paymentMethodCreation: 'manual',
}
The Element will dynamically surface available PMs according to the settings on the intent or the config you pass wen initialising it. If you change that param, then the available PMs will reflect that
we would like to list the payment methods manually, and have different behavior based on the payment method
Then you'd update the intent/Elements instance based on the selected PM and the desired capture method
it seems, that if we want to, for example, have the US bank account available, the capture method needs to be set to "automatic", when we want it to be "manual" if the credit card is selected
there is no per-payment method setting
we are able to create the payment intent with the capture method we want, but confirming it can throw an error if the Payment Element had a different capture method set
Yep, as I said you need to know ahead of time the desired capture method so that the Element can display supported PMs
so it's not possible to have a different capture method based on the selected payment method?
There is not no
I see, thank you, could you also clarify something related? I was able to create a payment method using the Payment Element:
const result = await stripe.createPaymentMethod({
elements,
params: {
billing_details: {
// ...
},
},
});
and then later, when the payment intent is created in the back-end, this seemed to work, even though, the capture method was different in the Payment Element:
const confirmationResult = await stripe.confirmPayment({
clientSecret,
confirmParams: {
return_url: 'https://www.1stdibs.com/',
payment_method: paymentMethodToken,
},
redirect: 'if_required',
});
basically, the elements instance was not used to confirm the intent, and the created payment method didn't "remember" the capture method. is this something you'd recommend against doing?
Yes a PM object (created via createPaymentMethod) won't contain tertiary data from the Elements instance like capture method, etc. The capture method is set at the intent level so you'd need to update the PI directly
do you know if a payment method created this way can always be used to confirm a payment intent, or is it possible to run into a scenario where this doesn't work? we're planning on enabling other payment methods like klarna and iDEAL as well
I guess I'm asking if it's a good idea to go around the capture method issue this way ๐
Well assuming the PM creation is successful and the intent parameters (currency etc) fit the eligibility for the PM type (i.e. iDEAL is EUR) then the API request should succeed yes
Also be mindful that the createPaymentMethod function is just a way to tokenise payment info. It doesn't handle authentication required for some PMs so when you attempt confirmation of the intent in the backend it'll likely transition to requires_action
yes, we're calling the confirmPayment in the client, so stuff like 3DS challenges are presented to the user, so I think we're good on that
Not sure why you call createPaymentMethod then?
well, the capture method gets in the way if we use the elements to confirm the payment intent
At what stage are you creating the intent? Before you intiailise Elements?
it is after, when we're ready to confirm the payment. the flow is something like this:
- the user selects a payment method, the stripe form is validated. we have custom logic for which payment methods to show
- the user confirms the transaction, we create the payment intent in the BE based on the transaction status
- we use the payment intent returned from BE to confirm the payment intent on the client, the user authenticates if necessary
- BE then continues with the transaction confirmation
What's the error that the confirmation throws?
just a moment, let me reproduce, I don't have it on hand
paymentMethodTypes: ['card', 'us_bank_account']
So this is set dynamically based on some logic you have?
yes
this is the error: "The provided capture_method (manual) does not match the expected capture_method (automatic). Try confirming with a Payment Intent that is configured to use the same parameters as Stripe Elements."
the "manual" capture method was used when creating the payment intent in the BE, but the elements have it set to "automatic" so the US bank accounts could be displayed
Can you share the req_xxx?
req_GIRBeezN4BXCvy
Yes, you'd need to update capture_method on the intent. You could probably fire a call to do that server-side if you listen for the change event: https://docs.stripe.com/js/element/events/on_change?type=paymentElement#element_on_change-event
Can get the selected PM type there
the problem is, we want the capture method to be "manual" for credit cards
but setting it to "manual" on the Element understandably doesn't work with US bank account PM
Right, but if the user clicks 'pay' at that point you create the intent so you know what PM they've selected in the UI and you can set capture_method accordingly on the creation
Yes, so as I said you'd update the Elements instance too to reflect the manual requirement for cards: https://docs.stripe.com/js/elements_object/update#elements_update-options-captureMethod
If they click 'pay', you can update the Element instance to reflect the capture method and then set capture_method on the intent creation to mirror that
Then you can also remove the manual PM creation part
I see, basically, we should be able to update the elements to the desired capture method just before calling the confirmPayment?
ok, thank you, I'll try doing it that way
yes, the change might be a bit complicated because of our current setup, but I'll get back here if I have any more problems
thank you, this was very helpful
No problem, glad I could help!