-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: ECE initialization when no shipping rates are provided #10169
base: develop
Are you sure you want to change the base?
fix: ECE initialization when no shipping rates are provided #10169
Conversation
Test the buildOption 1. Jetpack Beta
Option 2. Jurassic Ninja - available for logged-in A12s🚀 Launch a JN site with this branch 🚀 ℹ️ Install this Tampermonkey script to get more options. Build info:
Note: the build is updated when a new commit is pushed to this PR. |
@@ -33,8 +35,6 @@ export const shippingAddressChangeHandler = async ( api, event, elements ) => { | |||
amount: response.total.amount, | |||
} ); | |||
|
|||
lastSelectedAddress = event.address; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved above, so that the newly selected address is saved regardless of the error.
This makes the behavior consistent between block-based and shortcode-based checkout.
const shippingRates = requestShipping | ||
? [ | ||
{ | ||
id: 'pending', | ||
displayName: __( 'Pending', 'woocommerce-payments' ), | ||
amount: 0, | ||
}, | ||
] | ||
: undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This "Pending" rate is now consistently added on initialization. Before, it was added only on the product pages.
Size Change: +95 B (0%) Total Size: 1.36 MB
ℹ️ View Unchanged
|
Fixes #9939
Fixes #9593
Changes proposed in this Pull Request
When the "Hide shipping costs until an address is entered" option is checked, WooCommerce checkout requires a country/state/zipcode/city address to get shipping rates.
This scenario was incompatible with the ECE initialization.
You see, when we click on the ECE button, we tell Stripe: "Please initialize the ECE dialog with the possibility to select shipping rates.". In this scenario, Stripe requires us to provide some shipping rates.
But, unfortunately, if the product is physical and the "Hide shipping costs until an address is entered" option is selected in the WC settings and the customer hasn't visited the checkout before, we get in a bit of a pickle: we ask Stripe to initialize the ECE dialog with the possibility of showing shipping rates. But we don't have any initial shipping rates - and Stripe gets angry at us, erroring out with this message and with a partially initialized ECE:
I implemented these changes for both the tokenized ECE and non-tokenized ECE, where possible.
The non-tokenized ECE changes were slightly more complex (due to the server-side response we "hack"), so I didn't think it was worth spending more time on it.
Testing instructions
I also simulated this scenario when there are no shipping rates available for a given customer. I did so by adding a "US - California" shipping zone (in the WooCommerce Shipping settings), and ensuring it doesn't have any rates. Then, as an anonymous customer, you can click on the ECE button again. The ECE will prompt you to select a different address.
Here's an example with ApplePay:
npm run changelog
to add a changelog file, choosepatch
to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.Post merge