Skip to content

Commit

Permalink
chore: delete old feature flags from DB (#9263)
Browse files Browse the repository at this point in the history
Co-authored-by: Guilherme Pressutto <gpressutto5@gmail.com>
  • Loading branch information
frosso and gpressutto5 authored Aug 15, 2024
1 parent 6cd25af commit 3a443f5
Show file tree
Hide file tree
Showing 9 changed files with 149 additions and 41 deletions.
5 changes: 5 additions & 0 deletions changelog/chore-delete-old-feature-flags
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Significance: patch
Type: dev
Comment: chore: delete old feature flags from DB


6 changes: 0 additions & 6 deletions client/payment-details/summary/test/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ declare const global: {
};
featureFlags: {
isAuthAndCaptureEnabled: boolean;
isRefundControlsEnabled: boolean;
};
};
};
Expand Down Expand Up @@ -185,7 +184,6 @@ describe( 'PaymentDetailsSummary', () => {
},
featureFlags: {
isAuthAndCaptureEnabled: true,
isRefundControlsEnabled: false,
},
currencyData: {
US: {
Expand Down Expand Up @@ -921,8 +919,6 @@ describe( 'PaymentDetailsSummary', () => {

describe( 'order missing notice', () => {
test( 'renders notice if order missing', () => {
global.wcpaySettings.featureFlags.isRefundControlsEnabled = true;

const charge = getBaseCharge();
charge.order = null;

Expand All @@ -942,8 +938,6 @@ describe( 'PaymentDetailsSummary', () => {
} );

test( 'does not render notice if order present', () => {
global.wcpaySettings.featureFlags.isRefundControlsEnabled = true;

const charge = getBaseCharge();

const container = renderCharge( charge );
Expand Down
26 changes: 6 additions & 20 deletions includes/class-wc-payments-features.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
* WC Payments Features class
*/
class WC_Payments_Features {
/**
* If you need to remove or deprecate a flag:
* - Please update the `Erase_Deprecated_Flags_And_Options` migration with:
* - The next version of WooPayments.
* - The flag to be deleted.
*/
const WCPAY_SUBSCRIPTIONS_FLAG_NAME = '_wcpay_feature_subscriptions';
const STRIPE_BILLING_FLAG_NAME = '_wcpay_feature_stripe_billing';
const STRIPE_ECE_FLAG_NAME = '_wcpay_feature_stripe_ece';
Expand All @@ -23,7 +29,6 @@ class WC_Payments_Features {
const WOOPAY_DIRECT_CHECKOUT_FLAG_NAME = '_wcpay_feature_woopay_direct_checkout';
const AUTH_AND_CAPTURE_FLAG_NAME = '_wcpay_feature_auth_and_capture';
const DISPUTE_ISSUER_EVIDENCE = '_wcpay_feature_dispute_issuer_evidence';
const STREAMLINE_REFUNDS_FLAG_NAME = '_wcpay_feature_streamline_refunds';
const TOKENIZED_CART_PRB_FLAG_NAME = '_wcpay_feature_tokenized_cart_prb';
const PAYMENT_OVERVIEW_WIDGET_FLAG_NAME = '_wcpay_feature_payment_overview_widget';

Expand All @@ -47,15 +52,6 @@ public static function is_tokenized_cart_prb_enabled(): bool {
return '1' === get_option( self::TOKENIZED_CART_PRB_FLAG_NAME, '0' );
}

/**
* Checks whether streamline refunds is enabled.
*
* @return bool
*/
public static function is_streamline_refunds_enabled(): bool {
return '1' === get_option( self::STREAMLINE_REFUNDS_FLAG_NAME, '0' );
}

/**
* Checks if WooPay is enabled.
*
Expand Down Expand Up @@ -188,15 +184,6 @@ public static function maybe_enable_wcpay_subscriptions_after_onboarding( $onboa
update_option( self::WCPAY_SUBSCRIPTIONS_FLAG_NAME, '1' );
}

/**
* Returns whether WCPay Subscription migration is enabled
*
* @return bool
*/
public static function is_subscription_migration_enabled() {
return '1' === get_option( '_wcpay_feature_allow_subscription_migrations', '0' );
}

/**
* Checks whether woopay is enabled.
*
Expand Down Expand Up @@ -386,7 +373,6 @@ public static function to_array() {
'woopayExpressCheckout' => self::is_woopay_express_checkout_enabled(),
'isAuthAndCaptureEnabled' => self::is_auth_and_capture_enabled(),
'isDisputeIssuerEvidenceEnabled' => self::is_dispute_issuer_evidence_enabled(),
'isRefundControlsEnabled' => self::is_streamline_refunds_enabled(),
'isPaymentOverviewWidgetEnabled' => self::is_payment_overview_widget_ui_enabled(),
'isStripeEceEnabled' => self::is_stripe_ece_enabled(),
]
Expand Down
2 changes: 2 additions & 0 deletions includes/class-wc-payments.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ function () {
require_once __DIR__ . '/migrations/class-delete-active-woopay-webhook.php';
require_once __DIR__ . '/migrations/class-giropay-deprecation-settings-update.php';
require_once __DIR__ . '/migrations/class-erase-bnpl-announcement-meta.php';
require_once __DIR__ . '/migrations/class-erase-deprecated-flags-and-options.php';
add_action( 'woocommerce_woocommerce_payments_updated', [ new Allowed_Payment_Request_Button_Types_Update( self::get_gateway() ), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Allowed_Payment_Request_Button_Sizes_Update( self::get_gateway() ), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Update_Service_Data_From_Server( self::get_account_service() ), 'maybe_migrate' ] );
Expand All @@ -645,6 +646,7 @@ function () {
add_action( 'woocommerce_woocommerce_payments_updated', [ '\WCPay\Migrations\Delete_Active_WooPay_Webhook', 'maybe_delete' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Giropay_Deprecation_Settings_Update( self::get_gateway(), self::get_payment_gateway_map() ), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Erase_Bnpl_Announcement_Meta(), 'maybe_migrate' ] );
add_action( 'woocommerce_woocommerce_payments_updated', [ new \WCPay\Migrations\Erase_Deprecated_Flags_And_Options(), 'maybe_migrate' ] );

include_once WCPAY_ABSPATH . '/includes/class-wc-payments-explicit-price-formatter.php';
WC_Payments_Explicit_Price_Formatter::init();
Expand Down
63 changes: 63 additions & 0 deletions includes/migrations/class-erase-deprecated-flags-and-options.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* Class Erase_Deprecated_Flags_And_Options
*
* @package WooCommerce\Payments
*/

namespace WCPay\Migrations;

defined( 'ABSPATH' ) || exit;

/**
* Class Erase_Deprecated_Flags_And_Options
*
* Clearing up all flags and options that are no longer in use.
*
* @since 8.1.0
*/
class Erase_Deprecated_Flags_And_Options {
/**
* Checks whether it's worth doing the migration.
*/
public function maybe_migrate() {
$previous_version = get_option( 'woocommerce_woocommerce_payments_version' );
// feel free to modify the version here to the next one, if you add a new flag to be deleted in the `migrate` method.
if ( version_compare( '8.1.0', $previous_version, '>' ) ) {
$this->migrate();
}
}

/**
* Does the actual migration.
*/
private function migrate() {
// please update as necessary, when feature flags are removed.
// you don't need to check for previous values or if the migration already ran in previous versions.
// if the migration did already run, the operations below will just be noop.
delete_option( '_wcpay_feature_progressive_onboarding' );
delete_option( '_wcpay_feature_client_secret_encryption' );
delete_option( '_wcpay_feature_allow_subscription_migrations' );
delete_option( '_wcpay_feature_custom_deposit_schedules' );
delete_option( '_wcpay_feature_account_overview_task_list' );
delete_option( '_wcpay_feature_account_overview' );
delete_option( '_wcpay_feature_sepa' );
delete_option( '_wcpay_feature_sofort' );
delete_option( '_wcpay_feature_giropay' );
delete_option( '_wcpay_feature_grouped_settings' );
delete_option( '_wcpay_feature_upe_settings_preview' );
delete_option( '_wcpay_feature_upe' );
delete_option( '_wcpay_feature_upe_split' );
delete_option( '_wcpay_feature_upe_deferred_intent' );
delete_option( '_wcpay_feature_dispute_on_transaction_page' );
delete_option( '_wcpay_feature_streamline_refunds' );
delete_option( 'wcpay_fraud_protection_settings_active' );
delete_option( '_wcpay_feature_mc_order_meta_helper' );
delete_option( '_wcpay_feature_pay_for_order_flow' );
delete_option( '_wcpay_feature_simplify_deposits_ui' );
delete_option( '_wcpay_fraud_protection_settings_enabled' );
delete_option( '_wcpay_feature_platform_checkout_subscriptions_enabled' );
delete_option( '_wcpay_feature_platform_checkout' );
delete_option( '_wcpay_feature_capital' );
}
}
2 changes: 0 additions & 2 deletions tests/unit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ function () {
}
);

update_option( '_wcpay_feature_allow_subscription_migrations', '1' );

$_plugin_dir = __DIR__ . '/../../';

require $_plugin_dir . 'woocommerce-payments.php';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
/**
* Class Erase_Deprecated_Flags_And_Options_Test
*
* @package WooCommerce\Payments\Tests
*/

namespace unit\migrations;

use WCPay\Migrations\Erase_Deprecated_Flags_And_Options;
use WCPAY_UnitTestCase;

/**
* WCPay\Migrations\Erase_Deprecated_Flags_And_Options unit tests.
*/
class Erase_Deprecated_Flags_And_Options_Test extends WCPAY_UnitTestCase {

/**
* @var Erase_Deprecated_Flags_And_Options
*/
private $migration;

public function set_up() {
$this->migration = new Erase_Deprecated_Flags_And_Options();
// one of the old options, for which we'll test for.
update_option( '_wcpay_feature_grouped_settings', '1' );
// an unrelated option, that should not be deleted.
update_option( '_wcpay__unrelated_option', 'fake-value' );
}

public function tear_down() {
delete_option( '_wcpay_feature_grouped_settings' );
delete_option( '_wcpay__unrelated_option' );

parent::tear_down();
}

/**
* @dataProvider versions_not_applying_migration_provider
*/
public function test_it_does_nothing_if_migration_was_already_applied( string $stored_wcpay_version ) {
$this->setup_environment( $stored_wcpay_version );

$this->migration->maybe_migrate();

// all options remains untouched.
$this->assertEquals( '1', get_option( '_wcpay_feature_grouped_settings' ) );
$this->assertEquals( 'fake-value', get_option( '_wcpay__unrelated_option' ) );
}

public function test_it_migrates_if_stored_woopayments_version_is_too_old() {
$this->setup_environment( '8.0.0' );

$this->migration->maybe_migrate();

// this option has been deleted.
$this->assertEquals( 'default-value', get_option( '_wcpay_feature_grouped_settings', 'default-value' ) );
// this option remains untouched.
$this->assertEquals( 'fake-value', get_option( '_wcpay__unrelated_option' ) );
}

private function setup_environment( $stored_wcpay_version ) {
update_option( 'woocommerce_woocommerce_payments_version', $stored_wcpay_version );
}

public function versions_not_applying_migration_provider() {
return [
'newer major version' => [ '8.2.0' ],
'newer minor version' => [ '8.1.1' ],
'same version' => [ '8.1.0' ],
];
}
}
11 changes: 0 additions & 11 deletions tests/unit/test-class-wc-payments-order-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ public function set_up() {

$this->order_service = new WC_Payments_Order_Service( $this->createMock( WC_Payments_API_Client::class ) );
$this->order = WC_Helper_Order::create_order();

// Turn on fraud settings.
update_option( 'wcpay_fraud_protection_settings_active', '1' );
}

public function tear_down() {
// Disable fraud settings.
update_option( 'wcpay_fraud_protection_settings_active', 0 );

parent::tear_down();
}

/**
Expand Down Expand Up @@ -525,7 +515,6 @@ public function test_mark_payment_started_exits_on_existing_order_status_not_pen
public function test_mark_payment_started_does_not_add_fraud_meta_box_type_if_fraud_settings_disabled() {
// Arrange: Create intention with provided args, turn off fraud settings.
$intent = WC_Helper_Intention::create_intention( [ 'status' => Intent_Status::REQUIRES_ACTION ] );
update_option( 'wcpay_fraud_protection_settings_active', 0 );

// Act: Attempt to mark the payment started.
$this->order_service->update_order_status_from_intent( $this->order, $intent );
Expand Down
2 changes: 0 additions & 2 deletions tests/unit/test-class-wc-payments-token-service.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ public function test_add_token_to_user_for_sepa() {
* Test add SEPA token to user with deferred intent creation UPE.
*/
public function test_add_token_to_user_for_sepa_deferred_intent_creation_upe() {
$this->mock_cache->method( 'get' )->willReturn( [ 'is_deferred_intent_creation_upe_enabled' => true ] );
$mock_payment_method = [
'id' => 'pm_mock',
'sepa_debit' => [
Expand All @@ -197,7 +196,6 @@ public function test_add_token_to_user_for_sepa_deferred_intent_creation_upe() {
* Test add SEPA token to user with deferred intent UPE.
*/
public function test_add_token_to_user_for_sepa_deferred_upe() {
$this->mock_cache->method( 'get' )->willReturn( [ 'is_deferred_intent_creation_upe_enabled' => true ] );
$mock_payment_method = [
'id' => 'pm_mock',
'sepa_debit' => [
Expand Down

0 comments on commit 3a443f5

Please sign in to comment.