Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 - Enable the Optimized Checkout Suite feature for all new installations
* Dev - Deprecates all the legacy checkout payment method classes
* Dev - Deprecates all the LPM class constants
* Dev - Remove all references to the UPE-enabled feature flag
Expand Down
5 changes: 5 additions & 0 deletions includes/class-wc-stripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,11 @@ public function install() {
define( 'WC_STRIPE_INSTALLING', true );
}

// Mark optimized checkout as default on for new installs.
if ( false === get_option( 'wc_stripe_version' ) && false === get_option( 'wc_stripe_optimized_checkout_default_on' ) ) {
update_option( 'wc_stripe_optimized_checkout_default_on', true );
}

add_woocommerce_inbox_variant();
$this->update_plugin_version();

Expand Down
6 changes: 6 additions & 0 deletions includes/connect/class-wc-stripe-connect.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,12 @@ private function save_stripe_keys( $result, $type = 'connect', $mode = 'live' )
$options[ $prefix . 'secret_key' ] = $secret_key;
$options[ $prefix . 'connection_type' ] = $type;
$options['pmc_enabled'] = 'connect' === $type ? 'yes' : 'no'; // When not connected via Connect OAuth, the PMC is disabled.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thought for a follow-up/separate PR: maybe we should default to '' or not even set pmc_enabled when we don't have connect type.

Suggested change
$options['pmc_enabled'] = 'connect' === $type ? 'yes' : 'no'; // When not connected via Connect OAuth, the PMC is disabled.
$options['pmc_enabled'] = 'connect' === $type ? 'yes' : ''; // When not connected via Connect OAuth, defer the decision until we try to get a valid PMC.

$should_default_optimized_checkout_on = get_option( 'wc_stripe_optimized_checkout_default_on' );
// Clean up the option.
delete_option( 'wc_stripe_optimized_checkout_default_on' );
if ( 'connect' === $type && $should_default_optimized_checkout_on ) {
$options['optimized_checkout_element'] = 'yes';
}
if ( 'app' === $type ) {
$options[ $prefix . 'refresh_token' ] = $result->refreshToken; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
}
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 - Enable the Optimized Checkout Suite feature for all new installations
* Dev - Deprecates all the legacy checkout payment method classes
* Dev - Deprecates all the LPM class constants
* Dev - Remove all references to the UPE-enabled feature flag
Expand Down
96 changes: 96 additions & 0 deletions tests/phpunit/WC_Stripe_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,100 @@ 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',
],
],
];
}

/**
* Tests that the 'install' method sets the fresh install flag.
*
* @return void
*/
public function test_install_sets_fresh_install_flag(): void {
update_option( 'active_plugins', [ plugin_basename( WC_STRIPE_MAIN_FILE ) ] );

// Ensure the flag is not set.
delete_option( 'wc_stripe_optimized_checkout_default_on' );

$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();

$this->assertEquals( 'yes', get_option( 'wc_stripe_optimized_checkout_default_on' ) );
}
}
Loading