Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 10.1.0 - xxxx-xx-xx =
* Fix - Improves the error message shown in checkout when a saved payment method is no longer valid
* Fix - Fix fatal error when trying to allow the `display` CSS property using the `safe_style_css` filter
* Fix - Remove `redirect_url` parameter from Express Checkout payment flow
* Fix - Adjust UI spacing of help text on express checkout theme settings page
Expand Down
16 changes: 16 additions & 0 deletions includes/abstracts/abstract-wc-stripe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ abstract class WC_Stripe_Payment_Gateway extends WC_Payment_Gateway_CC {
use WC_Stripe_Subscriptions_Trait;
use WC_Stripe_Pre_Orders_Trait;

/**
* Error string returned by Stripe when a PaymentMethod is detached.
*
* @var string
*/
protected const DETACHED_PAYMENT_METHOD_ERROR_STRING = 'The provided PaymentMethod was previously used with a PaymentIntent without Customer attachment';

/**
* The delay between retries.
*
Expand Down Expand Up @@ -164,6 +171,15 @@ public function is_retryable_error( $error ) {
return false;
}

// Don't retry if the error indicates that a PaymentMethod is detached.
if ( isset( $error->type )
&& 'invalid_request_error' == $error->type
&& isset( $error->message )
&& str_contains( $error->message, self::DETACHED_PAYMENT_METHOD_ERROR_STRING )
) {
return false;
}

$retryable_types = [
'invalid_request_error',
'idempotency_error',
Expand Down
14 changes: 14 additions & 0 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -2467,6 +2467,20 @@ private function get_payment_intent_error_message( $payment_intent ) {
);
}

// This error indicates that the saved payment method is no longer valid.
// This can happen if the payment method was removed in Stripe dashboard, or if it expired.
// In this case, we want to show a specific message to the user.
if ( isset( $payment_intent->error->type )
&& 'invalid_request_error' === $payment_intent->error->type
&& isset( $payment_intent->error->message )
&& str_contains( $payment_intent->error->message, self::DETACHED_PAYMENT_METHOD_ERROR_STRING )
) {
return __(
'This saved payment method is no longer valid. It might be expired, removed, or broken. Please choose a different payment method.',
'woocommerce-gateway-stripe'
);
}

return $payment_intent->error->message;
}

Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 10.1.0 - xxxx-xx-xx =
* Fix - Improves the error message shown in checkout when a saved payment method is no longer valid
* Fix - Fix fatal error when trying to allow the `display` CSS property using the `safe_style_css` filter
* Fix - Remove `redirect_url` parameter from Express Checkout payment flow
* Fix - Adjust UI spacing of help text on express checkout theme settings page
Expand Down
Loading