#Ludvid-update-confirm-pi
1 messages ยท Page 1 of 1 (latest)
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
Well, putting the two api calls right after each other sounds like the solution, is it a good practice to do like this?
Are you doing server-side confirmation, or via Stripe.js (with confirmPayment)?
Hmm wait I'll check
You should be using Stripe.js - but you linked the API reference for the confirm endpoint (which we don't recommend)
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?
For reasons outlined here (at the top): https://stripe.com/docs/payments/accept-a-payment-synchronously
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
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.
- Create your PI on page load with initial
amountvalue (as you are now). - Initialise the Payment Element with the
client_secret. - If updates are made (quantity increment/decrement), make a call up update the PI accordingly via your server.
- Following an update, you will likely need to teardown the Payment Element instance and initiate a new one (otherwise the new
amountvalue will not be reflecting in some payment UIs - Google Pay etc)
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?
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
Is this something you could tell me more about? About when could this be released? Will it enable exactly this functionality to work in a better way?
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
You mean as to set "barriers" or "steps" between the cart and the payment? so that the paymentintent will only be created once the cart is final and the customer is ready to pay?
Yes, exactly. Then there's not necessarily any need to refresh the Payment Element
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
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
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)
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
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
Thanks for your help ๐
Sure, np!