Skip to content

Commit 1927b0b

Browse files
authored
Disable WooPay if WooPayments is not enabled as payment gateway (#9147)
1 parent 835a101 commit 1927b0b

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: fix
3+
4+
Disable WooPay if WooPayments is not enabled as payment gateway.

includes/class-wc-payments-features.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public static function is_streamline_refunds_enabled(): bool {
6262
* @return bool
6363
*/
6464
public static function is_woopay_enabled() {
65+
// If WooPayments is not enabled then disable WooPay.
66+
$enabled_gateways = WC()->payment_gateways->get_available_payment_gateways();
67+
if ( ! isset( $enabled_gateways['woocommerce_payments'] ) ) {
68+
return false;
69+
}
70+
6571
$is_woopay_eligible = self::is_woopay_eligible(); // Feature flag.
6672
$is_woopay_enabled = 'yes' === WC_Payments::get_gateway()->get_option( 'platform_checkout' );
6773
$is_woopay_express_button_enabled = self::is_woopay_express_checkout_enabled();

tests/unit/test-class-wc-payments-features.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ public function set_up() {
4848
->willReturn( false );
4949

5050
WC_Payments::set_account_service( $this->mock_wcpay_account );
51+
52+
add_filter(
53+
'woocommerce_available_payment_gateways',
54+
function () {
55+
return [
56+
'woocommerce_payments' => new class() extends WC_Payment_Gateway {
57+
},
58+
];
59+
}
60+
);
5161
}
5262

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

6777
// Restore the cache service in the main class.
6878
WC_Payments::set_database_cache( $this->_cache );
79+
80+
remove_all_filters( 'woocommerce_available_payment_gateways' );
81+
6982
parent::tear_down();
7083
}
7184

@@ -208,6 +221,12 @@ public function test_is_woopay_enabled_returns_false_when_ineligible() {
208221
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
209222
}
210223

224+
public function test_is_woopay_enabled_returns_false_when_woopayments_is_disabled() {
225+
remove_all_filters( 'woocommerce_available_payment_gateways' );
226+
227+
$this->assertFalse( WC_Payments_Features::is_woopay_enabled() );
228+
}
229+
211230
public function test_is_woopay_express_checkout_enabled_returns_true() {
212231
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
213232
$this->mock_cache->method( 'get' )->willReturn( [ 'platform_checkout_eligible' => true ] );
@@ -238,6 +257,12 @@ public function test_is_woopay_direct_checkout_enabled_returns_true() {
238257
$this->assertTrue( WC_Payments_Features::is_woopay_direct_checkout_enabled() );
239258
}
240259

260+
public function test_is_woopay_direct_checkout_enabled_returns_false_when_woopayments_is_disabled() {
261+
remove_all_filters( 'woocommerce_available_payment_gateways' );
262+
263+
$this->assertFalse( WC_Payments_Features::is_woopay_direct_checkout_enabled() );
264+
}
265+
241266
public function test_is_woopay_direct_checkout_enabled_returns_false_when_flag_is_false() {
242267
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_EXPRESS_CHECKOUT_FLAG_NAME, '1' );
243268
$this->set_feature_flag_option( WC_Payments_Features::WOOPAY_DIRECT_CHECKOUT_FLAG_NAME, '0' );

0 commit comments

Comments
 (0)