From 9cde0ae11b13b10355bc4245ca9f4b86b11ff489 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 10 Jun 2025 12:52:58 +0200 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=94=84=20Handle=20the=20Three=20D=20S?= =?UTF-8?q?ecure=20setting=20migration=20in=20the=20options=20and=20remove?= =?UTF-8?q?=20legacy=20references?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ppcp-compat/src/CompatModule.php | 33 +++++++++++++++++++ .../src/Data/PaymentSettings.php | 20 ----------- .../ppcp-settings/src/Data/SettingsModel.php | 2 +- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/modules/ppcp-compat/src/CompatModule.php b/modules/ppcp-compat/src/CompatModule.php index 81b603feb..0fbf6dedd 100644 --- a/modules/ppcp-compat/src/CompatModule.php +++ b/modules/ppcp-compat/src/CompatModule.php @@ -71,6 +71,7 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule { $this->migrate_pay_later_settings( $c ); $this->migrate_smart_button_settings( $c ); + $this->migrate_three_d_secure_setting(); $this->fix_page_builders(); $this->exclude_cache_plugins_js_minification( $c ); @@ -274,6 +275,38 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule { ); } + + /** + * Migrates the old Three D Secure setting located in PaymentSettings to the new location in SettingsModel. + * + * The migration will be done on plugin update if it hasn't already done. + */ + protected function migrate_three_d_secure_setting(): void { + $payment_settings = get_option('woocommerce-ppcp-data-payment') ?: array(); + $data_settings = get_option('woocommerce-ppcp-data-settings') ?: array(); + + // Skip if payment settings don't have the setting but data settings do. + if ( ! isset( $payment_settings['three_d_secure'] ) && isset( $data_settings['three_d_secure'] ) ) { + return; + } + + add_action( + 'woocommerce_paypal_payments_gateway_migrate_on_update', + function () { + $payment_settings = get_option('woocommerce-ppcp-data-payment') ?: array(); + $data_settings = get_option('woocommerce-ppcp-data-settings') ?: array(); + + // Move the setting. + $data_settings['three_d_secure'] = $payment_settings['three_d_secure']; + unset( $payment_settings['three_d_secure'] ); + + // Save both. + update_option('woocommerce-ppcp-data-settings', $data_settings); + update_option('woocommerce-ppcp-data-payment', $payment_settings); + } + ); + } + /** * Changes the button rendering place for page builders * that do not work well with our default places. diff --git a/modules/ppcp-settings/src/Data/PaymentSettings.php b/modules/ppcp-settings/src/Data/PaymentSettings.php index 52ac3e419..a61fb4b05 100644 --- a/modules/ppcp-settings/src/Data/PaymentSettings.php +++ b/modules/ppcp-settings/src/Data/PaymentSettings.php @@ -38,7 +38,6 @@ class PaymentSettings extends AbstractDataModel { protected function get_defaults() : array { return array( 'paypal_show_logo' => false, - 'three_d_secure' => 'no-3d-secure', 'fastlane_cardholder_name' => false, 'fastlane_display_watermark' => false, 'venmo_enabled' => false, @@ -158,15 +157,6 @@ class PaymentSettings extends AbstractDataModel { return (bool) $this->data['paypal_show_logo']; } - /** - * Get 3DSecure. - * - * @return string - */ - public function get_three_d_secure() : string { - return $this->data['three_d_secure']; - } - /** * Get Fastlane cardholder name. * @@ -213,16 +203,6 @@ class PaymentSettings extends AbstractDataModel { $this->data['paypal_show_logo'] = $value; } - /** - * Set 3DSecure. - * - * @param string $value The value. - * @return void - */ - public function set_three_d_secure( string $value ) : void { - $this->data['three_d_secure'] = $value; - } - /** * Set Fastlane cardholder name. * diff --git a/modules/ppcp-settings/src/Data/SettingsModel.php b/modules/ppcp-settings/src/Data/SettingsModel.php index ad8a6c74c..8f4b973e4 100644 --- a/modules/ppcp-settings/src/Data/SettingsModel.php +++ b/modules/ppcp-settings/src/Data/SettingsModel.php @@ -81,7 +81,7 @@ class SettingsModel extends AbstractDataModel { 'subtotal_adjustment' => 'correction', // Options: [correction|no_details]. 'landing_page' => 'any', // Options: [any|login|guest_checkout]. 'button_language' => '', // empty or a language locale code. - 'three_d_secure' => 'only-required-3d-secure', // Options: [no-3d-secure|only-required-3d-secure|always-3d-secure]. + 'three_d_secure' => 'no-3d-secure', // Options: [no-3d-secure|only-required-3d-secure|always-3d-secure]. // Boolean flags. 'authorize_only' => false, From 3443cd0ecf440e146f65debdb72774611b9d26b5 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 10 Jun 2025 12:56:55 +0200 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A7=B9=20Fix=20PHPCS=20linting=20issu?= =?UTF-8?q?es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ppcp-compat/src/CompatModule.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/ppcp-compat/src/CompatModule.php b/modules/ppcp-compat/src/CompatModule.php index 0fbf6dedd..a77ec4a68 100644 --- a/modules/ppcp-compat/src/CompatModule.php +++ b/modules/ppcp-compat/src/CompatModule.php @@ -282,8 +282,8 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule { * The migration will be done on plugin update if it hasn't already done. */ protected function migrate_three_d_secure_setting(): void { - $payment_settings = get_option('woocommerce-ppcp-data-payment') ?: array(); - $data_settings = get_option('woocommerce-ppcp-data-settings') ?: array(); + $payment_settings = get_option( 'woocommerce-ppcp-data-payment' ) ?: array(); + $data_settings = get_option( 'woocommerce-ppcp-data-settings' ) ?: array(); // Skip if payment settings don't have the setting but data settings do. if ( ! isset( $payment_settings['three_d_secure'] ) && isset( $data_settings['three_d_secure'] ) ) { @@ -293,16 +293,16 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule { add_action( 'woocommerce_paypal_payments_gateway_migrate_on_update', function () { - $payment_settings = get_option('woocommerce-ppcp-data-payment') ?: array(); - $data_settings = get_option('woocommerce-ppcp-data-settings') ?: array(); + $payment_settings = get_option( 'woocommerce-ppcp-data-payment' ) ?: array(); + $data_settings = get_option( 'woocommerce-ppcp-data-settings' ) ?: array(); // Move the setting. $data_settings['three_d_secure'] = $payment_settings['three_d_secure']; unset( $payment_settings['three_d_secure'] ); // Save both. - update_option('woocommerce-ppcp-data-settings', $data_settings); - update_option('woocommerce-ppcp-data-payment', $payment_settings); + update_option( 'woocommerce-ppcp-data-settings', $data_settings ); + update_option( 'woocommerce-ppcp-data-payment', $payment_settings ); } ); } From df8709aee94cc43e67ce00446c7cbf3c0ae4c6c5 Mon Sep 17 00:00:00 2001 From: Daniel Dudzic Date: Tue, 10 Jun 2025 14:58:47 +0200 Subject: [PATCH 3/3] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=203DS=20migra?= =?UTF-8?q?tion=20to=20run=20only=20when=20needed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/ppcp-compat/src/CompatModule.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/modules/ppcp-compat/src/CompatModule.php b/modules/ppcp-compat/src/CompatModule.php index a77ec4a68..b530e929d 100644 --- a/modules/ppcp-compat/src/CompatModule.php +++ b/modules/ppcp-compat/src/CompatModule.php @@ -282,20 +282,17 @@ class CompatModule implements ServiceModule, ExtendingModule, ExecutableModule { * The migration will be done on plugin update if it hasn't already done. */ protected function migrate_three_d_secure_setting(): void { - $payment_settings = get_option( 'woocommerce-ppcp-data-payment' ) ?: array(); - $data_settings = get_option( 'woocommerce-ppcp-data-settings' ) ?: array(); - - // Skip if payment settings don't have the setting but data settings do. - if ( ! isset( $payment_settings['three_d_secure'] ) && isset( $data_settings['three_d_secure'] ) ) { - return; - } - add_action( 'woocommerce_paypal_payments_gateway_migrate_on_update', function () { $payment_settings = get_option( 'woocommerce-ppcp-data-payment' ) ?: array(); $data_settings = get_option( 'woocommerce-ppcp-data-settings' ) ?: array(); + // Skip if payment settings don't have the setting but data settings do. + if ( ! isset( $payment_settings['three_d_secure'] ) && isset( $data_settings['three_d_secure'] ) ) { + return; + } + // Move the setting. $data_settings['three_d_secure'] = $payment_settings['three_d_secure']; unset( $payment_settings['three_d_secure'] );