Skip to content

Commit

Permalink
Add fraud and risk tools feature flag (#5645)
Browse files Browse the repository at this point in the history
  • Loading branch information
allie500 authored Feb 28, 2023
1 parent 91901d5 commit 23141d7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
4 changes: 4 additions & 0 deletions changelog/add-3046-add-fraud-and-risk-tools-feature-flag
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Add a feature flag for fraud and risk tools features.
55 changes: 28 additions & 27 deletions includes/admin/class-wc-payments-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -495,48 +495,49 @@ public function register_payments_scripts() {
$account_status_data = $this->account->get_account_status_data();

$wcpay_settings = [
'connectUrl' => WC_Payments_Account::get_connect_url(),
'connect' => [
'connectUrl' => WC_Payments_Account::get_connect_url(),
'connect' => [
'country' => WC()->countries->get_base_country(),
'availableCountries' => WC_Payments_Utils::supported_countries(),
'availableStates' => WC()->countries->get_states(),
],
'testMode' => WC_Payments::mode()->is_test(),
'testMode' => WC_Payments::mode()->is_test(),
// set this flag for use in the front-end to alter messages and notices if on-boarding has been disabled.
'onBoardingDisabled' => WC_Payments_Account::is_on_boarding_disabled(),
'errorMessage' => $error_message,
'featureFlags' => $this->get_frontend_feature_flags(),
'isSubscriptionsActive' => class_exists( 'WC_Subscriptions' ) && version_compare( WC_Subscriptions::$version, '2.2.0', '>=' ),
'onBoardingDisabled' => WC_Payments_Account::is_on_boarding_disabled(),
'errorMessage' => $error_message,
'featureFlags' => $this->get_frontend_feature_flags(),
'isSubscriptionsActive' => class_exists( 'WC_Subscriptions' ) && version_compare( WC_Subscriptions::$version, '2.2.0', '>=' ),
// used in the settings page by the AccountFees component.
'zeroDecimalCurrencies' => WC_Payments_Utils::zero_decimal_currencies(),
'fraudServices' => $this->account->get_fraud_services_config(),
'isJetpackConnected' => $this->payments_api_client->is_server_connected(),
'isJetpackIdcActive' => Jetpack_Identity_Crisis::has_identity_crisis(),
'accountStatus' => $account_status_data,
'accountFees' => $this->account->get_fees(),
'accountLoans' => $this->account->get_capital(),
'accountEmail' => $this->account->get_account_email(),
'showUpdateDetailsTask' => $this->get_should_show_update_business_details_task( $account_status_data ),
'wpcomReconnectUrl' => $this->payments_api_client->is_server_connected() && ! $this->payments_api_client->has_server_connection_owner() ? WC_Payments_Account::get_wpcom_reconnect_url() : null,
'additionalMethodsSetup' => [
'zeroDecimalCurrencies' => WC_Payments_Utils::zero_decimal_currencies(),
'fraudServices' => $this->account->get_fraud_services_config(),
'isJetpackConnected' => $this->payments_api_client->is_server_connected(),
'isJetpackIdcActive' => Jetpack_Identity_Crisis::has_identity_crisis(),
'accountStatus' => $account_status_data,
'accountFees' => $this->account->get_fees(),
'accountLoans' => $this->account->get_capital(),
'accountEmail' => $this->account->get_account_email(),
'showUpdateDetailsTask' => $this->get_should_show_update_business_details_task( $account_status_data ),
'wpcomReconnectUrl' => $this->payments_api_client->is_server_connected() && ! $this->payments_api_client->has_server_connection_owner() ? WC_Payments_Account::get_wpcom_reconnect_url() : null,
'additionalMethodsSetup' => [
'isUpeEnabled' => WC_Payments_Features::is_upe_enabled(),
'upeType' => WC_Payments_Features::get_enabled_upe_type(),
],
'multiCurrencySetup' => [
'multiCurrencySetup' => [
'isSetupCompleted' => get_option( 'wcpay_multi_currency_setup_completed' ),
],
'isMultiCurrencyEnabled' => WC_Payments_Features::is_customer_multi_currency_enabled(),
'isClientEncryptionEligible' => WC_Payments_Features::is_client_secret_encryption_eligible(),
'shouldUseExplicitPrice' => WC_Payments_Explicit_Price_Formatter::should_output_explicit_price(),
'overviewTasksVisibility' => [
'isMultiCurrencyEnabled' => WC_Payments_Features::is_customer_multi_currency_enabled(),
'isClientEncryptionEligible' => WC_Payments_Features::is_client_secret_encryption_eligible(),
'shouldUseExplicitPrice' => WC_Payments_Explicit_Price_Formatter::should_output_explicit_price(),
'overviewTasksVisibility' => [
'dismissedTodoTasks' => get_option( 'woocommerce_dismissed_todo_tasks', [] ),
'deletedTodoTasks' => get_option( 'woocommerce_deleted_todo_tasks', [] ),
'remindMeLaterTodoTasks' => get_option( 'woocommerce_remind_me_later_todo_tasks', [] ),
],
'currentUserEmail' => $current_user_email,
'currencyData' => $currency_data,
'restUrl' => get_rest_url( null, '' ), // rest url to concatenate when merchant use Plain permalinks.
'numDisputesNeedingResponse' => $this->get_disputes_awaiting_response_count(),
'currentUserEmail' => $current_user_email,
'currencyData' => $currency_data,
'restUrl' => get_rest_url( null, '' ), // rest url to concatenate when merchant use Plain permalinks.
'numDisputesNeedingResponse' => $this->get_disputes_awaiting_response_count(),
'isFraudProtectionSettingsEnabled' => WC_Payments_Features::is_fraud_protection_settings_enabled(),
];

wp_localize_script(
Expand Down
9 changes: 9 additions & 0 deletions includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ public static function is_progressive_onboarding_enabled(): bool {
return '1' === get_option( self::PROGRESSIVE_ONBOARDING_FLAG_NAME, '0' );
}

/**
* Checks whether the Fraud and Risk Tools feature flag is enabled.
*
* @return bool
*/
public static function is_fraud_protection_settings_enabled(): bool {
return '1' === get_option( 'wcpay_fraud_protection_settings_active', '0' );
}

/**
* Returns feature flags as an array suitable for display on the front-end.
*
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 @@ -230,6 +230,34 @@ public function test_split_upe_enabled_with_eligible_merchant() {
$this->assertTrue( WC_Payments_Features::is_upe_split_enabled() );
}

public function test_is_fraud_protection_settings_enabled_returns_true() {
add_filter(
'pre_option_wcpay_fraud_protection_settings_active',
function ( $pre_option, $option, $default ) {
return '1';
},
10,
3
);
$this->assertTrue( WC_Payments_Features::is_fraud_protection_settings_enabled() );
}

public function test_is_fraud_protection_settings_enabled_returns_false_when_flag_is_false() {
add_filter(
'pre_option_wcpay_fraud_protection_settings_active',
function ( $pre_option, $option, $default ) {
return '0';
},
10,
3
);
$this->assertFalse( WC_Payments_Features::is_fraud_protection_settings_enabled() );
}

public function test_is_fraud_protection_settings_enabled_returns_false_when_flag_is_not_set() {
$this->assertFalse( WC_Payments_Features::is_fraud_protection_settings_enabled() );
}

private function setup_enabled_flags( array $enabled_flags ) {
foreach ( array_keys( self::FLAG_OPTION_NAME_TO_FRONTEND_KEY_MAPPING ) as $flag ) {
add_filter(
Expand Down

0 comments on commit 23141d7

Please sign in to comment.