#ucjonathan_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/1240326624205865102
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
It looks like the amount is set on the Elements object, the object that represents the entire Elements instance that you create individual Elements from. So you can update the amount on that https://docs.stripe.com/js/elements_object/update#elements_update-options-amount
Do you think it's OK to call that during the shippingaddresschange callback, etc?
Ah sorry I forgot about that angle. You will want to use our updateWith handler in that event and pass it an object with the new total
https://docs.stripe.com/js/appendix/update_details
https://docs.stripe.com/js/payment_request/events/on_shipping_address_change
I'm confused because that seems to be associated with the PaymentRequest and I'm doing the Express Checkout element.
Hello! I'm taking over and catching up...
The guide here explains how to handle the shippingaddresschange event in the Express Checkout Element: https://docs.stripe.com/elements/express-checkout-element/accept-a-payment#collect-shipping
When you resolve the event the updates you pass in will be reflected in the UI.
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.
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?
Is there something undocumented like a line item named "total" having a meaning or something?
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.
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.
what is the recommended approach then for initializing the express checkout?
This guide outlines our recommended approach, where you don't create the Payment Intent until later in the process: https://docs.stripe.com/elements/express-checkout-element/accept-a-payment