Skip to content

Commit

Permalink
[Split PE] Fix errors on checkout caused by attempting to reuse inten…
Browse files Browse the repository at this point in the history
…ts that require action or require manual confirmation (#2952)

* Don't reuse payment intents that require action or manual confirmation

* Fix unit test
  • Loading branch information
mattallan authored Feb 28, 2024
1 parent 81a6849 commit dc4241f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/test-class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc4241f

Please sign in to comment.