Skip to content

Commit 37917fc

Browse files
wjrosaCopilotdaledupreez
authored
Making OC available by default (#4514)
* Making OC available by default * Changelog and readme entries * Fix tests * Fix tests * Update includes/class-wc-stripe-feature-flags.php Co-authored-by: Copilot <[email protected]> * Deprecating the feature flag constant * Bailing out when PMC is disabled * Update includes/class-wc-stripe-feature-flags.php Co-authored-by: daledupreez <[email protected]> --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: daledupreez <[email protected]>
1 parent a81fd09 commit 37917fc

File tree

4 files changed

+57
-16
lines changed

4 files changed

+57
-16
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*** Changelog ***
22

33
= 9.8.0 - xxxx-xx-xx =
4+
* Add - Makes the Optimized Checkout feature available for all merchants by default
45
* Add - Adds a new bulk action option to the subscriptions listing screen to check for detached payment methods
56
* Dev - Use product type constants that were added in WooCommerce 9.7
67
* Dev - Removes the inclusion of the deprecated WC_Stripe_Order class

includes/class-wc-stripe-feature-flags.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,21 @@ class WC_Stripe_Feature_Flags {
77
const UPE_CHECKOUT_FEATURE_ATTRIBUTE_NAME = 'upe_checkout_experience_enabled';
88
const ECE_FEATURE_FLAG_NAME = '_wcstripe_feature_ece';
99
const AMAZON_PAY_FEATURE_FLAG_NAME = '_wcstripe_feature_amazon_pay';
10-
const OC_FEATURE_FLAG_NAME = '_wcstripe_feature_oc';
1110
const LPM_ACH_FEATURE_FLAG_NAME = '_wcstripe_feature_lpm_ach';
1211
const LPM_ACSS_FEATURE_FLAG_NAME = '_wcstripe_feature_lpm_acss';
1312
const LPM_BACS_FEATURE_FLAG_NAME = '_wcstripe_feature_lpm_bacs';
1413
const LPM_BLIK_FEATURE_FLAG_NAME = '_wcstripe_feature_lpm_blik';
1514
const LPM_BECS_DEBIT_FEATURE_FLAG_NAME = '_wcstripe_feature_lpm_becs_debit';
1615

16+
/**
17+
* Feature flag for Optimized Checkout (OC).
18+
*
19+
* @var string
20+
*
21+
* @deprecated This feature flag will be removed in version 9.9.0.
22+
*/
23+
const OC_FEATURE_FLAG_NAME = '_wcstripe_feature_oc';
24+
1725
/**
1826
* Map of feature flag option names => their default "yes"/"no" value.
1927
* This single source of truth makes it easier to maintain our dev tools.
@@ -174,13 +182,24 @@ public static function are_apms_deprecated() {
174182
* @return bool
175183
*/
176184
public static function is_oc_available() {
177-
$default_value = self::get_option_with_default( self::OC_FEATURE_FLAG_NAME );
178185
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
179186
$pmc_enabled = $stripe_settings['pmc_enabled'] ?? 'no';
187+
if ( 'yes' !== $pmc_enabled ) {
188+
return false;
189+
}
190+
191+
/**
192+
* Filter to control the availability of the Optimized Checkout feature.
193+
*
194+
* @since 9.6.0
195+
* @deprecated This filter will be removed in version 9.9.0. No replacement will be provided as the Optimized Checkout feature will be permanently enabled.
196+
* @param string $default_value The default value for the feature flag.
197+
* @param string $pmc_enabled The value of the 'pmc_enabled' setting.
198+
*/
180199
return apply_filters(
181200
'wc_stripe_is_optimized_checkout_available',
182-
'yes' === $default_value && 'yes' === $pmc_enabled,
183-
$default_value,
201+
true,
202+
'yes',
184203
$pmc_enabled
185204
);
186205
}

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
111111
== Changelog ==
112112

113113
= 9.8.0 - xxxx-xx-xx =
114+
* Add - Makes the Optimized Checkout feature available for all merchants by default
114115
* Add - Adds a new bulk action option to the subscriptions listing screen to check for detached payment methods
115116
* Dev - Use product type constants that were added in WooCommerce 9.7
116117
* Dev - Removes the inclusion of the deprecated WC_Stripe_Order class

tests/phpunit/WC_Stripe_Feature_Flags_Test.php

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace WooCommerce\Stripe\Tests;
44

55
use WC_Stripe_Feature_Flags;
6+
use WooCommerce\Stripe\Tests\Helpers\PMC_Test_Helper;
67
use WP_UnitTestCase;
78

89
/**
@@ -16,19 +17,33 @@ class WC_Stripe_Feature_Flags_Test extends WP_UnitTestCase {
1617
/**
1718
* Test for `is_oc_available`.
1819
*
19-
* @param string $option_value The value of the feature flag option.
20+
* @param bool $pmc_enabled Whether the Payment Method Configuration API is enabled.
2021
* @param string $filter_function The filter function to apply.
2122
* @param bool $expected The expected result.
2223
* @return void
2324
* @dataProvider provide_test_is_oc_available
2425
*/
25-
public function test_is_oc_available( $option_value, $filter_function, $expected ) {
26+
public function test_is_oc_available( $pmc_enabled, $filter_function, $expected ) {
27+
// Mock the payment method configuration for the test, to avoid it being disabled by default.
28+
PMC_Test_Helper::cache_mocked_configuration();
29+
30+
if ( $pmc_enabled ) {
31+
PMC_Test_Helper::enable_pmc();
32+
} else {
33+
PMC_Test_Helper::disable_pmc();
34+
}
35+
2636
if ( ! empty( $filter_function ) ) {
2737
add_filter( 'wc_stripe_is_optimized_checkout_available', $filter_function );
2838
}
2939

30-
update_option( WC_Stripe_Feature_Flags::OC_FEATURE_FLAG_NAME, $option_value );
31-
$this->assertSame( $expected, WC_Stripe_Feature_Flags::is_oc_available() );
40+
$actual = WC_Stripe_Feature_Flags::is_oc_available();
41+
42+
// Clean up
43+
PMC_Test_Helper::disable_pmc();
44+
PMC_Test_Helper::delete_cached_configuration();
45+
46+
$this->assertSame( $expected, $actual );
3247

3348
if ( ! empty( $filter_function ) ) {
3449
remove_filter( 'wc_stripe_is_optimized_checkout_available', $filter_function );
@@ -42,23 +57,28 @@ public function test_is_oc_available( $option_value, $filter_function, $expected
4257
*/
4358
public function provide_test_is_oc_available() {
4459
return [
45-
'available' => [
46-
'option value' => 'yes',
60+
'PMC enabled' => [
61+
'PMC enabled' => true,
4762
'filter function' => '',
4863
'expected' => true,
4964
],
50-
'not available' => [
51-
'option value' => 'no',
65+
'PMC disabled' => [
66+
'PMC enabled' => false,
5267
'filter function' => '',
5368
'expected' => false,
5469
],
55-
'filter set to true' => [
56-
'option value' => 'no',
70+
'PMC disabled, filter set to true (ignored)' => [
71+
'PMC enabled' => false,
72+
'filter function' => '__return_true',
73+
'expected' => false,
74+
],
75+
'filter set to true' => [
76+
'PMC enabled' => true,
5777
'filter function' => '__return_true',
5878
'expected' => true,
5979
],
60-
'filter set to false' => [
61-
'option value' => 'yes',
80+
'filter set to false' => [
81+
'PMC enabled' => true,
6282
'filter function' => '__return_false',
6383
'expected' => false,
6484
],

0 commit comments

Comments
 (0)