#pinkpanda7052
1 messages · Page 1 of 1 (latest)
What is the correct procedure for resolving a shippingaddress, whilst updating line items and their amounts, and also updating the overal "amount" to pay? It seems from what I've read and tried, that we cannot update "amount" in the "resolve" function... when I tried passing in "amount" to this, it logs a warning to the console stating that "amount" is not a valid key.
Note: Originally we weren't adding tax to the "amount" given to each line item, so it was a tax-free price on the line items, while the "amount" to pay was set to a total price inclusive of tax, when tax is applicable. This worked, but it meant when viewing the summary of line items, the price of each line item didn't show inclusive of tax. We would prefer to show pricing with tax because it's clearer to the customer that way
quoting here to keep all the context together
Okay so I'm going to describe your issue back to you to make sure I understand it. Please correct me if I am wrong in any way.
- Create an Express Checkout Element object with a specified
amount - The customer clicks the ECE and launches whichever wallet modal they selected
- You are collecting shipping addresses and listen for the change event
- A customer changes their shipping such that it alters the final price
- Any updates to the total
amountare not reflected in the UI the customer is interfacing with
That's correct... Updates to the total amount are not reflected in the UI, in particular the button labelled "Pay £48.00" which should read "Pay £40.00" if the tax is removed... The "Summary" UI elements are indeed displayed correctly.
Note: As long as we don't alter pricing, then the pay button does get updated correctly. If we simply adjust the postcode which does not affect anything, the Pay button updates to the correct value...
I can record and share a video if you like?
Just to note: the "shippingaddresschange" event fires when the wallet popup first loads, so a customer may default to an address which triggers address validation at our end (and could reuslt in new new line items / shipping rates) without them manually "changing" their address.
Just so I'm clear, you are showing Line items in the modal interface and those do update but the total is not updating in the modal
This, for example
Can you share the code you are using to update the line items?
Sure, thought might be a bit messy now with all the experimenting and logs i've been throwing at it... is there a spcial "code block" I can paste here to make it format nicely?
Three ` marks
this is code
Would it help if I record a video and post it to youtube?
const updateAmount = function () {
elements.update({
amount: StripeExpressCheckoutElementsService.getTotalToPay()
});
}
expressCheckoutElement.on('shippingaddresschange', function (event) {
handleAddressChange(event);
});
const handleAddressChange = function (event) {
// Do validate and fetch shipping options
return validateAddressAndFetchShippingOptions(event.address, 'delivery').then(function () {
// Address is deliverable (resolve)
if (StripeExpressCheckoutElementsService.isLastValidatedAddressDeliverable()) {
updateAmount();
event.resolve({
lineItems: getLineItems(),
shippingRates: getShippingRates()
});
}
// Address not deliverable (reject)
else {
event.reject();
}
});
}
I've stripped away loads of irrelevant stuff, so this just leaves:
- Our "updateAmount" function which figures out the total the customer is expected to pay, taking into account line items and shipping costs, and this is returned as minor units.
- We are subscribing to Stripe's "shippingaddresschange" event. When triggered we call our own handler "handleAddressChange"... that makes a network request to validate the address, and then resolves or rejects... if resolving, we pass in the line items once again, and shipping rates after we've called "updateAmount"
Okay, quick question. If a user makes a change that impacts the shippingRates parameter but NOT the lineItems, does it update properly?
I'm looking through our code snippets here: https://stripe.com/docs/elements/express-checkout-element/accept-a-payment#collect-shipping
I see that we show passing shipping rates back as a parameter to your backend but the only thing that appears to be updated in the event.resolve() function is the lineItems
For example, if a user were to change their address from one country to another, where the only difference is the shipping rates offered?
I'm trying to replicate in my simple ECE integration but I don't see what you see
I think the answer is yes...
Example:
I change country to one with no tax, resolve the address and pass in new lineItems and new shippingRates... line items show in the summary updates as expected, but the pay button does not update.... if I then edit that same address and adjust the postcode slightly, then the pay button DOES update... it all ran through the same code block, but the line items being passed in were the same values as last time, since they didn't change.
I've got a stupid rule that updates the the amount in the elements object to 0 for an AU address and that works just fine. I start with a $60 charge for US and update it to $0 for AU addresses
It's "stupid" code because this is all it does
const free_options = {
mode: 'setup',
amount: 0,
currency: 'usd'
}
if (address.country === 'AU') {
this.elements.update(free_options)
}
But it works. The Google Pay interface reloads with the correect amount shown
If I were to simply call "update" within the checkout application, things would update as expected... it's only an issue when we resolve the address with new line items...
I think the best way to demonstrate is with a video
Hey really appreciate your time and everything... unfortauntely I have to duck out for about 40 minutes, and can't avoid it
Is it ok to record a video, and send you the link when this is done... I can do this later onl