feat: improve express checkout handling by surfacing errors #2273
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
All Submissions:
Changes proposed in this Pull Request:
Express Checkout (GPay/Apple Pay) errors were failing silently in the modal checkout because they use the WooCommerce Store API, which doesn't trigger the classic
checkout_errorevent that the modal relies on. Instead, the payment gateway plugin appends error elements directly to the DOM, but the modal's processing screen remains visible, and users see no feedback.This PR adds a MutationObserver to detect when error elements (
.woocommerce-erroror.wc-block-components-notice-banner.is-error) are added to the checkout container. When detected, it applies Newspack styling, dispatches theplaceOrderErrorEventto hide the processing screen, and scrolls the error into view. TheclearNotices()function was also updated to preserve the.woocommerce-notices-wrappercontainer, allowing payment plugins to continue appending errors to it.This fix applies to any error returned by the Store API checkout endpoint (
/wp-json/wc/store/v1/checkout). For example, when a user already has an account with the same email, it returns this:{ "code": "registration-error-email-exists", "message": "An account is already registered with email@example.com. Please log in or use a different email address.", "data": { "status": 400 } }Or when the billing address from GPay/Apple Pay is missing required fields:
{ "code": "woocommerce_rest_invalid_address", "message": "There was a problem with the provided billing address: Province is required, Postcode \/ ZIP is required", "data": { "errors": { "billing": [ "Province is required", "Postcode \/ ZIP is required" ] }, "status": 400 } }Closes NPPM-2426.
How to test the changes in this Pull Request:
Other information: