Skip to content

Commit

Permalink
feat: tokenized ECE flag via server-side control (#10389)
Browse files Browse the repository at this point in the history
  • Loading branch information
frosso authored Feb 19, 2025
1 parent 3eca1b3 commit 570cc98
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions changelog/feat-tokenized-ece-account-meta-control
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: dev: ability to disable the Tokenized ECE via server-side flag


4 changes: 3 additions & 1 deletion includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ public static function are_payments_enabled() {
* @return bool
*/
public static function is_tokenized_cart_ece_enabled(): bool {
return '1' === get_option( self::TOKENIZED_CART_ECE_FLAG_NAME, '0' );
$account = WC_Payments::get_database_cache()->get( WCPay\Database_Cache::ACCOUNT_KEY, true );

return is_array( $account ) && ! ( $account['is_tokenized_ece_disabled'] ?? false ) && '1' === get_option( self::TOKENIZED_CART_ECE_FLAG_NAME, '0' );
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/test-class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,34 @@ public function test_is_wcpay_frt_review_feature_active_returns_true() {
$this->clear_feature_flag_options( [ 'wcpay_frt_review_feature_active' ] );
}

public function test_is_tokenized_cart_ece_enabled_returns_true_when_site_flag_is_true() {
$this->mock_cache->method( 'get' )->willReturn( [] );
$this->set_feature_flag_option( '_wcpay_feature_tokenized_cart_ece', '1' );
$this->assertTrue( WC_Payments_Features::is_tokenized_cart_ece_enabled() );
$this->clear_feature_flag_options( [ '_wcpay_feature_tokenized_cart_ece' ] );
}

public function test_is_tokenized_cart_ece_enabled_returns_false_when_site_flag_is_false() {
$this->mock_cache->method( 'get' )->willReturn( [] );
$this->set_feature_flag_option( '_wcpay_feature_tokenized_cart_ece', '0' );
$this->assertFalse( WC_Payments_Features::is_tokenized_cart_ece_enabled() );
$this->clear_feature_flag_options( [ '_wcpay_feature_tokenized_cart_ece' ] );
}

public function test_is_tokenized_cart_ece_enabled_returns_false_when_account_flag_is_true() {
$this->mock_cache->method( 'get' )->willReturn( [ 'is_tokenized_ece_disabled' => true ] );
$this->set_feature_flag_option( '_wcpay_feature_tokenized_cart_ece', '1' );
$this->assertFalse( WC_Payments_Features::is_tokenized_cart_ece_enabled() );
$this->clear_feature_flag_options( [ '_wcpay_feature_tokenized_cart_ece' ] );
}

public function test_is_tokenized_cart_ece_enabled_returns_true_when_account_flag_is_false() {
$this->mock_cache->method( 'get' )->willReturn( [ 'is_tokenized_ece_disabled' => false ] );
$this->set_feature_flag_option( '_wcpay_feature_tokenized_cart_ece', '1' );
$this->assertTrue( WC_Payments_Features::is_tokenized_cart_ece_enabled() );
$this->clear_feature_flag_options( [ '_wcpay_feature_tokenized_cart_ece' ] );
}

public function test_is_frt_review_feature_active_returns_false_when_flag_is_not_set() {
$this->assertFalse( WC_Payments_Features::is_frt_review_feature_active() );
}
Expand Down

0 comments on commit 570cc98

Please sign in to comment.