From dc4241f85665bca5d36ebde5f048cbf0c1a255ae Mon Sep 17 00:00:00 2001 From: Matt Allan Date: Wed, 28 Feb 2024 10:47:34 +1000 Subject: [PATCH] [Split PE] Fix errors on checkout caused by attempting to reuse intents that require action or require manual confirmation (#2952) * Don't reuse payment intents that require action or manual confirmation * Fix unit test --- .../class-wc-stripe-upe-payment-gateway.php | 12 ++++++++++-- .../test-class-wc-stripe-upe-payment-gateway.php | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php index 6d2920df1e..b55bfb1490 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -2274,11 +2274,14 @@ private function get_return_url_for_redirect( $order, $save_payment_method ) { ); } - /* Retrieves the (possible) existing payment intent for an order and payment method types. + /** + * Retrieves the (possible) existing payment intent for an order and payment method types. * * @param WC_Order $order The order. - * @param array $payment_method_types The payment method types. + * @param array $payment_method_types The payment method types. + * * @return object|null + * * @throws WC_Stripe_Exception */ private function get_existing_compatible_payment_intent( $order, $payment_method_types ) { @@ -2299,6 +2302,11 @@ private function get_existing_compatible_payment_intent( $order, $payment_method return null; } + // If the intent requires confirmation to show voucher on checkout (i.e. Boleto or oxxo ) or requires action (i.e. need to show a 3DS confirmation card or handle the UPE redirect), don't reuse the intent + if ( in_array( $intent->status, [ 'requires_confirmation', 'requires_action' ], true ) ) { + return null; + } + return $intent; } diff --git a/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php b/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php index 2a38d35d4e..497438603f 100644 --- a/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php +++ b/tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php @@ -1883,7 +1883,7 @@ public function test_process_payment_deferred_intent_with_existing_intent() { $this->mock_gateway->intent_controller ->expects( $this->once() ) - ->method( 'update_and_confirm_payment_intent' ) + ->method( 'create_and_confirm_payment_intent' ) ->willReturn( $mock_intent ); $this->mock_gateway