#Ludvid-update-confirm-pi

1 messages ยท Page 1 of 1 (latest)

deft cloud
#

Hey! You can update certain parameters of the Payment Intent when confirming, but amount is not one of them. You'd need to make a separate API call (with your secret key) to update the PI

mortal saddle
#

Well, putting the two api calls right after each other sounds like the solution, is it a good practice to do like this?

deft cloud
#

Are you doing server-side confirmation, or via Stripe.js (with confirmPayment)?

mortal saddle
#

Hmm wait I'll check

deft cloud
#

You should be using Stripe.js - but you linked the API reference for the confirm endpoint (which we don't recommend)

mortal saddle
#

Oh yeah

#

I'm only creating the PI on the server

#

the rest happens with stripe.js I believe

#

Why is it not recommended to confirm over the server? I have seen this:

Always decide how much to charge on the server side, a trusted environment, as opposed to the client. This prevents malicious customers from being able to choose their own prices.

I was thinking that sending a cart object with prices to the server to be evaluated and confirmed at the same time would be a good idea, is it not how it should be done?

deft cloud
#

Yes, you decide how much to charge on the server (when creating the PI - that has to be done server-side)

#

But confirming the PI (to complete the payment) should โ€“ in the majority of cases โ€“ be the integration path

mortal saddle
#

alright, those are valid reasons. So how would I get this functionality with good practices in a custom checkout?

It's basically the same functionality that is in the pre-built checkout when you have line_items.adjustable_quantity set to true.

deft cloud
#
  1. Create your PI on page load with initial amount value (as you are now).
  2. Initialise the Payment Element with the client_secret.
  3. If updates are made (quantity increment/decrement), make a call up update the PI accordingly via your server.
  4. Following an update, you will likely need to teardown the Payment Element instance and initiate a new one (otherwise the new amount value will not be reflecting in some payment UIs - Google Pay etc)
mortal saddle
#

Is this how it has been done in the prebuilt checkout? It doesn't feel good to have to re-render the payment element every time someone updates the cart, am I wrong?

deft cloud
#

Not sure how Checkout implements it โ€“ it's a little different as it's a Stripe hosted solution so we have internal APIs to handle things like that

#

I do know that we're working on an improvement to the Payment Element to improve this workflow

mortal saddle
deft cloud
#

Nothing I can share currently.

#

If this is an issue, then you could have the Payment Element in a different scope/context to the 'checkout' page

mortal saddle
deft cloud
#

Yes, exactly. Then there's not necessarily any need to refresh the Payment Element

mortal saddle
#

Yeah, well it feels like stripe currently is built to be this way.
I hope an improvement soon would enable the functionality I asked about to work

#

listen to cart change -> update stripe amount to pay

deft cloud
#

It's a double edged sword โ€“ we trying to provide the low-level APIs to enable as many of these integration flows as possible without being too specific

mortal saddle
#

Absolutely, this is no easy product to create.

Render an Elements provider at the root of your React app so that it is available everywhere you need it
https://stripe.com/docs/stripe-js/react#elements-provider

Is it fine in my case to ignore this advice and have the <Elements> at the last step when the customer is ready to pay?

(Because the clientSecret won't be created until the cart is final and the payment is the last step)

deft cloud
#

Yes, that's just a recommendation

#

I'd still recommend initialise Stripe.js (loadStripe) at the root so you get the benefits of Radar throughout the site

mortal saddle
#

Could you send me a link as to why/how/what benefits this provide? Don't know anything about Radar and why loadStripe enables this

deft cloud
mortal saddle
#

Thanks for your help ๐Ÿ™‚

deft cloud
#

Sure, np!