Skip to content

Commit 8db98b6

Browse files
authored
Re-enabling migration of PRBs settings to ECE (#4689)
* Removing PRBs frontend code * Re-enabling the migration of PRBs settings to ECE * Updating all keys to the new ones * Replacing keys in tests * Fix tests * Readme and changelog entries * Fix tests * Revert unnecessary changes * Fix tests * Renaming private method
1 parent 7d055cd commit 8db98b6

14 files changed

+69
-142
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
= 10.1.0 - xxxx-xx-xx =
4+
* Update - Renames and migrates all Payment Request Buttons settings to Express Checkout
45
* Dev - Upgrades `@automattic/interpolate-components` to 1.2.1 to remove the `node-fetch` dependency
56
* Add - Includes a notice to inform merchants about methods that are automatically enabled upon account connection
67
* Dev - Upgrades the `nock` NPM package to version `^13.5.6` to remove the lodash.set dependency

includes/admin/class-wc-rest-stripe-settings-controller.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,28 +109,28 @@ public function register_routes() {
109109
'payment_request_button_type' => [
110110
'description' => __( 'Express checkout button types.', 'woocommerce-gateway-stripe' ),
111111
'type' => 'string',
112-
'enum' => array_keys( $form_fields['payment_request_button_type']['options'] ),
112+
'enum' => array_keys( $form_fields['express_checkout_button_type']['options'] ),
113113
'validate_callback' => 'rest_validate_request_arg',
114114
],
115115
'payment_request_button_theme' => [
116116
'description' => __( 'Express checkout button themes.', 'woocommerce-gateway-stripe' ),
117117
'type' => 'string',
118-
'enum' => array_keys( $form_fields['payment_request_button_theme']['options'] ),
118+
'enum' => array_keys( $form_fields['express_checkout_button_theme']['options'] ),
119119
'validate_callback' => 'rest_validate_request_arg',
120120
],
121121
'payment_request_button_size' => [
122122
'description' => __( 'Express checkout button sizes.', 'woocommerce-gateway-stripe' ),
123123
'type' => 'string',
124-
// it can happen that `$form_fields['payment_request_button_size']` is empty (in tests) - fixing temporarily.
125-
'enum' => array_keys( isset( $form_fields['payment_request_button_size']['options'] ) ? $form_fields['payment_request_button_size']['options'] : [] ),
124+
// it can happen that `$form_fields['express_checkout_button_size']` is empty (in tests) - fixing temporarily.
125+
'enum' => array_keys( isset( $form_fields['express_checkout_button_size']['options'] ) ? $form_fields['express_checkout_button_size']['options'] : [] ),
126126
'validate_callback' => 'rest_validate_request_arg',
127127
],
128128
'payment_request_button_locations' => [
129129
'description' => __( 'Express checkout locations that should be enabled.', 'woocommerce-gateway-stripe' ),
130130
'type' => 'array',
131131
'items' => [
132132
'type' => 'string',
133-
'enum' => array_keys( $form_fields['payment_request_button_locations']['options'] ),
133+
'enum' => array_keys( $form_fields['express_checkout_button_locations']['options'] ),
134134
],
135135
'validate_callback' => 'rest_validate_request_arg',
136136
],
@@ -237,10 +237,10 @@ public function get_settings() {
237237
'amazon_pay_button_size' => $this->gateway->get_validated_option( 'amazon_pay_button_size' ),
238238
'amazon_pay_button_locations' => $this->gateway->get_validated_option( 'amazon_pay_button_locations' ),
239239
'is_payment_request_enabled' => $this->gateway->is_payment_request_enabled(),
240-
'payment_request_button_type' => $this->gateway->get_validated_option( 'payment_request_button_type' ),
241-
'payment_request_button_theme' => $this->gateway->get_validated_option( 'payment_request_button_theme' ),
242-
'payment_request_button_size' => $this->gateway->get_validated_option( 'payment_request_button_size' ),
243-
'payment_request_button_locations' => $this->gateway->get_validated_option( 'payment_request_button_locations' ),
240+
'payment_request_button_type' => $this->gateway->get_validated_option( 'express_checkout_button_type' ),
241+
'payment_request_button_theme' => $this->gateway->get_validated_option( 'express_checkout_button_theme' ),
242+
'payment_request_button_size' => $this->gateway->get_validated_option( 'express_checkout_button_size' ),
243+
'payment_request_button_locations' => $this->gateway->get_validated_option( 'express_checkout_button_locations' ),
244244

245245
/* Settings > Payments & transactions */
246246
'is_manual_capture_enabled' => ! $this->gateway->is_automatic_capture_enabled(),
@@ -540,10 +540,10 @@ private function update_amazon_pay_settings( WP_REST_Request $request ) {
540540
*/
541541
private function update_payment_request_settings( WP_REST_Request $request ) {
542542
$attributes = [
543-
'payment_request_button_type' => 'payment_request_button_type',
544-
'payment_request_button_size' => 'payment_request_button_size',
545-
'payment_request_button_theme' => 'payment_request_button_theme',
546-
'payment_request_button_locations' => 'payment_request_button_locations',
543+
'payment_request_button_type' => 'express_checkout_button_type',
544+
'payment_request_button_size' => 'express_checkout_button_size',
545+
'payment_request_button_theme' => 'express_checkout_button_theme',
546+
'payment_request_button_locations' => 'express_checkout_button_locations',
547547
];
548548

549549
foreach ( $attributes as $request_key => $attribute ) {

includes/admin/class-wc-stripe-inbox-notes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public static function should_show_marketing_note() {
124124
// Make sure Apple Pay is enabled and setup is successful.
125125
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
126126
$stripe_enabled = isset( $stripe_settings['enabled'] ) && 'yes' === $stripe_settings['enabled'];
127-
$button_enabled = isset( $stripe_settings['payment_request'] ) && 'yes' === $stripe_settings['payment_request'];
127+
$button_enabled = isset( $stripe_settings['express_checkout'] ) && 'yes' === $stripe_settings['express_checkout'];
128128
$registration_complete = isset( $stripe_settings['apple_pay_domain_set'] ) && 'yes' === $stripe_settings['apple_pay_domain_set'];
129129
if ( ! $stripe_enabled || ! $button_enabled || ! $registration_complete ) {
130130
return false;

includes/admin/class-wc-stripe-payment-gateways-controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public function __construct() {
1919
// If UPE is enabled and there are enabled payment methods, we need to load the disable Stripe confirmation modal.
2020
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
2121
$enabled_upe_payment_methods = WC_Stripe_Payment_Method_Configurations::get_upe_enabled_payment_method_ids();
22-
$upe_payment_requests_enabled = 'yes' === ( $stripe_settings['payment_request'] ?? 'no' );
22+
$upe_payment_requests_enabled = 'yes' === ( $stripe_settings['express_checkout'] ?? 'no' );
2323

2424
if ( ( is_array( $enabled_upe_payment_methods ) && count( $enabled_upe_payment_methods ) > 0 ) || $upe_payment_requests_enabled ) {
2525
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_payments_scripts' ] );

includes/admin/stripe-settings.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
'default' => 'yes',
118118
'desc_tip' => true,
119119
],
120-
'payment_request' => [
120+
'express_checkout' => [
121121
'title' => __( 'Payment Request Buttons', 'woocommerce-gateway-stripe' ),
122122
'label' => sprintf(
123123
/* translators: 1) br tag 2) Stripe anchor tag 3) Apple anchor tag 4) Stripe dashboard opening anchor tag 5) Stripe dashboard closing anchor tag */
@@ -133,7 +133,7 @@
133133
'default' => 'yes',
134134
'desc_tip' => true,
135135
],
136-
'payment_request_button_type' => [
136+
'express_checkout_button_type' => [
137137
'title' => __( 'Payment Request Button Type', 'woocommerce-gateway-stripe' ),
138138
'label' => __( 'Button Type', 'woocommerce-gateway-stripe' ),
139139
'type' => 'select',
@@ -148,7 +148,7 @@
148148
'custom' => __( 'Custom', 'woocommerce-gateway-stripe' ),
149149
],
150150
],
151-
'payment_request_button_theme' => [
151+
'express_checkout_button_theme' => [
152152
'title' => __( 'Payment Request Button Theme', 'woocommerce-gateway-stripe' ),
153153
'label' => __( 'Button Theme', 'woocommerce-gateway-stripe' ),
154154
'type' => 'select',
@@ -189,7 +189,7 @@
189189
'long' => __( 'Text and logo', 'woocommerce-gateway-stripe' ),
190190
],
191191
],
192-
'payment_request_button_locations' => [
192+
'express_checkout_button_locations' => [
193193
'title' => __( 'Payment Request Button Locations', 'woocommerce-gateway-stripe' ),
194194
'type' => 'multiselect',
195195
'description' => __( 'Select where you would like Payment Request Buttons to be displayed', 'woocommerce-gateway-stripe' ),
@@ -205,7 +205,7 @@
205205
'data-placeholder' => __( 'Select pages', 'woocommerce-gateway-stripe' ),
206206
],
207207
],
208-
'payment_request_button_size' => [
208+
'express_checkout_button_size' => [
209209
'title' => __( 'Payment Request Button Size', 'woocommerce-gateway-stripe' ),
210210
'type' => 'select',
211211
'description' => __( 'Select the size of the button.', 'woocommerce-gateway-stripe' ),
@@ -293,20 +293,20 @@
293293

294294
if ( WC_Stripe_Feature_Flags::is_upe_preview_enabled() ) {
295295
// in the new settings, "checkout" is going to be enabled by default (if it is a new WCStripe installation).
296-
$stripe_settings['payment_request_button_locations']['default'][] = 'checkout';
296+
$stripe_settings['express_checkout_button_locations']['default'][] = 'checkout';
297297

298298
// no longer needed in the new settings.
299-
unset( $stripe_settings['payment_request_button_branded_type'] );
300-
unset( $stripe_settings['payment_request_button_height'] );
301-
unset( $stripe_settings['payment_request_button_label'] );
299+
unset( $stripe_settings['express_checkout_button_branded_type'] );
300+
unset( $stripe_settings['express_checkout_button_height'] );
301+
unset( $stripe_settings['express_checkout_button_label'] );
302302
// injecting some of the new options.
303-
$stripe_settings['payment_request_button_type']['options']['default'] = __( 'Only icon', 'woocommerce-gateway-stripe' );
304-
$stripe_settings['payment_request_button_type']['options']['book'] = __( 'Book', 'woocommerce-gateway-stripe' );
303+
$stripe_settings['express_checkout_button_type']['options']['default'] = __( 'Only icon', 'woocommerce-gateway-stripe' );
304+
$stripe_settings['express_checkout_button_type']['options']['book'] = __( 'Book', 'woocommerce-gateway-stripe' );
305305
// no longer valid options.
306-
unset( $stripe_settings['payment_request_button_type']['options']['branded'] );
307-
unset( $stripe_settings['payment_request_button_type']['options']['custom'] );
306+
unset( $stripe_settings['express_checkout_button_type']['options']['branded'] );
307+
unset( $stripe_settings['express_checkout_button_type']['options']['custom'] );
308308
} else {
309-
unset( $stripe_settings['payment_request_button_size'] );
309+
unset( $stripe_settings['express_checkout_button_size'] );
310310
}
311311

312312
if ( WC_Stripe_Feature_Flags::is_upe_preview_enabled() ) {

includes/class-wc-gateway-stripe.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function __construct() {
116116
$this->saved_cards = 'yes' === $this->get_option( 'saved_cards' );
117117
$this->secret_key = $this->testmode ? $this->get_validated_option( 'test_secret_key' ) : $this->get_validated_option( 'secret_key' );
118118
$this->publishable_key = $this->testmode ? $this->get_validated_option( 'test_publishable_key' ) : $this->get_validated_option( 'publishable_key' );
119-
$this->payment_request = 'yes' === $this->get_option( 'payment_request', 'yes' );
119+
$this->payment_request = 'yes' === $this->get_option( 'express_checkout', 'yes' );
120120

121121
WC_Stripe_API::set_secret_key( $this->secret_key );
122122

@@ -1236,7 +1236,7 @@ private function validate_field( $field_key, $field_value ) {
12361236
* @return bool
12371237
*/
12381238
public function is_payment_request_enabled() {
1239-
return 'yes' === $this->get_option( 'payment_request' );
1239+
return 'yes' === $this->get_option( 'express_checkout' );
12401240
}
12411241

12421242
/**

includes/class-wc-stripe-helper.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ public static function should_enqueue_in_current_tab_section( $tab, $section ) {
12511251
* @return boolean True if Stripe's JS should be loaded, false otherwise.
12521252
*/
12531253
public static function should_load_scripts_on_product_page() {
1254-
if ( self::should_load_scripts_for_prb_location( 'product' ) ) {
1254+
if ( self::should_load_scripts_for_ece_location( 'product' ) ) {
12551255
return true;
12561256
}
12571257

@@ -1268,7 +1268,7 @@ public static function should_load_scripts_on_product_page() {
12681268
* @return boolean True if Stripe's JS should be loaded, false otherwise.
12691269
*/
12701270
public static function should_load_scripts_on_cart_page() {
1271-
if ( self::should_load_scripts_for_prb_location( 'cart' ) ) {
1271+
if ( self::should_load_scripts_for_ece_location( 'cart' ) ) {
12721272
return true;
12731273
}
12741274

@@ -1282,11 +1282,11 @@ public static function should_load_scripts_on_cart_page() {
12821282
* @param string $location Either 'product' or 'cart'. Used to specify which location to check.
12831283
* @return boolean True if Stripe's JS should be loaded for the provided location, false otherwise.
12841284
*/
1285-
private static function should_load_scripts_for_prb_location( $location ) {
1285+
private static function should_load_scripts_for_ece_location( $location ) {
12861286
// Make sure location parameter is sanitized.
12871287
$location = in_array( $location, [ 'product', 'cart' ], true ) ? $location : '';
1288-
$are_prbs_enabled = self::get_settings( null, 'payment_request' ) ?? 'yes';
1289-
$prb_locations = self::get_settings( null, 'payment_request_button_locations' ) ?? [ 'product', 'cart' ];
1288+
$are_prbs_enabled = self::get_settings( null, 'express_checkout' ) ?? 'yes';
1289+
$prb_locations = self::get_settings( null, 'express_checkout_button_locations' ) ?? [ 'product', 'cart' ];
12901290

12911291
// The scripts should be loaded when all of the following are true:
12921292
// 1. The PRBs are enabled; and

includes/class-wc-stripe-payment-method-configurations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public static function maybe_migrate_payment_methods_from_db_to_pmc( $force_migr
545545
}
546546

547547
// Add Google Pay and Apple Pay to the list if payment_request is enabled
548-
if ( ! empty( $stripe_settings['payment_request'] ) && 'yes' === $stripe_settings['payment_request'] ) {
548+
if ( ! empty( $stripe_settings['express_checkout'] ) && 'yes' === $stripe_settings['express_checkout'] ) {
549549
$enabled_payment_methods = array_merge(
550550
$enabled_payment_methods,
551551
[ WC_Stripe_Payment_Methods::GOOGLE_PAY, WC_Stripe_Payment_Methods::APPLE_PAY ]

includes/class-wc-stripe.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,7 @@ public function init() {
217217
require_once WC_STRIPE_PLUGIN_PATH . '/includes/class-wc-stripe-account.php';
218218

219219
new Allowed_Payment_Request_Button_Types_Update();
220-
// TODO: Temporary disabling the migration as it has a conflict with the new UPE checkout.
221-
// new Migrate_Payment_Request_Data_To_Express_Checkout_Data();
220+
new Migrate_Payment_Request_Data_To_Express_Checkout_Data();
222221
new Sepa_Tokens_For_Other_Methods_Settings_Update();
223222

224223
$this->api = new WC_Stripe_Connect_API();
@@ -415,8 +414,8 @@ public function migrate_to_new_checkout_experience() {
415414
*/
416415
public function update_prb_location_settings() {
417416
$stripe_settings = WC_Stripe_Helper::get_stripe_settings();
418-
$prb_locations = isset( $stripe_settings['payment_request_button_locations'] )
419-
? $stripe_settings['payment_request_button_locations']
417+
$prb_locations = isset( $stripe_settings['express_checkout_button_locations'] )
418+
? $stripe_settings['express_checkout_button_locations']
420419
: [];
421420
if ( ! empty( $stripe_settings ) && empty( $prb_locations ) ) {
422421
global $post;
@@ -439,7 +438,7 @@ public function update_prb_location_settings() {
439438
$new_prb_locations[] = 'checkout';
440439
}
441440

442-
$stripe_settings['payment_request_button_locations'] = $new_prb_locations;
441+
$stripe_settings['express_checkout_button_locations'] = $new_prb_locations;
443442
WC_Stripe_Helper::update_main_stripe_settings( $stripe_settings );
444443
}
445444
}

includes/payment-methods/class-wc-stripe-express-checkout-helper.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function is_account_creation_possible() {
108108
* @return string
109109
*/
110110
public function get_button_type() {
111-
return isset( $this->stripe_settings['payment_request_button_type'] ) ? $this->stripe_settings['payment_request_button_type'] : 'default';
111+
return isset( $this->stripe_settings['express_checkout_button_type'] ) ? $this->stripe_settings['express_checkout_button_type'] : 'default';
112112
}
113113

114114
/**
@@ -117,7 +117,7 @@ public function get_button_type() {
117117
* @return string
118118
*/
119119
public function get_button_theme() {
120-
return isset( $this->stripe_settings['payment_request_button_theme'] ) ? $this->stripe_settings['payment_request_button_theme'] : 'dark';
120+
return isset( $this->stripe_settings['express_checkout_button_theme'] ) ? $this->stripe_settings['express_checkout_button_theme'] : 'dark';
121121
}
122122

123123
/**
@@ -126,7 +126,7 @@ public function get_button_theme() {
126126
* @return string
127127
*/
128128
public function get_button_height() {
129-
$height = isset( $this->stripe_settings['payment_request_button_size'] ) ? $this->stripe_settings['payment_request_button_size'] : 'default';
129+
$height = isset( $this->stripe_settings['express_checkout_button_size'] ) ? $this->stripe_settings['express_checkout_button_size'] : 'default';
130130
if ( 'small' === $height ) {
131131
return '40';
132132
}
@@ -144,7 +144,7 @@ public function get_button_height() {
144144
* @return string
145145
*/
146146
public function get_button_radius() {
147-
$height = isset( $this->stripe_settings['payment_request_button_size'] ) ? $this->stripe_settings['payment_request_button_size'] : 'default';
147+
$height = isset( $this->stripe_settings['express_checkout_button_size'] ) ? $this->stripe_settings['express_checkout_button_size'] : 'default';
148148
if ( 'small' === $height ) {
149149
return '2';
150150
}
@@ -1553,18 +1553,18 @@ public function get_login_confirmation_settings() {
15531553
*/
15541554
public function get_button_locations() {
15551555
// If the locations have not been set return the default setting.
1556-
if ( ! isset( $this->stripe_settings['payment_request_button_locations'] ) ) {
1556+
if ( ! isset( $this->stripe_settings['express_checkout_button_locations'] ) ) {
15571557
return [ 'product', 'cart' ];
15581558
}
15591559

15601560
// If all locations are removed through the settings UI the location config will be set to
15611561
// an empty string "". If that's the case (and if the settings are not an array for any
15621562
// other reason) we should return an empty array.
1563-
if ( ! is_array( $this->stripe_settings['payment_request_button_locations'] ) ) {
1563+
if ( ! is_array( $this->stripe_settings['express_checkout_button_locations'] ) ) {
15641564
return [];
15651565
}
15661566

1567-
return $this->stripe_settings['payment_request_button_locations'];
1567+
return $this->stripe_settings['express_checkout_button_locations'];
15681568
}
15691569

15701570
/**

0 commit comments

Comments
 (0)