Skip to content

Commit

Permalink
[Split PE] Fix purchasing with Alipay with our deferred intent changes (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
mattallan committed Feb 28, 2024
1 parent dc4241f commit d4bfea0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions client/stripe-utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand All @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
16 changes: 8 additions & 8 deletions tests/phpunit/test-class-wc-stripe-upe-payment-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,33 +237,33 @@ 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() );
$this->assertEquals( 'Przelewy24', $p24_method->get_label() );
$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() );
$this->assertEquals( 'EPS', $eps_method->get_label() );
$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() );
Expand Down Expand Up @@ -306,15 +306,15 @@ 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() );
$this->assertEquals( 'OXXO', $oxxo_method->get_label() );
$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() );
}

Expand Down

0 comments on commit d4bfea0

Please sign in to comment.