diff --git a/changelog.txt b/changelog.txt index b600c762f..cf49c8940 100644 --- a/changelog.txt +++ b/changelog.txt @@ -32,6 +32,7 @@ * Dev - Add a GitHub Action workflow to run QIT E2E Integrations tests. * Fix - Check billing interval and period to set in mandate options. * Fix - Check order currency on pay for order page to display supported payment methods. +* Update - Migrate payment request settings data to express checkout settings data. * Update - Make the new Stripe Express Checkout Element enabled by default in all accounts. = 9.0.0 - 2024-12-12 = diff --git a/includes/migrations/class-migrate-payment-request-data-to-express-checkout-data.php b/includes/migrations/class-migrate-payment-request-data-to-express-checkout-data.php new file mode 100644 index 000000000..9592f69ae --- /dev/null +++ b/includes/migrations/class-migrate-payment-request-data-to-express-checkout-data.php @@ -0,0 +1,63 @@ +get_gateway(); + + $express_checkout_enabled = $stripe_gateway->get_option( 'express_checkout' ); + + if ( empty( $express_checkout_enabled ) ) { + $this->migrate(); + } + } + + /** + * Copies over Payment Request settings data to Express Checkout settings data. + */ + private function migrate() { + $stripe_gateway = $this->get_gateway(); + + $payment_request_enabled = $stripe_gateway->get_option( 'payment_request', 'no' ); + $payment_request_button_type = $stripe_gateway->get_option( 'payment_request_button_type', 'default' ); + $payment_request_button_theme = $stripe_gateway->get_option( 'payment_request_button_theme', 'dark' ); + $payment_request_button_size = $stripe_gateway->get_option( 'payment_request_button_size', 'default' ); + $payment_request_button_locations = $stripe_gateway->get_option( 'payment_request_button_locations', [ 'checkout' ] ); + + $stripe_gateway->update_option( 'express_checkout', $payment_request_enabled ); + $stripe_gateway->update_option( 'express_checkout_button_type', $payment_request_button_type ); + $stripe_gateway->update_option( 'express_checkout_button_theme', $payment_request_button_theme ); + $stripe_gateway->update_option( 'express_checkout_button_size', $payment_request_button_size ); + $stripe_gateway->update_option( 'express_checkout_button_locations', $payment_request_button_locations ); + } + + /** + * Returns the main Stripe payment gateways. + * + * @return WC_Stripe_Payment_Gateway + */ + public function get_gateway() { + return woocommerce_gateway_stripe()->get_main_stripe_gateway(); + } +} diff --git a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php index fe8aa1272..ac5705e50 100644 --- a/includes/payment-methods/class-wc-stripe-express-checkout-helper.php +++ b/includes/payment-methods/class-wc-stripe-express-checkout-helper.php @@ -85,7 +85,7 @@ public function is_account_creation_possible() { * @return string */ public function get_button_type() { - return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default'; + return isset( $this->stripe_settings['express_checkout_button_type'] ) ? $this->stripe_settings['express_checkout_button_type'] : 'default'; } /** @@ -94,7 +94,7 @@ public function get_button_type() { * @return string */ public function get_button_theme() { - return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark'; + return isset( $this->stripe_settings['express_checkout_button_theme'] ) ? $this->stripe_settings['express_checkout_button_theme'] : 'dark'; } /** @@ -103,7 +103,7 @@ public function get_button_theme() { * @return string */ public function get_button_height() { - $height = isset( $this->stripe_settings['payment_request_button_size'] ) ? $this->stripe_settings['payment_request_button_size'] : 'default'; + $height = isset( $this->stripe_settings['express_checkout_button_size'] ) ? $this->stripe_settings['express_checkout_button_size'] : 'default'; if ( 'small' === $height ) { return '40'; } @@ -121,7 +121,7 @@ public function get_button_height() { * @return string */ public function get_button_radius() { - $height = isset( $this->stripe_settings['payment_request_button_size'] ) ? $this->stripe_settings['payment_request_button_size'] : 'default'; + $height = isset( $this->stripe_settings['express_checkout_button_size'] ) ? $this->stripe_settings['express_checkout_button_size'] : 'default'; if ( 'small' === $height ) { return '2'; } @@ -1329,18 +1329,18 @@ public function get_login_confirmation_settings() { */ public function get_button_locations() { // If the locations have not been set return the default setting. - if ( ! isset( $this->stripe_settings['payment_request_button_locations'] ) ) { + if ( ! isset( $this->stripe_settings['express_checkout_button_locations'] ) ) { return [ 'product', 'cart' ]; } // If all locations are removed through the settings UI the location config will be set to // an empty string "". If that's the case (and if the settings are not an array for any // other reason) we should return an empty array. - if ( ! is_array( $this->stripe_settings['payment_request_button_locations'] ) ) { + if ( ! is_array( $this->stripe_settings['express_checkout_button_locations'] ) ) { return []; } - return $this->stripe_settings['payment_request_button_locations']; + return $this->stripe_settings['express_checkout_button_locations']; } /** @@ -1351,7 +1351,7 @@ public function get_button_locations() { * @return boolean */ public function is_express_checkout_enabled() { - return isset( $this->stripe_settings['payment_request'] ) && 'yes' === $this->stripe_settings['payment_request']; + return isset( $this->stripe_settings['express_checkout'] ) && 'yes' === $this->stripe_settings['express_checkout']; } /** diff --git a/readme.txt b/readme.txt index 07a6499d2..f7a2330b0 100644 --- a/readme.txt +++ b/readme.txt @@ -142,6 +142,7 @@ If you get stuck, you can ask for help in the [Plugin Forum](https://wordpress.o * Dev - Add a GitHub Action workflow to run QIT E2E Integrations tests. * Fix - Check billing interval and period to set in mandate options. * Fix - Check order currency on pay for order page to display supported payment methods. +* Update - Migrate payment request settings data to express checkout settings data. * Update - Make the new Stripe Express Checkout Element enabled by default in all accounts. [See changelog for all versions](https://raw.githubusercontent.com/woocommerce/woocommerce-gateway-stripe/trunk/changelog.txt). diff --git a/tests/phpunit/admin/migrations/test-class-migrate-payment-request-data-to-express-checkout-data.php b/tests/phpunit/admin/migrations/test-class-migrate-payment-request-data-to-express-checkout-data.php new file mode 100644 index 000000000..13e1c832b --- /dev/null +++ b/tests/phpunit/admin/migrations/test-class-migrate-payment-request-data-to-express-checkout-data.php @@ -0,0 +1,64 @@ +gateway_mock = $this->getMockBuilder( WC_Gateway_Stripe::class ) + ->disableOriginalConstructor() + ->getMock(); + $this->migration = $this->getMockBuilder( Migrate_Payment_Request_Data_To_Express_Checkout_Data::class ) + ->disableOriginalConstructor() + ->setMethods( [ 'get_gateway' ] ) + ->getMock(); + } + + public function test_migration_not_executed_when_data_already_migrated() { + $this->setup_environment( [ 'express_checkout' => 'yes' ] ); + + $this->gateway_mock->expects( $this->never() ) + ->method( 'update_option' ); + + $this->migration->maybe_migrate(); + } + + public function test_prb_settings_data_migration_to_ece_settings_data() { + $this->setup_environment( [] ); + + $this->gateway_mock->expects( $this->exactly( 5 ) ) + ->method( 'update_option' ); + + $this->migration->maybe_migrate(); + } + + private function setup_environment( $settings ) { + $this->gateway_mock->method( 'get_option' ) + ->willReturnCallback( + function ( $key ) use ( $settings ) { + return isset( $settings[ $key ] ) ? $settings[ $key ] : ''; + } + ); + $this->migration->method( 'get_gateway' )->willReturn( $this->gateway_mock ); + } +} diff --git a/woocommerce-gateway-stripe.php b/woocommerce-gateway-stripe.php index 786af27cd..1fd543e2d 100644 --- a/woocommerce-gateway-stripe.php +++ b/woocommerce-gateway-stripe.php @@ -264,8 +264,10 @@ public function init() { require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-inbox-notes.php'; require_once dirname( __FILE__ ) . '/includes/admin/class-wc-stripe-upe-compatibility-controller.php'; require_once dirname( __FILE__ ) . '/includes/migrations/class-allowed-payment-request-button-types-update.php'; + require_once dirname( __FILE__ ) . '/includes/migrations/class-migrate-payment-request-data-to-express-checkout-data.php'; require_once dirname( __FILE__ ) . '/includes/class-wc-stripe-account.php'; new Allowed_Payment_Request_Button_Types_Update(); + new Migrate_Payment_Request_Data_To_Express_Checkout_Data(); $this->api = new WC_Stripe_Connect_API(); $this->connect = new WC_Stripe_Connect( $this->api );