#eugene-bakhmetiev_code
1 messages ยท Page 1 of 1 (latest)
๐ 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/1435610195471630377
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
๐
By updating the Element's amount, should update the Apple Pay
https://docs.stripe.com/js/elements_object/update#elements_update-options-amount
hi, yes, it should, but it doesn't. I know that the update goes through correctly, because when I confirm payment, it completes without throwing "You are trying to confirm a payment intent with an instance of Elements with different amount total" error
it also reproduces for Google Pay, for that matter
I'm assuming that if I re-mount PaymentElement, it should display the updated amount correctly, but it means that the payment form will flicker briefly while it's being re-initialized, so I'm trying to avoid this if I can
Let me do a quick test...
Sorry for the late reply, still on this
no worries, let me know if I can provide any additional info
ok as you are confirming the Element with the client secret, you should udpate the PaymentIntent too
at this point we don't have a payment intent yet, we generate it later
meaning we generate it after calling elements.submit() and before calling stripe.confirmPayment()
hey there, just stepping in for my colleagues who need to step away
The error you shared indicates to me the elements & payment intent are mismatched, are you making sure to pass the same final_price_raw for payment intent creation?
Please share an example payment intent or request ID, such as pi_123 or req_123 for me to look at a specific example
hi, it doesn't throw any errors, just displays the incorrect value in Apple Pay and Google Pay. Yes, the price is correct in payment intent. Let me generate a new example for you
here's a test payment intent ID pi_3SQ7PTJaf89hC41I1TrZeWzH
it displays the initial amount with which Elements were initialized, without the shipping rate added
if I understand correctly, Apple Pay interface is only displayed when I call elements.submit(), right?
That's right
so it should display correct value, because I'm calling elements.update() before elements.submit(). And even if there was some kind of race condition, it should still display correct value if I close the Apple Pay interface and open it again, but it doesn't
I think this is because the update() is async and we don't expect it to be modified directly before a submit like that
As a crude test/validation, can you add a short delay after update, before calling submit?
For my context, whats the customer flow/use case that leads you to make this update in the sequence before submit like this, instead of before your payment button is clicked?
yeah, but if I close the Apple Pay interface, it should have the correct value for the next time, which doesn't happen.
I will test adding a delay in any case, thanks.
The idea was that this is the moment when we are sure that we have all of the information we need to get final price -- customer selected quantity of items, shipping rate etc and is ready to proceed to payment. So instead of calling elements.update() every time the price changes, we call it at the last possible moment.
Is there a callback or something that would let me know that the update completed? elements.update() is not returning a Promise, so I cannot await it as far as I see
Yea, you can listen for an update-end as the actual signal, rather than the crude delay: https://docs.corp.stripe.com/js/element/events/on_update_end
The idea was that this is the moment when we are sure that we have all of the information we need to get final price -- customer selected quantity of items, shipping rate etc and is ready to proceed to payment. So instead of calling elements.update() every time the price changes, we call it at the last possible moment.
I'd suggest revising this to call those updates each time you have a change
Changing some details can also impact the available payment methods, so waiting like this could lead to other invalid states
Then you can disable the payment button while waiting for the update end event