#nyxi_paymentelement-updates
1 messages ยท Page 1 of 1 (latest)
Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.
- nyxi_automatic-payment-methods, 57 minutes ago, 91 messages
- nyxi_docs, 4 days ago, 11 messages
- nyxi_pi-autopms, 4 days ago, 62 messages
- nyxi_invoice-return-url, 5 days ago, 79 messages
๐ 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/1245055324088569917
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
@fleet mirage that's expected behaviour overall yes. You can use https://docs.stripe.com/js/elements_object/fetch_updates if you want to get the latest state of the PaymentIntent
nyxi_paymentelement-updates
That doesn't really remove the race-condition issue though, it would just make the window smaller. In my previous integration I would select the row for update while processing the payment, but that's not possible with async payments.
When do you suggest I call this? On a timer? Before clicking the confirm button on the page?
I don't really have a solution to offer. If you are worried about a race condition you should switch to our "defer intent" flow instead: https://docs.stripe.com/payments/accept-a-payment-deferred?
Hmm. As far as I can tell this code example suffers the same theoretical race condition after line 31, although we're in "highly unlikely" territory then. I think I have to rethink my integration a little if there are no safeguards against this particular condition on Stripe's end (from the client perspective). I would have hoped for https://docs.stripe.com/error-codes#payment-intent-amount-reconfirmation-required or a similar error when trying to confirm the payment intent on the client after the amount changed (also this error code is gated behind my account; I couldn't find it on my test account which confused me a bit - is it a beta error code?).
Also, can you point me in the direction of the documentation for the parameters stripe appends to the return_url after payment redirection? I cannot find them. I got redirect_status=pending but I'm not entirely sure what that means.
the same theoretical race condition after line 31
what is line 31?
This code has you create the PaymentIntent server-side after creating the PaymentMethod so you control the amount and you shouldn't change the amount server-side anymore in that flow.
We have docs like the bottom of https://docs.stripe.com/payments/cash-app-pay/accept-a-payment?web-or-mobile=web&payments-ui-type=direct-api#handle-redirect that covers the query params but I recommend ignoring those since someone can change them client-side and instead checking the PaymentIntent
If we assume we won't change the amount, then sure, it will work all the time. What I'm saying is there is a gap after creating the intent where you can change the amount. In the code example it's very unlikely because it's immedaitely going to confirm it, but it's essentially the same problem I have: I create the intent when a payment is set up, and the amount can be changed at any time after that. That's just the nature of the payment flow. I could cancel the payment intent and create a new one if the amount changes -- that would at least remove all chances of a race condition, but I was under the impression that the payment intent was designed to be reused, including changing the amount (implied also since the amount can be updated).
Ok, I will fetch the intent and ignore the params.
I don't really get why you would change the amount of the PaymentIntent in that flow though. Like what is triggering this behaviour that the client-side code isn't aware of?
You prepay for a table at a nightclub. The venue sets up the payment, including the amount, and ship off a link to you. At any time after this, they can choose to change the amount.
You could call them, say the amount is wrong after looking at the page, they could change it and then you could pay for it and get the old/wrong amount.
I'm not saying this is likely, just that it's possible
In my old synchronous flow, I'd have a "last edited" timestamp that the client would send to the server along with a payment method. If it didn't match, it would not process the payment but tell the user to reload the page.
You can use the same logic in this case right? Sorry I'm still not wrapping my head around what real issue you could be experiencing here.
But otherwise, don't update the PI anymore and cancel, that seems fine for your flow to just create a new one each time
I cannot, because I no longer send data to the (my) server, I confirm the payment intent on the client and the server waits for a webhook where it captures and processes the payment, and the server has no way to determine what the client was looking at.
Yes, I think cancellation is the best solution.
I think it would be a good idea to perhaps investigate if the stripe SDKs could handle this case: When you confirm a payment intent, send some data from the SDK along with the payment to Stripe's API, and if there is a mismatch in something critical (whatever that may be; currency, amount etc.), throw an error instead of completing the payment intent.
Hello! I'm taking over and catching up...
Sure all good
It sounds like you're describing Confirmation Tokens, but let me read more of the thread...
I was hoping moving to automatic payment methods and webhooks would simplify the integration ๐
Not entirely understanding where the confirmation token would go into my flow
It's only designed for the two flows linked from the documentation above, it may not be suitable for your flow.
Basically the idea is that whatever changes the amount on the Payment Intent would also trigger the client-side update to show the new amount (and any other details that may have changed). There's always a chance someone can confirm the Payment Intent at the same instant the amount is updated; that's the nature of variable pricing during a payment flow.
I understand, but Stripe sits in the middle and should be able to intercept this case and not process it. I don't know what data you send to Stripe when calling confirmPayment() on the client, but I don't see how it could not include the amount and currency and match it against Stripe's version of the payment intent on the server (which as I understand it gets locked during processing - at least you have that option), the same way you cannot cancel and succeed a payment intent, even if you make the API calls at the same time.
And yes, I also understand this is a rare case
Just from an implementation perspective, it should be solvable.
I think I will just cancel the payment intent instead of updating it; either the call to cancel will fail (and the venue will receive the original amount like the client sees on their screen) or the client will receive an error as the intent was canceled.
I mean, not really? confirmPayment() is client-side code that can be modified by the client. If it did an amount check it could be easily bypassed or modified by the client, so it wouldn't do any good.
sure, if you're being intentionally malicious
It does sound like canceling the Payment Intent and creating a new one is your best option if you're worried about this situation.
If you modify it on the client to a value that does not match it should just fail. I'm not suggesting letting the client decide the amount. I hope I'm making myself clear ๐
You are, yeah.
Alright. Something to consider at least. Yes, you can modify the value, but you're essentially just "attacking yourself" in that case as it would just not work. People do all kinds of odd implementations that are not necessarily what Stripe recommends (or expects), based on this conversation alone. A check like this could prevent mistakes during async payments, and would never cause a legit payment to error.