@@ -413,7 +413,7 @@ public function update_payment_intent_ajax() {
413413 throw new Exception ( __ ( 'Unable to verify your request. Please reload the page and try again. ' , 'woocommerce-gateway-stripe ' ) );
414414 }
415415
416- wp_send_json_success ( $ this ->update_payment_intent ( $ payment_intent_id , $ order_id , $ save_payment_method , $ selected_upe_payment_type ), 200 );
416+ wp_send_json_success ( $ this ->update_intent ( $ payment_intent_id , $ order_id , $ save_payment_method , $ selected_upe_payment_type ), 200 );
417417 } catch ( Exception $ e ) {
418418 // Send back error so it can be displayed to the customer.
419419 wp_send_json_error (
@@ -427,19 +427,20 @@ public function update_payment_intent_ajax() {
427427 }
428428
429429 /**
430- * Updates payment intent to be able to save payment method.
430+ * Updates payment intent or setup intent to be able to save payment method.
431431 *
432432 * @since 5.6.0
433+ * @version x.x.x
433434 *
434- * @param {string} $payment_intent_id The id of the payment intent to update.
435+ * @param {string} $intent_id The id of the payment intent or setup intent to update.
435436 * @param {int} $order_id The id of the order if intent created from Order.
436437 * @param {boolean} $save_payment_method True if saving the payment method.
437438 * @param {string} $selected_upe_payment_type The name of the selected UPE payment type or empty string.
438439 *
439440 * @throws Exception If the update intent call returns with an error.
440441 * @return array|null An array with result of the update, or nothing
441442 */
442- public function update_payment_intent ( $ payment_intent_id = '' , $ order_id = null , $ save_payment_method = false , $ selected_upe_payment_type = '' ) {
443+ public function update_intent ( $ intent_id = '' , $ order_id = null , $ save_payment_method = false , $ selected_upe_payment_type = '' ) {
443444 $ order = wc_get_order ( $ order_id );
444445
445446 if ( ! is_a ( $ order , 'WC_Order ' ) ) {
@@ -451,16 +452,20 @@ public function update_payment_intent( $payment_intent_id = '', $order_id = null
451452 $ currency = $ order ->get_currency ();
452453 $ customer = new WC_Stripe_Customer ( wp_get_current_user ()->ID );
453454
454- if ( $ payment_intent_id ) {
455-
455+ if ( $ intent_id ) {
456456 $ request = [
457- 'amount ' => WC_Stripe_Helper::get_stripe_amount ( $ amount , strtolower ( $ currency ) ),
458- 'currency ' => strtolower ( $ currency ),
459457 'metadata ' => $ gateway ->get_metadata_from_order ( $ order ),
460458 /* translators: 1) blog name 2) order number */
461459 'description ' => sprintf ( __ ( '%1$s - Order %2$s ' , 'woocommerce-gateway-stripe ' ), wp_specialchars_decode ( get_bloginfo ( 'name ' ), ENT_QUOTES ), $ order ->get_order_number () ),
462460 ];
463461
462+ $ is_setup_intent = substr ( $ intent_id , 0 , 4 ) === 'seti ' ;
463+ if ( ! $ is_setup_intent ) {
464+ // These parameters are only supported for payment intents.
465+ $ request ['amount ' ] = WC_Stripe_Helper::get_stripe_amount ( $ amount , strtolower ( $ currency ) );
466+ $ request ['currency ' ] = strtolower ( $ currency );
467+ }
468+
464469 if ( '' !== $ selected_upe_payment_type ) {
465470 // Only update the payment_method_types if we have a reference to the payment type the customer selected.
466471 $ request ['payment_method_types ' ] = [ $ selected_upe_payment_type ];
@@ -488,16 +493,21 @@ public function update_payment_intent( $payment_intent_id = '', $order_id = null
488493
489494 $ level3_data = $ gateway ->get_level3_data_from_order ( $ order );
490495
496+ // Use "setup_intents" endpoint if `$intent_id` starts with `seti_`.
497+ $ endpoint = $ is_setup_intent ? 'setup_intents ' : 'payment_intents ' ;
491498 WC_Stripe_API::request_with_level3_data (
492499 $ request ,
493- "payment_intents / {$ payment_intent_id }" ,
500+ "{ $ endpoint } / {$ intent_id }" ,
494501 $ level3_data ,
495502 $ order
496503 );
497504
498- $ order ->update_status ( OrderStatus::PENDING , __ ( 'Awaiting payment. ' , 'woocommerce-gateway-stripe ' ) );
505+ // Prevent any failures if updating the status of a subscription order.
506+ if ( ! $ gateway ->has_subscription ( $ order_id ) ) {
507+ $ order ->update_status ( OrderStatus::PENDING , __ ( 'Awaiting payment. ' , 'woocommerce-gateway-stripe ' ) );
508+ }
499509 $ order ->save ();
500- WC_Stripe_Helper::add_payment_intent_to_order ( $ payment_intent_id , $ order );
510+ WC_Stripe_Helper::add_payment_intent_to_order ( $ intent_id , $ order );
501511 }
502512
503513 return [
@@ -822,8 +832,8 @@ private function maybe_add_mandate_options( $request, $payment_method_type, $is_
822832 $ request ['payment_method_options ' ] = [
823833 WC_Stripe_Payment_Methods::ACSS_DEBIT => [
824834 'mandate_options ' => [
825- 'payment_schedule ' => 'interval ' ,
826- 'interval_description ' => __ ( 'One-time payment ' , 'woocommerce-gateway-stripe ' ), // TODO: Change to cadence if purchasing a subscription.
835+ 'payment_schedule ' => 'combined ' ,
836+ 'interval_description ' => __ ( 'Payments as per agreement ' , 'woocommerce-gateway-stripe ' ),
827837 'transaction_type ' => 'personal ' ,
828838 ],
829839 ],
0 commit comments