-
Notifications
You must be signed in to change notification settings - Fork 217
Improves the error message shown in checkout when a saved payment method is invalid #4737
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
base: develop
Are you sure you want to change the base?
Conversation
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.
The change look ok and tests as described!
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.
Over and above removing the polyfill, this PR is not working for me.
After debugging things somewhat extensively, it looks like we're missing code in WC_Stripe_UPE_Payment_Gateway->process_payment_with_saved_payment_method() to call $this->get_payment_intent_error_message() after we have determined that the error is not retryable and before we call $this->throw_localized_message() (where we don't have any intent-specific logic -- see below). I also checked, and we can't simply hand the modified error message to $this->throw_localized_message(), as it will get overridden based on the error code. 🙃
woocommerce-gateway-stripe/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Lines 1429 to 1438 in 7d055cd
| if ( ! empty( $intent->error ) ) { | |
| $this->maybe_remove_non_existent_customer( $intent->error, $order ); | |
| // We want to retry (apparently). | |
| if ( $this->is_retryable_error( $intent->error ) ) { | |
| return $this->retry_after_error( $intent, $order, $can_retry ); | |
| } | |
| $this->throw_localized_message( $intent, $order ); | |
| } |
I am also having a separate issue where the returned error message is not being displayed in the UI, but that is unrelated to this PR.
| * @version 10.1.0 | ||
| */ | ||
|
|
||
| if ( ! function_exists( 'str_contains' ) ) { |
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.
We don't need our own polyfill for this, as a polyfill for str_contains() has been in WordPress since 5.9.0 as per WordPress/wordpress-develop@3cc8f12. Given that 5.9.0 was released in early 2022 and our minimum supported version is 6.7, I think we should rely on the WordPress core polyfill.
Fixes STRIPE-572
Changes proposed in this Pull Request:
As requested in STRIPE-572, this PR improves the error message shown when a saved payment method becomes invalid. The goal is to reduce confusion among shoppers and merchants. Shoppers may then attempt to use another method when this happens.
Error preview:

Testing instructions
fix/improving-error-message-for-detached-methods)Changelog entry
Changelog Entry Comment
Comment
Post merge