#adamgp
1 messages · Page 1 of 1 (latest)
Hi! hmm. If you're explicitly using the PaymentRequestButton, you don't need a PaymentIntent or a client secret at any point until the final .on("paymentmethod") event that happens when the user finishes their actions in the wallet window , so I don't 100% follow.
Hi Karl, I see what you're saying, and now - trying to identify why we're doing what we're doing...
normally the way you'd integrate with the PaymentRequestButton is when you get that final event, you can confirm a PaymentIntent. That can mean either you have a client secret already available, ideally from first render(the traditional way to use PaymentIntents is you create one when the page is loaded, and the guide at https://stripe.com/docs/stripe-js/elements/payment-request-button?client=html#html-js-complete-payment sort of implicitly assume that), or you could ajax your backend at that point and get one and then call confirmCardPayment with it, that works fine too.
Ok, sorry just give me a few minutes to digest what you're saying
Hi again, ok so reading the link above, step 4 a Payment Intent is created (at which point this is created is not specified, but crucially) before the .on("paymentmethod") section is reached (step 5)
To prevent creating hundreds of thousands of unused Payment Intents when the cart page is viewed with the Digital Wallet payment button in the small chance that a visitor proceed to pay (by digital wallet) we create the payment intent when it is clicked
the doc assumes you already have one yes(the doc itself is not very complete, it's I suppose meant to be read in conjunction with https://stripe.com/docs/payments/accept-a-payment?platform=web&ui=elements which describes creating the PI when the page loads or using SSR etc.
But you can call your backend and get one during handling that event yes, that's fine.
Is it not possible for me to call our backend upon paymentrequest button being clicked. But allow me to control when the UI of the digital wallet appears with paymentrequest.show()
As we're experiencing a race conditiona I believe between the PI being created (only when needed) and shippingaddress events being fired
yeah I didn't really understand that, since the shippingaddresschange doesn't really have anything to do with or require a PaymentIntent.
Is it not possible for me to call our backend upon paymentrequest button being clicked.
to be clear that is not what I'm suggesting.
I think you're right, im using the payment intent client_secret to obtain the relevant link to our shopping basket in the backend for recalculating address costs - I think talking it out has releaved that actually, I can use a better reference for calculating shipping rates - against the correct shopping cart/basket.
yeah I assumed it was that, that your backend requires the PaymentIntent/order on its side to exist when you send whatever request you send from the shippingaddresschange handler to calculate rates for the updateWith function.
in which case I suppose you just have to try to rearchitect this so either the backend can do that without that context/backend order, or so that you create the PaymentIntent earlier in the flow(which yes might lead to dummy extra PaymentIntents like you say but that's unfortunately just how a lot of Stripe integrations work and it's not a massive problem)
Ok - I will do just that, but continue to avoid creating unnecesary payment intents. Thanks for invaluable and prompt help, as per usual!