Skip to content
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 crash when address has no defined shipping rates #3560

Merged
merged 4 commits into from
Oct 30, 2024

Conversation

annemirasol
Copy link
Contributor

@annemirasol annemirasol commented Oct 29, 2024

Fixes #3538

Changes proposed in this Pull Request:

For block cart and block checkout, when Apple Pay, Google Pay or Link loads and the default address (first address, or last selected address) is not defined under Shipping, we get an IntegrationError and the cart/checkout page gets stuck trying to load the modal.

This happens because for block cart and block checkout, we pass a potentially empty shippingRates array option to ECE. When shippingRates is empty but shippingAddressRequired is true, the Stripe JS library throws an error and bails (Stripe docs).

This issue does not happen inside the Product and shortcode pages because we are always passing a non-empty "pending" shippingRates array when ECE loads.

To fix the issue, we will do the same for block cart and block checkout: when we do not have shipping rates for the current address, we will pass a "pending" shipping rates array. With this change, ECE will not crash the page, and the user has a chance to change to a valid shipping address, in case of multiple available addresses.

Testing instructions

  1. Join the Google Pay test group to easily get multiple shipping addresses available to your account: https://groups.google.com/g/googlepay-test-mode-stub-data
  2. As the merchant, set up your shipping zones such that only Japan is defined, with a free or flat rate shipping.
  3. As the shopper, clear cookies and add a product to your cart.
  4. For both block cart and block checkout, verify the following behavior:
    • On develop: Google Pay modal does not launch and the page is stuck loading.
    • On this branch:
      • Google Pay modal launches without any error.
      • Shopper still cannot proceed with the purchase if an address other than Japan is selected.
      • Shipping computation is correct when selecting a valid shipping address.
  5. Regression test: the product, shortcode cart and shortcode checkout pages should not be affected and should behave the same as above.

Google Pay

Before After
Screenshot 2024-10-29 at 1 05 19 PM Screenshot 2024-10-29 at 1 06 01 PM

Apple Pay

Before After
Screenshot 2024-10-30 at 12 18 37 PM Screenshot 2024-10-30 at 12 19 07 PM

Link

Before After
Screenshot 2024-10-30 at 12 29 41 PM Screenshot 2024-10-30 at 12 27 15 PM

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Added changelog entry in both changelog.txt and readme.txt (or does not apply)
  • Tested on mobile (or does not apply)

Post merge

@annemirasol annemirasol self-assigned this Oct 29, 2024
@annemirasol annemirasol force-pushed the fix/3538-ece-shipping-rates-missing branch from 97a15f1 to 2042a8f Compare October 29, 2024 18:29
@annemirasol annemirasol marked this pull request as ready for review October 29, 2024 20:45
@annemirasol annemirasol requested review from a team and wjrosa and removed request for a team October 29, 2024 21:01
@annemirasol annemirasol force-pushed the fix/3538-ece-shipping-rates-missing branch from 00fcc2a to 5fade4c Compare October 29, 2024 21:24
*
* @param array $data
*/
public function get_checkout_data() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to have a simple unit test for this method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests in c9c7efe, thanks!

Copy link
Contributor

@wjrosa wjrosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code is good, and it works as expected! Left a minor suggestion.

On develop: Google Pay modal does not launch and the page is stuck loading.

Screenshot 2024-10-30 at 15 27 41

On this branch:
Google Pay modal launches without any error.

Screenshot 2024-10-30 at 15 28 52

Shopper still cannot proceed with the purchase if an address other than Japan is selected.

Screenshot 2024-10-30 at 15 29 23 Screenshot 2024-10-30 at 15 31 51

@annemirasol annemirasol merged commit 3db5663 into develop Oct 30, 2024
34 of 35 checks passed
@annemirasol annemirasol deleted the fix/3538-ece-shipping-rates-missing branch October 30, 2024 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ECE] Error when shopper address is not covered in Shipping
2 participants