Skip to content

Commit dc56c8f

Browse files
committed
Save payment method info in subscription
1 parent 88b7a08 commit dc56c8f

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

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

+21-9
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,17 @@ private function process_payment_with_confirmation_token( int $order_id ) {
10391039
}
10401040
}
10411041

1042+
if ( $payment_information['has_subscription'] ) {
1043+
$this->maybe_update_source_on_subscription_order(
1044+
$order,
1045+
(object) [
1046+
'payment_method' => $payment_method_id,
1047+
'customer' => $payment_information['customer'],
1048+
],
1049+
'stripe' // TODO: get the correct payment gateway ID
1050+
);
1051+
}
1052+
10421053
$return_url = $this->get_return_url( $order );
10431054

10441055
return [
@@ -2213,6 +2224,7 @@ protected function prepare_payment_information_from_request( WC_Order $order ) {
22132224
'payment_method_details' => [],
22142225
'payment_type' => 'single', // single | recurring.
22152226
'capture_method' => $capture_method,
2227+
'save_payment_method_to_store' => $save_payment_method_to_store,
22162228
];
22172229

22182230
if ( 'us_bank_account' === $selected_payment_type ) {
@@ -2224,22 +2236,22 @@ protected function prepare_payment_information_from_request( WC_Order $order ) {
22242236
unset( $payment_information['payment_method_details'] );
22252237
unset( $payment_information['capture_method'] );
22262238

2227-
$confirmation_token_id = sanitize_text_field( wp_unslash( $_POST['wc-stripe-confirmation-token'] ?? '' ) );
2228-
$payment_information['confirmation_token'] = $confirmation_token_id;
2229-
$payment_information['save_payment_method_to_store'] = false; // TODO Is this needed for subscriptions?
2230-
$payment_information['payment_method_options'] = $this->get_payment_method_options_for_confirmation_tokens(
2239+
$confirmation_token_id = sanitize_text_field( wp_unslash( $_POST['wc-stripe-confirmation-token'] ?? '' ) );
2240+
$payment_information['confirmation_token'] = $confirmation_token_id;
2241+
$payment_information['payment_method_options'] = $this->get_payment_method_options_for_confirmation_tokens(
22312242
$selected_payment_type,
22322243
[
22332244
'capture_method' => $capture_method,
22342245
'has_subscription' => $payment_information['has_subscription'],
22352246
]
22362247
);
2248+
// TODO: remove this once Amazon Pay supports saved payment methods
2249+
$payment_information['save_payment_method_to_store'] = false;
22372250
} else {
2238-
$payment_method_details = WC_Stripe_API::get_payment_method( $payment_method_id );
2239-
$payment_information['payment_method'] = $payment_method_id;
2240-
$payment_information['payment_method_details'] = $payment_method_details;
2241-
$payment_information['save_payment_method_to_store'] = $save_payment_method_to_store;
2242-
$payment_information['payment_method_options'] = $this->get_payment_method_options(
2251+
$payment_method_details = WC_Stripe_API::get_payment_method( $payment_method_id );
2252+
$payment_information['payment_method'] = $payment_method_id;
2253+
$payment_information['payment_method_details'] = $payment_method_details;
2254+
$payment_information['payment_method_options'] = $this->get_payment_method_options(
22432255
$selected_payment_type,
22442256
$order,
22452257
$payment_method_details

0 commit comments

Comments
 (0)