Skip to content

Commit

Permalink
Disable Direct Checkout When WooPayments Gateway Is Disabled (#9203)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovo-h authored Aug 2, 2024
1 parent f525f7c commit dbfd6b6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
4 changes: 4 additions & 0 deletions changelog/fix-disable-woopay-dc-when-woopayments-disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Only enable Direct Checkout when WooPayments gateway is enabled.
14 changes: 13 additions & 1 deletion includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public static function is_woopay_direct_checkout_enabled() {
$is_direct_checkout_eligible = is_array( $account_cache ) && ( $account_cache['platform_direct_checkout_eligible'] ?? false );
$is_direct_checkout_flag_enabled = '1' === get_option( self::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );

return $is_direct_checkout_eligible && $is_direct_checkout_flag_enabled && self::is_woopay_enabled();
return $is_direct_checkout_eligible && $is_direct_checkout_flag_enabled && self::is_woopayments_gateway_enabled() && self::is_woopay_enabled();
}

/**
Expand Down Expand Up @@ -392,4 +392,16 @@ public static function to_array() {
]
);
}

/**
* Checks if WooCommerce Payments gateway is enabled.
*
* @return bool True if WooCommerce Payments gateway is enabled, false otherwise.
*/
private static function is_woopayments_gateway_enabled() {
$woopayments_settings = get_option( 'woocommerce_woocommerce_payments_settings' );
$woopayments_enabled_setting = $woopayments_settings['enabled'] ?? 'no';

return 'yes' === $woopayments_enabled_setting;
}
}
17 changes: 16 additions & 1 deletion tests/unit/test-class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ public function test_is_woopay_express_checkout_enabled_returns_false_when_woopa
$this->assertFalse( WC_Payments_Features::is_woopay_express_checkout_enabled() );
}

public function test_is_woopay_direct_checkout_enabled_returns_true() {
public function test_is_woopay_direct_checkout_enabled_returns_true_when_woopayments_gateway_enabled() {
update_option( 'woocommerce_woocommerce_payments_settings', [ 'enabled' => 'yes' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );
$this->mock_cache->method( 'get' )->willReturn(
Expand All @@ -238,6 +239,19 @@ public function test_is_woopay_direct_checkout_enabled_returns_true() {
$this->assertTrue( WC_Payments_Features::is_woopay_direct_checkout_enabled() );
}

public function test_is_woopay_direct_checkout_enabled_returns_false_when_woopayments_gateway_disabled() {
update_option( 'woocommerce_woocommerce_payments_settings', [ 'enabled' => 'no' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );
$this->mock_cache->method( 'get' )->willReturn(
[
'platform_checkout_eligible' => true,
'platform_direct_checkout_eligible' => true,
]
);
$this->assertFalse( WC_Payments_Features::is_woopay_direct_checkout_enabled() );
}

public function test_is_woopay_direct_checkout_enabled_returns_false_when_flag_is_false() {
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '0' );
Expand All @@ -263,6 +277,7 @@ public function test_is_woopay_direct_checkout_enabled_returns_false_when_woopay
}

public function test_is_woopay_direct_checkout_enabled_returns_true_when_first_party_auth_is_disabled() {
update_option( 'woocommerce_woocommerce_payments_settings', [ 'enabled' => 'yes' ] );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_FIRST_PARTY_AUTH_FLAG_NAME, '0' );
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '1' );
Expand Down

0 comments on commit dbfd6b6

Please sign in to comment.