#ucjonathan_api

1 messages ¡ Page 1 of 1 (latest)

hearty aspenBOT
#

👋 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/1240326624205865102

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

fierce folio
sand vapor
#

Do you think it's OK to call that during the shippingaddresschange callback, etc?

hearty aspenBOT
fierce folio
sand vapor
#

I'm confused because that seems to be associated with the PaymentRequest and I'm doing the Express Checkout element.

tall creek
#

Hello! I'm taking over and catching up...

#

When you resolve the event the updates you pass in will be reflected in the UI.

sand vapor
#

I can return rates in the callback, but the documentation is lacking details on how to provide the new total

#

It seems very incomplete compared to all the documentation I used when implementing PaymentRequest functionality for Apple Pay / Google Pay. For example, when the customer changes their address it's going to have an impact on the tax associated with the order so it's important that the total can be updated. Right now when I change the address on the Amazon Pay screen, I can't get the total to update.

#

one sec, may have a typo in my update call. let me test it.

#

that.elements.update({amount: Math.round(window.cart.total * 100)});

                                let resolveOptions = {
                                    "shippingRates": that.stripeShippingOptions(availableShippingMethods)
                                };

                                // call event.resolve within 20 seconds
                                event.resolve(resolveOptions);
#

So you can't do that update call inside the callback. It's throwing the error: IntegrationError: Invalid value for elements.update(): amount is only applicable when a mode is set.

tall creek
#

You shouldn't be calling elements.update.

#

Err, wait, sorry.

#

Was looking at the wrong thing.

#

What mode are you using?

#

Or, rather, what does your code look like when you initialize elements and create the Express Checkout Element?

sand vapor
#

Is there something undocumented like a line item named "total" having a meaning or something?

tall creek
#

No.

#

Can you share the code I mentioned above?

sand vapor
#

const appearance = { /* appearance / };
const options = {
appearance: {/
...*/}
};
that.elements = that.stripe.elements({
clientSecret: stripePaymentIntentResponse.client_secret
});
const expressCheckoutElement = that.elements.create('expressCheckout');
expressCheckoutElement.mount(apButtonDom);

#

The client_secret is being created on the server side with the initial total of the current cart.

tall creek
#

Ah, you're initializing elements with a Payment Intent's client secret. That means the amount is always going to be the amount on the Payment Intent. In order to change the amount you would need to change the Payment Intent's amount, then have Elements fetch updates: https://docs.stripe.com/js/elements_object/fetch_updates

#

That is not the recommended approach with Express Checkout Element, but it should work.

sand vapor
#

what is the recommended approach then for initializing the express checkout?

tall creek