Skip to content

Commit a119790

Browse files
authored
Fix Subscriptions compatibility with SEPA (#4280)
- Fix purchasing a subscription using SEPA - Fix updating the payment method of an existing subscription to SEPA
1 parent 1e71526 commit a119790

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,8 +1241,8 @@ public function confirm_change_payment_from_setup_intent_ajax() {
12411241

12421242
// Set the new Stripe payment method ID and customer ID on the subscription.
12431243
$customer = new WC_Stripe_Customer( wp_get_current_user()->ID );
1244-
$gateway->set_customer_id_for_order( $subscription, $customer->get_id() );
1245-
$gateway->set_payment_method_id_for_order( $subscription, $token->get_token() );
1244+
$gateway->set_customer_id_for_subscription( $subscription, $customer->get_id() );
1245+
$gateway->set_payment_method_id_for_subscription( $subscription, $token->get_token() );
12461246

12471247
// Check if the subscription has the delayed update all flag and attempt to update all subscriptions after the intent has been confirmed. If successful, display the "updated all subscriptions" notice.
12481248
if ( WC_Subscriptions_Change_Payment_Gateway::will_subscription_update_all_payment_methods( $subscription ) && WC_Subscriptions_Change_Payment_Gateway::update_all_payment_methods_from_subscription( $subscription, $token->get_gateway_id() ) ) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ public function process_change_subscription_payment_with_deferred_intent( $subsc
319319
WC_Subscriptions_Change_Payment_Gateway::update_payment_method( $subscription, $new_payment_method );
320320

321321
// Attach the new payment method ID and the customer ID to the subscription on success.
322-
$this->set_payment_method_id_for_order( $subscription, $payment_method_id );
323-
$this->set_customer_id_for_order( $subscription, $payment_information['customer'] );
322+
$this->set_payment_method_id_for_subscription( $subscription, $payment_method_id );
323+
$this->set_customer_id_for_subscription( $subscription, $payment_information['customer'] );
324324

325325
// Trigger wc_stripe_change_subs_payment_method_success action hook to preserve backwards compatibility, see process_change_subscription_payment_method().
326326
do_action(

includes/payment-methods/class-wc-stripe-upe-payment-gateway.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,13 +2692,15 @@ protected function handle_saving_payment_method( WC_Order $order, $payment_metho
26922692
// If the payment method object is a Link payment method, use Link as the payment method type.
26932693
if ( isset( $payment_method_object->type ) && WC_Stripe_Payment_Methods::LINK === $payment_method_object->type ) {
26942694
$payment_method_type = WC_Stripe_Payment_Methods::LINK;
2695+
$payment_method_instance = $this->get_payment_method_instance( $payment_method_type );
26952696
} elseif ( $this->spe_enabled && isset( $payment_method_object->type ) ) {
26962697
// When SPE is enabled, use the payment method type from the payment method object
26972698
$payment_method_type = $payment_method_object->type;
2699+
$payment_method_instance = $this->get_payment_method_instance( $payment_method_type );
2700+
} else {
2701+
$payment_method_instance = $this->payment_methods[ $payment_method_type ];
26982702
}
26992703

2700-
$payment_method_instance = $this->get_payment_method_instance( $payment_method_type );
2701-
27022704
// Searches for an existing duplicate token to update.
27032705
$found_token = WC_Stripe_Payment_Tokens::get_duplicate_token( $payment_method_object, $customer->get_user_id(), $this->id );
27042706

@@ -2736,6 +2738,17 @@ public function set_payment_method_id_for_order( WC_Order $order, string $paymen
27362738
$order->save_meta_data();
27372739
}
27382740

2741+
/**
2742+
* Set the payment metadata for payment method id for subscription.
2743+
*
2744+
* @param WC_Subscription $order The order.
2745+
* @param string $payment_method_id The value to be set.
2746+
*/
2747+
public function set_payment_method_id_for_subscription( $subscription, string $payment_method_id ) {
2748+
$subscription->update_meta_data( '_stripe_source_id', $payment_method_id );
2749+
$subscription->save_meta_data();
2750+
}
2751+
27392752
/**
27402753
* Set the payment metadata for customer id.
27412754
*
@@ -2749,6 +2762,19 @@ public function set_customer_id_for_order( WC_Order $order, string $customer_id
27492762
$order->save_meta_data();
27502763
}
27512764

2765+
/**
2766+
* Set the payment metadata for customer id for subscription.
2767+
*
2768+
* Set to public so it can be called from confirm_change_payment_from_setup_intent_ajax()
2769+
*
2770+
* @param WC_Stripe_Order $order The order.
2771+
* @param string $customer_id The value to be set.
2772+
*/
2773+
public function set_customer_id_for_subscription( $subscription, string $customer_id ) {
2774+
$subscription->update_meta_data( '_stripe_customer_id', $customer_id );
2775+
$subscription->save_meta_data();
2776+
}
2777+
27522778
/**
27532779
* Set the payment metadata for the selected payment type.
27542780
*

0 commit comments

Comments
 (0)