From d4bfea0b0e3cc49bd864a53821b9c42134fd5dc3 Mon Sep 17 00:00:00 2001 From: Matt Allan Date: Wed, 28 Feb 2024 10:49:28 +1000 Subject: [PATCH] [Split PE] Fix purchasing with Alipay with our deferred intent changes (#2948) * Add alipay to the list of methods returned by getPaymentMethodConstants() * Properly redirect customers to alipay redirect URL * Make sure Alipay is labelled consistently with our other UPE methods * Make get_retrievable_type() return the stripe ID instead of null for non-reusable UPE methods * Fix unit tests * Update get_retrievable_type() unit tests * More unit test fixes --- client/stripe-utils/constants.js | 2 ++ .../class-wc-stripe-upe-payment-gateway.php | 6 +++--- ...class-wc-stripe-upe-payment-method-alipay.php | 2 +- .../class-wc-stripe-upe-payment-method.php | 2 +- .../test-class-wc-stripe-upe-payment-method.php | 16 ++++++++-------- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/stripe-utils/constants.js b/client/stripe-utils/constants.js index eace2f92ec..c11818b814 100644 --- a/client/stripe-utils/constants.js +++ b/client/stripe-utils/constants.js @@ -8,6 +8,7 @@ export const PAYMENT_METHOD_NAME_SOFORT = 'stripe_sofort'; export const PAYMENT_METHOD_NAME_BOLETO = 'stripe_boleto'; export const PAYMENT_METHOD_NAME_OXXO = 'stripe_oxxo'; export const PAYMENT_METHOD_NAME_BANCONTACT = 'stripe_bancontact'; +export const PAYMENT_METHOD_NAME_ALIPAY = 'stripe_alipay'; export function getPaymentMethodsConstants() { return { @@ -21,6 +22,7 @@ export function getPaymentMethodsConstants() { boleto: PAYMENT_METHOD_NAME_BOLETO, oxxo: PAYMENT_METHOD_NAME_OXXO, bancontact: PAYMENT_METHOD_NAME_BANCONTACT, + alipay: PAYMENT_METHOD_NAME_ALIPAY, }; } 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 b55bfb1490..9f152c8a08 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-gateway.php @@ -781,7 +781,7 @@ private function process_payment_with_deferred_intent( int $order_id ) { * Depending on the payment method used to process the payment, we may need to redirect the user to a URL for further processing. * * - Voucher payments (Boleto or Oxxo) respond with a hash URL so the client JS code can recognize the response, pull out the necessary args and handle the displaying of the voucher. - * - Other payment methods like Giropay, iDEAL etc require a redirect to a URL provided by Stripe. + * - Other payment methods like Giropay, iDEAL, Alipay etc require a redirect to a URL provided by Stripe. * - 3DS Card payments return a hash URL so the client JS code can recognize the response, pull out the necessary PI args and display the 3DS confirmation modal. */ if ( in_array( $payment_intent->status, [ 'requires_confirmation', 'requires_action' ], true ) ) { @@ -794,8 +794,8 @@ private function process_payment_with_deferred_intent( int $order_id ) { $payment_intent->client_secret, rawurlencode( $redirect ) ); - } elseif ( isset( $payment_intent->next_action->type ) && 'redirect_to_url' === $payment_intent->next_action->type && ! empty( $payment_intent->next_action->redirect_to_url->url ) ) { - $redirect = $payment_intent->next_action->redirect_to_url->url; + } elseif ( isset( $payment_intent->next_action->type ) && in_array( $payment_intent->next_action->type, [ 'redirect_to_url', 'alipay_handle_redirect' ], true ) && ! empty( $payment_intent->next_action->{$payment_intent->next_action->type}->url ) ) { + $redirect = $payment_intent->next_action->{$payment_intent->next_action->type}->url; } else { $redirect = sprintf( '#wc-stripe-confirm-%s:%s:%s:%s', diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method-alipay.php b/includes/payment-methods/class-wc-stripe-upe-payment-method-alipay.php index 876935bb03..35fee86b50 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method-alipay.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method-alipay.php @@ -18,7 +18,7 @@ class WC_Stripe_UPE_Payment_Method_Alipay extends WC_Stripe_UPE_Payment_Method { public function __construct() { parent::__construct(); $this->stripe_id = self::STRIPE_ID; - $this->title = __( 'Pay with Alipay', 'woocommerce-gateway-stripe' ); + $this->title = __( 'Alipay', 'woocommerce-gateway-stripe' ); $this->is_reusable = false; $this->supported_currencies = [ 'EUR', diff --git a/includes/payment-methods/class-wc-stripe-upe-payment-method.php b/includes/payment-methods/class-wc-stripe-upe-payment-method.php index cd5a5af0c8..147e00b72e 100644 --- a/includes/payment-methods/class-wc-stripe-upe-payment-method.php +++ b/includes/payment-methods/class-wc-stripe-upe-payment-method.php @@ -294,7 +294,7 @@ public function get_capabilities_response() { * to query to retrieve saved payment methods from Stripe. */ public function get_retrievable_type() { - return $this->is_reusable() ? WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID : null; + return $this->is_reusable() ? WC_Stripe_UPE_Payment_Method_Sepa::STRIPE_ID : static::STRIPE_ID; } /** diff --git a/tests/phpunit/test-class-wc-stripe-upe-payment-method.php b/tests/phpunit/test-class-wc-stripe-upe-payment-method.php index a71f94dd7c..03bca82e2b 100644 --- a/tests/phpunit/test-class-wc-stripe-upe-payment-method.php +++ b/tests/phpunit/test-class-wc-stripe-upe-payment-method.php @@ -237,17 +237,17 @@ public function test_payment_methods_show_correct_default_outputs() { $this->assertEquals( 'alipay', $alipay_method->get_id() ); $this->assertEquals( 'Alipay', $alipay_method->get_label() ); - $this->assertEquals( 'Pay with Alipay', $alipay_method->get_title() ); - $this->assertEquals( 'Pay with Alipay', $alipay_method->get_title( $mock_alipay_details ) ); + $this->assertEquals( 'Alipay', $alipay_method->get_title() ); + $this->assertEquals( 'Alipay', $alipay_method->get_title( $mock_alipay_details ) ); $this->assertFalse( $alipay_method->is_reusable() ); - $this->assertEquals( null, $alipay_method->get_retrievable_type() ); + $this->assertEquals( 'alipay', $alipay_method->get_retrievable_type() ); $this->assertEquals( 'giropay', $giropay_method->get_id() ); $this->assertEquals( 'giropay', $giropay_method->get_label() ); $this->assertEquals( 'giropay', $giropay_method->get_title() ); $this->assertEquals( 'giropay', $giropay_method->get_title( $mock_giropay_details ) ); $this->assertFalse( $giropay_method->is_reusable() ); - $this->assertEquals( null, $giropay_method->get_retrievable_type() ); + $this->assertEquals( 'giropay', $giropay_method->get_retrievable_type() ); $this->assertEquals( '', $giropay_method->get_testing_instructions() ); $this->assertEquals( 'p24', $p24_method->get_id() ); @@ -255,7 +255,7 @@ public function test_payment_methods_show_correct_default_outputs() { $this->assertEquals( 'Przelewy24', $p24_method->get_title() ); $this->assertEquals( 'Przelewy24', $p24_method->get_title( $mock_p24_details ) ); $this->assertFalse( $p24_method->is_reusable() ); - $this->assertEquals( null, $p24_method->get_retrievable_type() ); + $this->assertEquals( 'p24', $p24_method->get_retrievable_type() ); $this->assertEquals( '', $p24_method->get_testing_instructions() ); $this->assertEquals( 'eps', $eps_method->get_id() ); @@ -263,7 +263,7 @@ public function test_payment_methods_show_correct_default_outputs() { $this->assertEquals( 'EPS', $eps_method->get_title() ); $this->assertEquals( 'EPS', $eps_method->get_title( $mock_eps_details ) ); $this->assertFalse( $eps_method->is_reusable() ); - $this->assertEquals( null, $eps_method->get_retrievable_type() ); + $this->assertEquals( 'eps', $eps_method->get_retrievable_type() ); $this->assertEquals( '', $eps_method->get_testing_instructions() ); $this->assertEquals( 'sepa_debit', $sepa_method->get_id() ); @@ -306,7 +306,7 @@ public function test_payment_methods_show_correct_default_outputs() { $this->assertEquals( 'Boleto', $boleto_method->get_title() ); $this->assertEquals( 'Boleto', $boleto_method->get_title( $mock_boleto_details ) ); $this->assertFalse( $boleto_method->is_reusable() ); - $this->assertEquals( null, $boleto_method->get_retrievable_type() ); + $this->assertEquals( 'boleto', $boleto_method->get_retrievable_type() ); $this->assertEquals( '', $boleto_method->get_testing_instructions() ); $this->assertEquals( 'oxxo', $oxxo_method->get_id() ); @@ -314,7 +314,7 @@ public function test_payment_methods_show_correct_default_outputs() { $this->assertEquals( 'OXXO', $oxxo_method->get_title() ); $this->assertEquals( 'OXXO', $oxxo_method->get_title( $mock_oxxo_details ) ); $this->assertFalse( $oxxo_method->is_reusable() ); - $this->assertEquals( null, $oxxo_method->get_retrievable_type() ); + $this->assertEquals( 'oxxo', $oxxo_method->get_retrievable_type() ); $this->assertEquals( '', $oxxo_method->get_testing_instructions() ); }