Skip to content

Commit 23141d7

Browse files
authored
Add fraud and risk tools feature flag (#5645)
1 parent 91901d5 commit 23141d7

File tree

4 files changed

+69
-27
lines changed

4 files changed

+69
-27
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: dev
3+
4+
Add a feature flag for fraud and risk tools features.

includes/admin/class-wc-payments-admin.php

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -495,48 +495,49 @@ public function register_payments_scripts() {
495495
$account_status_data = $this->account->get_account_status_data();
496496

497497
$wcpay_settings = [
498-
'connectUrl' => WC_Payments_Account::get_connect_url(),
499-
'connect' => [
498+
'connectUrl' => WC_Payments_Account::get_connect_url(),
499+
'connect' => [
500500
'country' => WC()->countries->get_base_country(),
501501
'availableCountries' => WC_Payments_Utils::supported_countries(),
502502
'availableStates' => WC()->countries->get_states(),
503503
],
504-
'testMode' => WC_Payments::mode()->is_test(),
504+
'testMode' => WC_Payments::mode()->is_test(),
505505
// set this flag for use in the front-end to alter messages and notices if on-boarding has been disabled.
506-
'onBoardingDisabled' => WC_Payments_Account::is_on_boarding_disabled(),
507-
'errorMessage' => $error_message,
508-
'featureFlags' => $this->get_frontend_feature_flags(),
509-
'isSubscriptionsActive' => class_exists( 'WC_Subscriptions' ) && version_compare( WC_Subscriptions::$version, '2.2.0', '>=' ),
506+
'onBoardingDisabled' => WC_Payments_Account::is_on_boarding_disabled(),
507+
'errorMessage' => $error_message,
508+
'featureFlags' => $this->get_frontend_feature_flags(),
509+
'isSubscriptionsActive' => class_exists( 'WC_Subscriptions' ) && version_compare( WC_Subscriptions::$version, '2.2.0', '>=' ),
510510
// used in the settings page by the AccountFees component.
511-
'zeroDecimalCurrencies' => WC_Payments_Utils::zero_decimal_currencies(),
512-
'fraudServices' => $this->account->get_fraud_services_config(),
513-
'isJetpackConnected' => $this->payments_api_client->is_server_connected(),
514-
'isJetpackIdcActive' => Jetpack_Identity_Crisis::has_identity_crisis(),
515-
'accountStatus' => $account_status_data,
516-
'accountFees' => $this->account->get_fees(),
517-
'accountLoans' => $this->account->get_capital(),
518-
'accountEmail' => $this->account->get_account_email(),
519-
'showUpdateDetailsTask' => $this->get_should_show_update_business_details_task( $account_status_data ),
520-
'wpcomReconnectUrl' => $this->payments_api_client->is_server_connected() && ! $this->payments_api_client->has_server_connection_owner() ? WC_Payments_Account::get_wpcom_reconnect_url() : null,
521-
'additionalMethodsSetup' => [
511+
'zeroDecimalCurrencies' => WC_Payments_Utils::zero_decimal_currencies(),
512+
'fraudServices' => $this->account->get_fraud_services_config(),
513+
'isJetpackConnected' => $this->payments_api_client->is_server_connected(),
514+
'isJetpackIdcActive' => Jetpack_Identity_Crisis::has_identity_crisis(),
515+
'accountStatus' => $account_status_data,
516+
'accountFees' => $this->account->get_fees(),
517+
'accountLoans' => $this->account->get_capital(),
518+
'accountEmail' => $this->account->get_account_email(),
519+
'showUpdateDetailsTask' => $this->get_should_show_update_business_details_task( $account_status_data ),
520+
'wpcomReconnectUrl' => $this->payments_api_client->is_server_connected() && ! $this->payments_api_client->has_server_connection_owner() ? WC_Payments_Account::get_wpcom_reconnect_url() : null,
521+
'additionalMethodsSetup' => [
522522
'isUpeEnabled' => WC_Payments_Features::is_upe_enabled(),
523523
'upeType' => WC_Payments_Features::get_enabled_upe_type(),
524524
],
525-
'multiCurrencySetup' => [
525+
'multiCurrencySetup' => [
526526
'isSetupCompleted' => get_option( 'wcpay_multi_currency_setup_completed' ),
527527
],
528-
'isMultiCurrencyEnabled' => WC_Payments_Features::is_customer_multi_currency_enabled(),
529-
'isClientEncryptionEligible' => WC_Payments_Features::is_client_secret_encryption_eligible(),
530-
'shouldUseExplicitPrice' => WC_Payments_Explicit_Price_Formatter::should_output_explicit_price(),
531-
'overviewTasksVisibility' => [
528+
'isMultiCurrencyEnabled' => WC_Payments_Features::is_customer_multi_currency_enabled(),
529+
'isClientEncryptionEligible' => WC_Payments_Features::is_client_secret_encryption_eligible(),
530+
'shouldUseExplicitPrice' => WC_Payments_Explicit_Price_Formatter::should_output_explicit_price(),
531+
'overviewTasksVisibility' => [
532532
'dismissedTodoTasks' => get_option( 'woocommerce_dismissed_todo_tasks', [] ),
533533
'deletedTodoTasks' => get_option( 'woocommerce_deleted_todo_tasks', [] ),
534534
'remindMeLaterTodoTasks' => get_option( 'woocommerce_remind_me_later_todo_tasks', [] ),
535535
],
536-
'currentUserEmail' => $current_user_email,
537-
'currencyData' => $currency_data,
538-
'restUrl' => get_rest_url( null, '' ), // rest url to concatenate when merchant use Plain permalinks.
539-
'numDisputesNeedingResponse' => $this->get_disputes_awaiting_response_count(),
536+
'currentUserEmail' => $current_user_email,
537+
'currencyData' => $currency_data,
538+
'restUrl' => get_rest_url( null, '' ), // rest url to concatenate when merchant use Plain permalinks.
539+
'numDisputesNeedingResponse' => $this->get_disputes_awaiting_response_count(),
540+
'isFraudProtectionSettingsEnabled' => WC_Payments_Features::is_fraud_protection_settings_enabled(),
540541
];
541542

542543
wp_localize_script(

includes/class-wc-payments-features.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,15 @@ public static function is_progressive_onboarding_enabled(): bool {
226226
return '1' === get_option( self::PROGRESSIVE_ONBOARDING_FLAG_NAME, '0' );
227227
}
228228

229+
/**
230+
* Checks whether the Fraud and Risk Tools feature flag is enabled.
231+
*
232+
* @return bool
233+
*/
234+
public static function is_fraud_protection_settings_enabled(): bool {
235+
return '1' === get_option( 'wcpay_fraud_protection_settings_active', '0' );
236+
}
237+
229238
/**
230239
* Returns feature flags as an array suitable for display on the front-end.
231240
*

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,34 @@ public function test_split_upe_enabled_with_eligible_merchant() {
230230
$this->assertTrue( WC_Payments_Features::is_upe_split_enabled() );
231231
}
232232

233+
public function test_is_fraud_protection_settings_enabled_returns_true() {
234+
add_filter(
235+
'pre_option_wcpay_fraud_protection_settings_active',
236+
function ( $pre_option, $option, $default ) {
237+
return '1';
238+
},
239+
10,
240+
3
241+
);
242+
$this->assertTrue( WC_Payments_Features::is_fraud_protection_settings_enabled() );
243+
}
244+
245+
public function test_is_fraud_protection_settings_enabled_returns_false_when_flag_is_false() {
246+
add_filter(
247+
'pre_option_wcpay_fraud_protection_settings_active',
248+
function ( $pre_option, $option, $default ) {
249+
return '0';
250+
},
251+
10,
252+
3
253+
);
254+
$this->assertFalse( WC_Payments_Features::is_fraud_protection_settings_enabled() );
255+
}
256+
257+
public function test_is_fraud_protection_settings_enabled_returns_false_when_flag_is_not_set() {
258+
$this->assertFalse( WC_Payments_Features::is_fraud_protection_settings_enabled() );
259+
}
260+
233261
private function setup_enabled_flags( array $enabled_flags ) {
234262
foreach ( array_keys( self::FLAG_OPTION_NAME_TO_FRONTEND_KEY_MAPPING ) as $flag ) {
235263
add_filter(

0 commit comments

Comments
 (0)