Skip to content

Commit

Permalink
Disable WooPay if WooPayments is not enabled as payment gateway (#9147)
Browse files Browse the repository at this point in the history
  • Loading branch information
asumaran authored and lovo-h committed Aug 1, 2024
1 parent fe3b68d commit dcdc987
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions changelog/as-disable-dc-if-woopayments-disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Disable WooPay if WooPayments is not enabled as payment gateway.
6 changes: 6 additions & 0 deletions includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public static function is_streamline_refunds_enabled(): bool {
* @return bool
*/
public static function is_woopay_enabled() {
// If WooPayments is not enabled then disable WooPay.
$enabled_gateways = WC()->payment_gateways->get_available_payment_gateways();
if ( ! isset( $enabled_gateways['woocommerce_payments'] ) ) {
return false;
}

$is_woopay_eligible = self::is_woopay_eligible(); // Feature flag.
$is_woopay_enabled = 'yes' === WC_Payments::get_gateway()->get_option( 'platform_checkout' );
$is_woopay_express_button_enabled = self::is_woopay_express_checkout_enabled();
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/test-class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ public function set_up() {
->willReturn( false );

WC_Payments::set_account_service( $this->mock_wcpay_account );

add_filter(
'woocommerce_available_payment_gateways',
function () {
return [
'woocommerce_payments' => new class() extends WC_Payment_Gateway {
},
];
}
);
}

public function tear_down() {
Expand All @@ -66,6 +76,9 @@ function ( $key ) {

// Restore the cache service in the main class.
WC_Payments::set_database_cache( $this->_cache );

remove_all_filters( 'woocommerce_available_payment_gateways' );

parent::tear_down();
}

Expand Down Expand Up @@ -208,6 +221,12 @@ public function test_is_woopay_enabled_returns_false_when_ineligible() {
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_enabled_returns_false_when_woopayments_is_disabled() {
remove_all_filters( 'woocommerce_available_payment_gateways' );

$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
}

public function test_is_woopay_express_checkout_enabled_returns_true() {
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );
Expand Down Expand Up @@ -238,6 +257,12 @@ 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_is_disabled() {
remove_all_filters( 'woocommerce_available_payment_gateways' );

$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 Down

0 comments on commit dcdc987

Please sign in to comment.