Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Changelog ***

= 10.2.0 - xxxx-xx-xx =
* Update - Makes the Optimized Checkout Suite feature enabled by default for all new installations
* Dev - Remove all references to the UPE-enabled feature flag
* Dev - Removing all usages of the `is_stripe_ece_enabled` feature flag method
* Dev - Expands the Stripe Order Helper class to handle mandate ID, Multibanco data, refund status, card brand, charge captured flag, status final flag, and the refund failure reason
Expand Down
21 changes: 15 additions & 6 deletions includes/class-wc-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,22 @@ public function install() {
// Try to schedule the daily async cleanup of the Stripe database cache.
WC_Stripe_Database_Cache::maybe_schedule_daily_async_cleanup();

// If we have previously disabled settings synchronization, remove the flag after the upgrade,
// just to make sure we are still ineligible for settings synchronization.
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
if ( isset( $stripe_settings['pmc_enabled'] ) && 'no' === $stripe_settings['pmc_enabled'] ) {
unset( $stripe_settings['pmc_enabled'] );
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
WC_Stripe_Logger::warning( 'Settings synchronization eligibility will be re-checked after upgrade' );
if ( isset( $stripe_settings['pmc_enabled'] ) ) {
// If we have previously disabled settings synchronization, remove the flag after the upgrade,
// just to make sure we are still ineligible for settings synchronization.
if ( 'no' === $stripe_settings['pmc_enabled'] ) {
unset( $stripe_settings['pmc_enabled'] );
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
WC_Stripe_Logger::warning( 'Settings synchronization eligibility will be re-checked after upgrade' );
} else if ( 'yes' === $stripe_settings['pmc_enabled'] ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this approach also has issues. If we have a merchant who has settings sync enabled but hasn't had the optimized_checkout_element sub-option set, upgrading will now result in Optimized Checkout being enabled. AFAICT, we don't have any logic that's only going to run for a new/fresh install.

I had a fairly different thought about how to approach this much earlier in install():

  • Get current value of wc_stripe_version (which we're already doing for the comparison against WC_STRIPE_VERSION)
  • If the value is empty, we have a new install, so set a new option (or maybe sub-option) like wc_stripe_optimized_checkout_default_on to yes
  • Leave all other logic in this code as-is -- we only want to take action when we (re)enable settings sync
  • Then in WC_Stripe_Payment_Method_Configurations::maybe_migrate_payment_methods_from_db_to_pmc(), if we execute the code path where we set pmc_enabled to yes, also set optimized_checkout_element to yes if it wasn't previously set.

I am planning to do something very similar for enabling Amazon Pay on fresh installs as well. Let me know if it would help for me to put together an initial PR. I am now thinking that it could be worth creating a helper method like init_on_new_install() that handles initialising some options for managing default behaviours like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'd appreciate it if you could open another PR then. We can move forward from there 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem here is that if we run the code in install just for new installations (wc_stripe_version is false), pmc_enabled will be undefined, and we will never set wc_stripe_optimized_checkout_default_on there

Copy link
Contributor Author

@wjrosa wjrosa Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What we can do is set a flag/constant when we identify a fresh install, and proceed with the settings update in maybe_migrate_payment_methods_from_db_to_pmc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That wouldn't work either, because the install and the connection method are called different in different flows 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a refactor using a new flag in options to identify new installs. See 7f2b87d. Let me know what you think. It worked for me

// Enable the Optimized Checkout feature by default if not set.
// It requires PMC to be enabled.
if ( ! isset( $stripe_settings['optimized_checkout_element'] ) ) {
$stripe_settings['optimized_checkout_element'] = 'yes';
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o
== Changelog ==

= 10.2.0 - xxxx-xx-xx =
* Update - Makes the Optimized Checkout Suite feature enabled by default for all new installations
* Dev - Remove all references to the UPE-enabled feature flag
* Dev - Removing all usages of the `is_stripe_ece_enabled` feature flag method
* Dev - Expands the Stripe Order Helper class to handle mandate ID, Multibanco data, refund status, card brand, charge captured flag, status final flag, and the refund failure reason
Expand Down
78 changes: 78 additions & 0 deletions tests/phpunit/WC_Stripe_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,82 @@ public function provide_test_maybe_toggle_payment_methods() {
],
];
}

/**
* Tests for the 'install' method when it updates the main Stripe settings.
*
* @param array $stripe_settings The initial Stripe settings.
* @param array $expected_settings The expected Stripe settings after installation.
* @return void
*
* @dataProvider provide_test_install_settings
*/
public function test_install_settings_update( array $stripe_settings = [], array $expected_settings = [] ): void {
// Activate the Stripe plugin.
update_option( 'active_plugins', [ plugin_basename( WC_STRIPE_MAIN_FILE ) ] );

// Set initial settings.
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );

$wc_stripe = $this->getMockBuilder( WC_Stripe::class )
->disableOriginalConstructor()
->onlyMethods(
[
'update_plugin_version',
'update_prb_location_settings',
'migrate_to_new_checkout_experience',
]
)
->getMock();

$wc_stripe->install();

$actual_settings = WC_Stripe_Helper::get_stripe_settings();
foreach ( $expected_settings as $key => $value ) {
if ( null == $value ) {
$this->assertArrayNotHasKey( $key, $actual_settings );
} else {
$this->assertArrayHasKey( $key, $actual_settings );
$this->assertSame( $value, $actual_settings[ $key ] );
}
}
}

/**
* Data provider for `test_install_settings`.
*
* @return array
*/
public function provide_test_install_settings(): array {
return [
'will not enable OCS by default due to PMC being disabled' => [
'stripe settings' => [
'pmc_enabled' => 'no',
],
'expected settings' => [
'pmc_enabled' => null,
'optimized_checkout_element' => null,
],
],
'will not enable OCS by default due to OCS being set' => [
'stripe settings' => [
'pmc_enabled' => 'yes',
'optimized_checkout_element' => 'no',
],
'expected settings' => [
'pmc_enabled' => 'yes',
'optimized_checkout_element' => 'no',
],
],
'will enable OCS by default' => [
'stripe settings' => [
'pmc_enabled' => 'yes',
],
'expected settings' => [
'pmc_enabled' => 'yes',
'optimized_checkout_element' => 'yes',
],
],
];
}
}
Loading