#adr_best-practices

1 messages ยท Page 1 of 1 (latest)

young yachtBOT
#

๐Ÿ‘‹ 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.

true gulch
#

Can you share your Stripe.js code?

unborn crest
#

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',
}
true gulch
#

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

unborn crest
#

we would like to list the payment methods manually, and have different behavior based on the payment method

true gulch
#

Then you'd update the intent/Elements instance based on the selected PM and the desired capture method

unborn crest
#

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

true gulch
#

Yep, as I said you need to know ahead of time the desired capture method so that the Element can display supported PMs

unborn crest
#

so it's not possible to have a different capture method based on the selected payment method?

true gulch
#

There is not no

unborn crest
#

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?

true gulch
#

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

unborn crest
#

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 ๐Ÿ˜…

true gulch
#

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

unborn crest
#

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

true gulch
#

Not sure why you call createPaymentMethod then?

unborn crest
#

well, the capture method gets in the way if we use the elements to confirm the payment intent

true gulch
#

At what stage are you creating the intent? Before you intiailise Elements?

unborn crest
#

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
true gulch
#

What's the error that the confirmation throws?

unborn crest
#

just a moment, let me reproduce, I don't have it on hand

true gulch
#
paymentMethodTypes: ['card', 'us_bank_account']

So this is set dynamically based on some logic you have?

unborn crest
#

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

unborn crest
#

req_GIRBeezN4BXCvy

true gulch
#

Can get the selected PM type there

unborn crest
#

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

true gulch
#

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

#

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

unborn crest
#

I see, basically, we should be able to update the elements to the desired capture method just before calling the confirmPayment?

true gulch
#

Yes, exactly

#

I think that should work as you need, but let us know

unborn crest
#

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

true gulch
#

No problem, glad I could help!