Skip to content

Conversation

@wjrosa
Copy link
Contributor

@wjrosa wjrosa commented Oct 16, 2025

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:
Screenshot 2025-10-16 at 18 17 34

Testing instructions

  • Checkout to this branch on your test environment (fix/improving-error-message-for-detached-methods)
  • Connect your Stripe account
  • As a shopper, add a new payment method using the My Account screen
  • As a merchant, go to your Stripe dashboard
  • Open the shopper details
  • Delete the newly added payment method
  • As the same shopper, attempt to purchase using the same saved payment method
  • Confirm the new error message above is shown

  • Covered with tests (or have a good reason not to test in description ☝️)
  • Tested on mobile (or does not apply)

Changelog entry

  • This Pull Request does not require a changelog entry. (Comment required below)
Changelog Entry Comment

Comment

Post merge

@wjrosa wjrosa self-assigned this Oct 16, 2025
@wjrosa wjrosa marked this pull request as ready for review October 16, 2025 21:13
@wjrosa wjrosa requested review from a team, daledupreez and diegocurbelo and removed request for a team October 16, 2025 21:20
Copy link
Member

@diegocurbelo diegocurbelo left a 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!

Copy link
Contributor

@daledupreez daledupreez left a 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. 🙃

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' ) ) {
Copy link
Contributor

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.

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.

4 participants