Skip to content

Commit cd3bb55

Browse files
authored
Fix Stripe Link saved payment methods (#3311)
* Ensure payments with Link as the selected payment type include mandate data * Add Link to the list of queryable Stripe payment method types * Use nice token descriptions for Stripe Link tokens * Add changelog entries * Display the Stripe Link Payment method on My account subscription pages * Fall back to selected payment type if payment types aren't provided * Include sepa tokens in switch statement * Replace if-elseif stack with switch statement * Use switch statement and payment method type * Use generic confirmSetup so Link 3DS cards can be confirmed via add payment method flow
1 parent 4d7e0a0 commit cd3bb55

File tree

7 files changed

+49
-36
lines changed

7 files changed

+49
-36
lines changed

changelog.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
* Fix - Display the payment decline reason on the checkout when using Cash App or WeChat.
1313
* Fix - Re-enable the "Place order" button on the block checkout after closing the WeChat or Cash App payment modal.
1414
* Fix - When SEPA tokens are added via the My Account > Payment methods page, ensure they are attached to the Stripe customer.
15+
* Fix - Clear the saved Stripe Link payment methods when a customer cache is cleared to ensure cached methods are updated promptly.
16+
* Fix - Display Stripe Link payment methods correctly in both Block Checkout and My Account pages.
17+
* Fix - Resolve an error when adding a saved card payment method in My Account when Stripe Link is enabled.
1518
* Fix - Resolved an error when using 3D Secure-enabled cards with Stripe Link enabled.
1619
* Fix - Corrected setup intent payment method types to include 'link' when Stripe Link is enabled, resolving errors during subscription signups.
1720
* Fix - Resolved an issue where changing the payment method for subscriptions failed after 3D-Secure authentication.

client/api/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ export default class WCStripeAPI {
225225

226226
// Card Payments.
227227
return this.getStripe()
228-
.confirmCardSetup( response.data.client_secret )
228+
.confirmSetup( {
229+
clientSecret: response.data.client_secret,
230+
redirect: 'if_required',
231+
} )
229232
.then( ( confirmedSetupIntent ) => {
230233
const { setupIntent, error } = confirmedSetupIntent;
231234
if ( error ) {

includes/class-wc-stripe-customer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class WC_Stripe_Customer {
2020
*/
2121
const STRIPE_PAYMENT_METHODS = [
2222
WC_Stripe_UPE_Payment_Method_CC::STRIPE_ID,
23+
WC_Stripe_UPE_Payment_Method_LINK::STRIPE_ID,
2324
WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID,
2425
WC_Stripe_UPE_Payment_Method_Cash_App_Pay::STRIPE_ID,
2526
];

includes/class-wc-stripe-intent-controller.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ public function is_mandate_data_required( $selected_payment_type, $is_using_save
937937
return false;
938938
}
939939

940-
if ( in_array( $selected_payment_type, [ 'sepa_debit', 'bancontact', 'ideal', 'sofort', 'cashapp' ], true ) ) {
940+
if ( in_array( $selected_payment_type, [ 'sepa_debit', 'bancontact', 'ideal', 'sofort', 'cashapp', 'link' ], true ) ) {
941941
return true;
942942
}
943943

@@ -956,7 +956,7 @@ public function is_mandate_data_required( $selected_payment_type, $is_using_save
956956
public function create_and_confirm_setup_intent( $payment_information ) {
957957
$request = [
958958
'payment_method' => $payment_information['payment_method'],
959-
'payment_method_types' => $payment_information['payment_method_types'],
959+
'payment_method_types' => $payment_information['payment_method_types'] ?? [ $payment_information['selected_payment_type'] ],
960960
'customer' => $payment_information['customer'],
961961
'confirm' => 'true',
962962
'return_url' => $payment_information['return_url'],

includes/class-wc-stripe-payment-tokens.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -383,17 +383,17 @@ private function get_payment_method_type_from_token( $payment_token ) {
383383
* @return array $item Modified list item.
384384
*/
385385
public function get_account_saved_payment_methods_list_item( $item, $payment_token ) {
386-
if ( 'sepa' === strtolower( $payment_token->get_type() ) ) {
387-
$item['method']['last4'] = $payment_token->get_last4();
388-
$item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' );
389-
}
390-
391-
if ( 'cashapp' === strtolower( $payment_token->get_type() ) ) {
392-
/**
393-
* WC's wc_get_credit_card_type_label() function will automatically replace underscores and dashes with spaces.
394-
* Cashtags can include `_` and `-` characters and so to keep the cashtag intact, we need to avoid that by using their HTML entity.
395-
*/
396-
$item['method']['brand'] = str_replace( [ '_', '-' ], [ '_', '&#8211' ], $payment_token->get_display_name() );
386+
switch ( strtolower( $payment_token->get_type() ) ) {
387+
case 'sepa':
388+
$item['method']['last4'] = $payment_token->get_last4();
389+
$item['method']['brand'] = esc_html__( 'SEPA IBAN', 'woocommerce-gateway-stripe' );
390+
break;
391+
case 'cashapp':
392+
$item['method']['brand'] = esc_html__( 'Cash App Pay', 'woocommerce-gateway-stripe' );
393+
break;
394+
case 'link':
395+
$item['method']['brand'] = esc_html__( 'Stripe Link', 'woocommerce-gateway-stripe' );
396+
break;
397397
}
398398

399399
return $item;
@@ -543,6 +543,7 @@ public static function get_token_label_overrides_for_checkout() {
543543
$label_overrides = [];
544544
$payment_method_types = [
545545
WC_Stripe_UPE_Payment_Method_Cash_App_Pay::STRIPE_ID,
546+
WC_Stripe_UPE_Payment_Method_Link::STRIPE_ID,
546547
];
547548

548549
foreach ( $payment_method_types as $stripe_id ) {

includes/compat/trait-wc-stripe-subscriptions.php

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -784,36 +784,38 @@ public function maybe_render_subscription_payment_method( $payment_method_to_dis
784784

785785
$payment_method_to_display = __( 'N/A', 'woocommerce-gateway-stripe' );
786786

787-
// Retrieve all possible payment methods for subscriptions.
788787
try {
789-
$sources = array_merge(
790-
$stripe_customer->get_payment_methods( 'card' ),
791-
$stripe_customer->get_payment_methods( 'sepa_debit' ),
792-
$stripe_customer->get_payment_methods( 'cashapp' )
793-
);
788+
// Retrieve all possible payment methods for subscriptions.
789+
foreach ( WC_Stripe_Customer::STRIPE_PAYMENT_METHODS as $payment_method_type ) {
790+
foreach ( $stripe_customer->get_payment_methods( $payment_method_type ) as $source ) {
791+
if ( $source->id !== $stripe_source_id ) {
792+
continue;
793+
}
794794

795-
if ( $sources ) {
796-
foreach ( $sources as $source ) {
797-
if ( $source->id === $stripe_source_id ) {
798-
$card = false;
799-
if ( isset( $source->type ) && 'card' === $source->type ) {
800-
$card = $source->card;
801-
} elseif ( isset( $source->object ) && 'card' === $source->object ) {
802-
$card = $source;
803-
}
795+
// Legacy handling for Stripe Card objects. ref: https://docs.stripe.com/api/cards/object
796+
if ( isset( $source->object ) && 'card' === $source->object ) {
797+
/* translators: 1) card brand 2) last 4 digits */
798+
$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $source->brand ) ? $source->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $source->last4 );
799+
break 2;
800+
}
804801

805-
if ( $card ) {
802+
switch ( $source->type ) {
803+
case 'card':
806804
/* translators: 1) card brand 2) last 4 digits */
807-
$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $card->brand ) ? $card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $card->last4 );
808-
} elseif ( ! empty( $source->sepa_debit ) ) {
805+
$payment_method_to_display = sprintf( __( 'Via %1$s card ending in %2$s', 'woocommerce-gateway-stripe' ), ( isset( $source->card->brand ) ? $source->card->brand : __( 'N/A', 'woocommerce-gateway-stripe' ) ), $source->card->last4 );
806+
break 3;
807+
case 'sepa_debit':
809808
/* translators: 1) last 4 digits of SEPA Direct Debit */
810809
$payment_method_to_display = sprintf( __( 'Via SEPA Direct Debit ending in %1$s', 'woocommerce-gateway-stripe' ), $source->sepa_debit->last4 );
811-
} elseif ( ! empty( $source->cashapp ) ) {
810+
break 3;
811+
case 'cashapp':
812812
/* translators: 1) Cash App Cashtag */
813813
$payment_method_to_display = sprintf( __( 'Via Cash App Pay (%1$s)', 'woocommerce-gateway-stripe' ), $source->cashapp->cashtag );
814-
}
815-
816-
break;
814+
break 3;
815+
case 'link':
816+
/* translators: 1) email address associated with the Stripe Link payment method */
817+
$payment_method_to_display = sprintf( __( 'Via Stripe Link (%1$s)', 'woocommerce-gateway-stripe' ), $source->link->email );
818+
break 3;
817819
}
818820
}
819821
}

readme.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ If you get stuck, you can ask for help in the Plugin Forum.
140140
* Fix - Display the payment decline reason on the checkout when using Cash App or WeChat.
141141
* Fix - Re-enable the "Place order" button on the block checkout after closing the WeChat or Cash App payment modal.
142142
* Fix - When SEPA tokens are added via the My Account > Payment methods page, ensure they are attached to the Stripe customer.
143+
* Fix - Clear the saved Stripe Link payment methods when a customer cache is cleared to ensure cached methods are updated promptly.
144+
* Fix - Display Stripe Link payment methods correctly in both Block Checkout and My Account pages.
145+
* Fix - Resolve an error when adding a saved card payment method in My Account when Stripe Link is enabled.
143146
* Fix - Resolved an error when using 3D Secure-enabled cards with Stripe Link enabled.
144147
* Fix - Corrected setup intent payment method types to include 'link' when Stripe Link is enabled, resolving errors during subscription signups.
145148
* Fix - Resolved an issue where changing the payment method for subscriptions failed after 3D-Secure authentication.

0 commit comments

Comments
 (0)