@@ -1071,6 +1071,14 @@ private function process_payment_with_confirmation_token( int $order_id ) {
1071
1071
}
1072
1072
}
1073
1073
1074
+ if ( $ payment_information ['save_payment_method_to_store ' ] ) {
1075
+ $ this ->handle_saving_payment_method (
1076
+ $ order ,
1077
+ $ payment_method ,
1078
+ $ selected_payment_type
1079
+ );
1080
+ }
1081
+
1074
1082
$ return_url = $ this ->get_return_url ( $ order );
1075
1083
1076
1084
return [
@@ -2223,6 +2231,8 @@ protected function prepare_payment_information_from_request( WC_Order $order ) {
2223
2231
2224
2232
if ( is_a ( $ token , 'WC_Payment_Token_SEPA ' ) ) {
2225
2233
$ selected_payment_type = WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID ;
2234
+ } elseif ( is_a ( $ token , 'WC_Payment_Token_Amazon_Pay ' ) ) {
2235
+ $ selected_payment_type = WC_Stripe_UPE_Payment_Method_Amazon_Pay::STRIPE_ID ;
2226
2236
}
2227
2237
} else {
2228
2238
$ payment_method_id = sanitize_text_field ( wp_unslash ( $ _POST ['wc-stripe-payment-method ' ] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Missing
@@ -2253,56 +2263,86 @@ protected function prepare_payment_information_from_request( WC_Order $order ) {
2253
2263
'return_url ' => $ this ->get_return_url_for_redirect ( $ order , $ save_payment_method_to_store ),
2254
2264
'use_stripe_sdk ' => 'true ' , // We want to use the SDK to handle next actions via the client payment elements. See https://docs.stripe.com/api/setup_intents/create#create_setup_intent-use_stripe_sdk
2255
2265
'has_subscription ' => $ this ->has_subscription ( $ order ->get_id () ),
2256
- 'payment_method ' => '' ,
2266
+ 'payment_method ' => $ payment_method_id ,
2257
2267
'payment_method_details ' => $ payment_method_details ,
2258
2268
'payment_type ' => 'single ' , // single | recurring.
2269
+ 'save_payment_method_to_store ' => $ save_payment_method_to_store ,
2270
+ 'capture_method ' => $ capture_method ,
2259
2271
];
2260
2272
2261
2273
if ( WC_Stripe_Payment_Methods::ACH === $ selected_payment_type ) {
2262
2274
WC_Stripe_API::attach_payment_method_to_customer ( $ payment_information ['customer ' ], $ payment_method_id );
2263
2275
}
2264
2276
2265
- if ( ! empty ( $ payment_method_id ) ) {
2266
- $ payment_information ['payment_method ' ] = $ payment_method_id ;
2267
- $ payment_information ['save_payment_method_to_store ' ] = $ save_payment_method_to_store ;
2268
- $ payment_information ['payment_method_options ' ] = $ this ->get_payment_method_options (
2277
+ // Use the dynamic + short statement descriptor if enabled and it's a card payment.
2278
+ $ is_short_statement_descriptor_enabled = 'yes ' === $ this ->get_option ( 'is_short_statement_descriptor_enabled ' , 'no ' );
2279
+ if ( WC_Stripe_Payment_Methods::CARD === $ selected_payment_type && $ is_short_statement_descriptor_enabled ) {
2280
+ $ payment_information ['statement_descriptor_suffix ' ] = WC_Stripe_Helper::get_dynamic_statement_descriptor_suffix ( $ order );
2281
+ }
2282
+
2283
+ if ( empty ( $ payment_method_id ) && ! empty ( $ _POST ['wc-stripe-confirmation-token ' ] ) ) {
2284
+ // Add fields that are only set when using the confirmation token flow.
2285
+ $ payment_information = $ this ->prepare_payment_information_for_confirmation_token (
2286
+ $ payment_information ,
2269
2287
$ selected_payment_type ,
2270
- $ order ,
2271
- $ payment_method_details
2288
+ $ capture_method ,
2272
2289
);
2273
- $ payment_information ['capture_method ' ] = $ capture_method ;
2274
2290
} else {
2275
- $ confirmation_token_id = sanitize_text_field ( wp_unslash ( $ _POST ['wc-stripe-confirmation-token ' ] ?? '' ) );
2276
- $ payment_information ['confirmation_token ' ] = $ confirmation_token_id ;
2277
- $ payment_information ['save_payment_method_to_store ' ] = false ;
2278
-
2279
- // When using confirmation tokens with manual capture, we need to
2280
- // set the capture_method parameter under payment method options.
2281
- if ( 'manual ' === $ capture_method ) {
2282
- $ payment_information ['payment_method_options ' ] = [
2283
- $ selected_payment_type => [
2284
- 'capture_method ' => 'manual ' ,
2285
- ],
2286
- ];
2287
- } else {
2288
- $ payment_information ['capture_method ' ] = $ capture_method ;
2289
- }
2291
+ // Add fields that are only set when using the payment method flow.
2292
+ $ payment_information = $ this ->prepare_payment_information_for_payment_method ( $ payment_information , $ selected_payment_type , $ order );
2293
+ }
2290
2294
2291
- // When using confirmation tokens for subscriptions, we need to set the setup_future_usage parameter under payment method options.
2292
- if ( $ payment_information ['has_subscription ' ] ) {
2293
- $ payment_information ['payment_method_options ' ][ $ selected_payment_type ]['setup_future_usage ' ] = 'off_session ' ;
2294
- }
2295
+ return $ payment_information ;
2296
+ }
2297
+
2298
+ /**
2299
+ * Add or remove payment information fields for the confirmation token flow.
2300
+ *
2301
+ * @param array $payment_information The base payment information.
2302
+ * @param string $selected_payment_type The selected payment type.
2303
+ * @param string $capture_method The capture method to be used.
2304
+ * @return array The customized payment information for the confirmation token flow.
2305
+ */
2306
+ private function prepare_payment_information_for_confirmation_token ( $ payment_information , $ selected_payment_type , $ capture_method ) {
2307
+ // These fields should not be set when using confirmation tokens to create a payment intent.
2308
+ unset( $ payment_information ['payment_method ' ] );
2309
+ unset( $ payment_information ['payment_method_details ' ] );
2310
+
2311
+ $ confirmation_token_id = sanitize_text_field ( wp_unslash ( $ _POST ['wc-stripe-confirmation-token ' ] ?? '' ) );
2312
+ $ payment_information ['confirmation_token ' ] = $ confirmation_token_id ;
2313
+
2314
+ // Some payment methods such as Amazon Pay will only accept a capture_method of 'manual'
2315
+ // under payment_method_options instead of at the top level.
2316
+ if ( 'manual ' === $ capture_method ) {
2317
+ unset( $ payment_information ['capture_method ' ] );
2318
+ $ payment_information ['payment_method_options ' ][ $ selected_payment_type ]['capture_method ' ] = 'manual ' ;
2295
2319
}
2296
2320
2297
- // Use the dynamic + short statement descriptor if enabled and it's a card payment.
2298
- $ is_short_statement_descriptor_enabled = 'yes ' === $ this ->get_option ( 'is_short_statement_descriptor_enabled ' , 'no ' );
2299
- if ( WC_Stripe_Payment_Methods::CARD === $ selected_payment_type && $ is_short_statement_descriptor_enabled ) {
2300
- $ payment_information ['statement_descriptor_suffix ' ] = WC_Stripe_Helper::get_dynamic_statement_descriptor_suffix ( $ order );
2321
+ if ( $ payment_information ['has_subscription ' ] ) {
2322
+ $ payment_information ['payment_method_options ' ][ $ selected_payment_type ]['setup_future_usage ' ] = 'off_session ' ;
2301
2323
}
2302
2324
2303
2325
return $ payment_information ;
2304
2326
}
2305
2327
2328
+ /**
2329
+ * Add or remove payment information fields for the payment method flow.
2330
+ *
2331
+ * @param array $payment_information The base payment information.
2332
+ * @param string $selected_payment_type The selected payment type.
2333
+ * @param WC_Order $order The WC Order being processed.
2334
+ * @return array The customized payment information for the payment method flow.
2335
+ */
2336
+ private function prepare_payment_information_for_payment_method ( $ payment_information , $ selected_payment_type , $ order ) {
2337
+ $ payment_information ['payment_method_options ' ] = $ this ->get_payment_method_options (
2338
+ $ selected_payment_type ,
2339
+ $ order ,
2340
+ $ payment_information ['payment_method_details ' ]
2341
+ );
2342
+
2343
+ return $ payment_information ;
2344
+ }
2345
+
2306
2346
/**
2307
2347
* Returns the payment method options for the selected payment type.
2308
2348
*
0 commit comments