#alan-tse_api

1 messages · Page 1 of 1 (latest)

upbeat vergeBOT
#

👋 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.

dull stag
#

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.

storm basalt
#

👋 Hi there! Let me take a look

#

In the first case, are you able to call elements.update({ amount: newTotal })?

dull stag
#

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

storm basalt
#

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?

dull stag
#

what is ECS means ? Is that Express Checkout Element?

storm basalt
#

Yes, sorry: Express Checkout Element

dull stag
#

disppear means the button is gone😂

#

let me show you a video

storm basalt
#

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

dull stag
#

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 ?

storm basalt
#

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?

dull stag
storm basalt
dull stag
#

ah.... At the first time, I did not see element.update(options) contains amount

#

I read this part Update an Express Checkout Element

storm basalt
#

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

dull stag
#

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..

storm basalt
#

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

dull stag
#

what does a simple setup means?

storm basalt
#

Like a really basic setup, to see whether it works at all

dull stag
#

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?

storm basalt
#

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

dull stag
#

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?

storm basalt
#

No, I don't believe so

dull stag
#

I think it is about currency, when I use USD, it works. But when I use TWD, it fails

storm basalt
#

Hm, I do have problems with getting the ECE to show if I use TWD with small amounts

dull stag
#

Right, when the amount is under 1000, it fails.

storm basalt
#

But otherwise, are you able to handle shipping address changes when using the ECE, with a minimal setup?

dull stag
#

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.

upbeat vergeBOT
dull stag
#

So I guess it fails because of the small amounts with zero decimal currency.

storm basalt
dull stag
#

Huh? Do I have to calculate based on the minimum amount in US dollars?

#

That's new for me XD

storm basalt
#

It depends on what the settlement currency is on your Stripe account, as shown in the table on that page

dull stag
#

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!

storm basalt
#

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?

storm basalt
dull stag
#

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.

storm basalt
dull stag
#

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?

storm basalt
dull stag
#

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

storm basalt
#

But I don't believe you can show the popup without user interaction

dull stag
#

you mean, if I want to stop the popup, I can only do this in the click handler. There is no other way

upbeat vergeBOT
dull stag
#

I notice that paymentRequest has show to call to show popup proactively. Is ECE has the similar way to do so?

dense mirage
#

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

narrow oxide
#

Taking over from my colleague. Let me know if you've any follow-up questions