Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine the proper setting for split UPE to work with WooPay #6828

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/fix-split-upe-with-woopay-and-multiple-pms
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Improve split UPE support of WooPay with multiple payment methods enabled.
2 changes: 1 addition & 1 deletion includes/class-wc-payments-checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public function get_payment_fields_js_config() {
'genericErrorMessage' => __( 'There was a problem processing the payment. Please check your email inbox and refresh the page to try again.', 'woocommerce-payments' ),
'fraudServices' => $this->account->get_fraud_services_config(),
'features' => $this->gateway->supports,
'forceNetworkSavedCards' => WC_Payments::is_network_saved_cards_enabled() || $this->gateway->should_use_stripe_platform_on_checkout_page(),
'forceNetworkSavedCards' => WC_Payments::is_network_saved_cards_enabled() || WC_Payments::get_registered_card_gateway()->should_use_stripe_platform_on_checkout_page(),
'locale' => WC_Payments_Utils::convert_to_stripe_locale( get_locale() ),
'isPreview' => is_preview(),
'isUPEEnabled' => WC_Payments_Features::is_upe_enabled(),
Expand Down
9 changes: 9 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,15 @@ public static function get_registered_card_gateway() {
return self::$registered_card_gateway;
}

/**
* Sets registered card gateway instance.
*
* @param WC_Payment_Gateway_WCPay|UPE_Payment_Gateway|UPE_Split_Payment_Gateway $gateway Gateway instance.
*/
public static function set_registered_card_gateway( $gateway ) {
self::$registered_card_gateway = $gateway;
}

/**
* Called on Payments setting page.
*
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test-class-wc-payment-gateway-wcpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -2172,6 +2172,8 @@ public function test_force_network_saved_cards_is_returned_as_true_if_should_use
->method( 'should_use_stripe_platform_on_checkout_page' )
->willReturn( true );

WC_Payments::set_registered_card_gateway( $mock_wcpay_gateway );

$payments_checkout = new WC_Payments_Checkout(
$mock_wcpay_gateway,
$this->woopay_utilities,
Expand All @@ -2182,6 +2184,26 @@ public function test_force_network_saved_cards_is_returned_as_true_if_should_use
$this->assertTrue( $payments_checkout->get_payment_fields_js_config()['forceNetworkSavedCards'] );
}

public function test_force_network_saved_cards_is_returned_as_false_if_should_not_use_stripe_platform() {
$mock_wcpay_gateway = $this->get_partial_mock_for_gateway( [ 'should_use_stripe_platform_on_checkout_page' ] );

$mock_wcpay_gateway
->expects( $this->once() )
->method( 'should_use_stripe_platform_on_checkout_page' )
->willReturn( false );

WC_Payments::set_registered_card_gateway( $mock_wcpay_gateway );

$payments_checkout = new WC_Payments_Checkout(
$mock_wcpay_gateway,
$this->woopay_utilities,
$this->mock_wcpay_account,
$this->mock_customer_service
);

$this->assertFalse( $payments_checkout->get_payment_fields_js_config()['forceNetworkSavedCards'] );
}

public function test_is_woopay_enabled_returns_false_if_ineligible() {
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => false ] );
$this->assertFalse( $this->payments_checkout->get_payment_fields_js_config()['isWooPayEnabled'] );
Expand Down