#alan-tse_api
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/1450404014905753752
📝 Have more to share? Add more details, code, screenshots, videos, etc. below.
Our current payment button integration does support updating the total amount during a shipping address change.
However, after migrating to the Express Checkout Element, we’re no longer able to update the total in the same scenario.
👋 Hi there! Let me take a look
In the first case, are you able to call elements.update({ amount: newTotal })?
if I call elements.update({ amount: newTotal }) during the 'shippingaddresschange' callback, the button will disapear while no error occure
I am not sure if this is the correct way to do it
That is the way to update the total amount in an ECE callback
Which payment method are you testing this with in the ECE? What do you mean when you say the button disappears?
what is ECS means ? Is that Express Checkout Element?
Yes, sorry: Express Checkout Element
Sure. I'm asking because normally, for example with Google Pay, a popup appears. If you change the shipping address there, the total amount will be updated in that popup… so the Express Checkout button shouldn't be affected at all
can you see it?
when the googlepay popup show, it trigger shippingaddresschange right now, and I will update the amount in the callback, then the popup disapear and also the button
if I remove the update function, everything is alright
If I don't call the update function and only resolve lineItems and shippingRates, the amount is not right. Will stripe calculate the right amount and show in the popup ?
No, you need to call the update function to update the total
But yeah, I see in the video that the button disappears when the shipping address is set when the popup is opened
What is stripeElementFactory in this case? How is it created?
You can try to reproduce this in a more minimal setup, since elements.update({ amount }) is the documented way to update the total amount: https://docs.stripe.com/js/elements_object/update#elements_update-options-amount
ah.... At the first time, I did not see element.update(options) contains amount
I read this part Update an Express Checkout Element
Right, you need to call that method on the elements object (or stripeElementFactory in your case), and not on the element itself (expressCheckoutElement); they are separate functions
But that's what you've now tried, it seems
so?? What is wrong? What should I do to make it right?
There is no error thrown or log
I have no idea what I had done wrong..
I think you would need to see if you can reproduce the problem with a simple setup, and see what the difference is between that and your code
what does a simple setup means?
Like a really basic setup, to see whether it works at all
ok, I will try
so I am doning the right way . I just don't know what param is wrong. Is there any way to capture the error?
Yeah, what you're doing looks OK in general. But I see that you have a complex webapp, so I don't know what else is happening 🙂
You should normally see errors in the browser console if something is wrong… but I know that's not happening for you here
I try to debug the stripe.js, but it's really hard to read. Is there a full version js that is not minify or uglify for easier debug?
No, I don't believe so
I think it is about currency, when I use USD, it works. But when I use TWD, it fails
Hm, I do have problems with getting the ECE to show if I use TWD with small amounts
Right, when the amount is under 1000, it fails.
But otherwise, are you able to handle shipping address changes when using the ECE, with a minimal setup?
Yes! I remove the async interface and update the amount immediately, it works. But I found the currency problem.
And then I reuse the interface to get amount and update a bigger amount, it works too.
So I guess it fails because of the small amounts with zero decimal currency.
Possibly. You need to charge at least around amount: 1600 with currency: twd, which is about US$0.50: https://docs.stripe.com/currencies#minimum-and-maximum-charge-amounts
Huh? Do I have to calculate based on the minimum amount in US dollars?
That's new for me XD
It depends on what the settlement currency is on your Stripe account, as shown in the table on that page
Right! I reproduce the problem!! When I use 1700 TWD, it works, but when I change to 1600, it fails...Amazing
Now I know.Thank you for the quz 1! Now we go to quz 2!
For the second question, I would ask why you need to perform updates when the user clicks the checkout button. Can you not apply those updates to the element before they click?
I can reproduce this now as well, and see the ECE disappear! I will see if we can improve this behaviour
This is our process: when a user visits the page, we create the express button. At this point, the price is not yet determined, so we only use a default price(like 10000, big enough to avoide the problem above). Then when the user clicks the button, we assume the page price has stabilized, and then we call an API to fetch the latest pricing to update and show the popup.
You'll have to fetch the price sooner, if possible. Or have the user first click a "Pay" button which fetches the price, and then shows the ECE. Or something like that.
The one-second limit when clicking an ECE button is required: https://docs.stripe.com/js/element/events/on_click?type=expressCheckoutElement#element_on_click-handler-resolve
The time required to call the API is hard to control and cannot be guaranteed. Displaying two buttons would result in a poor user experience.
I think we can call the API in 'ready' . Do this function have a time limitation?
There is no time limit in the ready callback, as you do not have to call a resolve function: https://docs.stripe.com/js/element/events/on_ready
actually, we want to prevent the popup when the api throw an error. Is there any other way to stop the popup or show the popup proactively
You can call reject in the click handler to prevent it from being shown: https://docs.stripe.com/js/element/events/on_click?type=expressCheckoutElement#element_on_click-handler-reject
But I don't believe you can show the popup without user interaction
you mean, if I want to stop the popup, I can only do this in the click handler. There is no other way
I notice that paymentRequest has show to call to show popup proactively. Is ECE has the similar way to do so?
No, you can't use your own button with ECE and trigger the display of it
This was just available for the Payment Request button
Taking over from my colleague. Let me know if you've any follow-up questions