From 3001245c3b22337315dc22453f0fedfa8f4fb14d Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 16 Jul 2025 19:13:53 +0400 Subject: [PATCH 1/5] Update option if the migration is done. --- modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php b/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php index d5d5fb0da..a1bc218d0 100644 --- a/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php +++ b/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php @@ -24,6 +24,7 @@ class SwitchSettingsUiEndpoint { public const ENDPOINT = 'ppcp-settings-switch-ui'; public const OPTION_NAME_SHOULD_USE_OLD_UI = 'woocommerce_ppcp-settings-should-use-old-ui'; + public const OPTION_NAME_MIGRATION_IS_DONE = 'woocommerce_ppcp-settings-migration-is-done'; protected RequestData $request_data; protected LoggerInterface $logger; @@ -70,6 +71,8 @@ class SwitchSettingsUiEndpoint { $this->onboarding_profile->save(); $this->settings_data_migration->migrate(); + + update_option( self::OPTION_NAME_MIGRATION_IS_DONE, 'yes' ); wp_send_json_success(); } catch ( Exception $error ) { wp_send_json_error( array( 'message' => $error->getMessage() ), 500 ); From e3eee0970d1b799860d6dcdede52a17c7f70b1df Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 16 Jul 2025 19:14:11 +0400 Subject: [PATCH 2/5] Add the todo based on option --- .../src/Data/Definition/TodosDefinition.php | 69 ++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php index 6d1a3be7a..a8018842c 100644 --- a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php @@ -9,6 +9,8 @@ declare(strict_types=1); namespace WooCommerce\PayPalCommerce\Settings\Data\Definition; +use WooCommerce\PayPalCommerce\Settings\Ajax\SwitchSettingsUiEndpoint; +use WooCommerce\PayPalCommerce\Settings\Data\TodosModel; use WooCommerce\PayPalCommerce\Settings\Service\TodosEligibilityService; use WooCommerce\PayPalCommerce\Settings\Data\GeneralSettings; @@ -34,18 +36,23 @@ class TodosDefinition { */ protected GeneralSettings $settings; + protected TodosModel $todos; + /** * Constructor. * * @param TodosEligibilityService $eligibilities The todos eligibility service. * @param GeneralSettings $settings The general settings service. + * @param TodosModel $todos The todos model instance. */ public function __construct( TodosEligibilityService $eligibilities, - GeneralSettings $settings + GeneralSettings $settings, + TodosModel $todos ) { $this->eligibilities = $eligibilities; $this->settings = $settings; + $this->todos = $todos; } /** @@ -56,7 +63,7 @@ class TodosDefinition { public function get(): array { $eligibility_checks = $this->eligibilities->get_eligibility_checks(); - return array( + $todo_items = array( 'enable_fastlane' => array( 'title' => __( 'Enable Fastlane', 'woocommerce-paypal-payments' ), 'description' => __( 'Accelerate your guest checkout with Fastlane by PayPal', 'woocommerce-paypal-payments' ), @@ -228,5 +235,63 @@ class TodosDefinition { 'priority' => 13, ), ); + + $todo_items['check_settings_after_migration'] = array( + 'title' => __( "You're now using the new PayPal Payments interface!", 'woocommerce-paypal-payments' ), + 'description' => __( 'Complete the items below to ensure your payment configuration is optimized for your store.', 'woocommerce-paypal-payments' ), + 'isEligible' => fn(): bool => $this->is_settings_migration_done() && ! $this->are_all_todos_completed( $todo_items ), + 'action' => array( + 'type' => 'tab', + 'tab' => 'overview', + ), + 'priority' => 0, + ); + + return $todo_items; } + + /** + * Checks whether the settings migration to the new UI has been completed. + * + * @return bool True if the migration is marked as done, false otherwise. + */ + protected function is_settings_migration_done(): bool { + return 'yes' === get_option( SwitchSettingsUiEndpoint::OPTION_NAME_MIGRATION_IS_DONE ); + } + + /** + * Determines whether all todos have been completed or dismissed appropriately. + * + * A to-do is considered completed if: + * - It's eligible (based on the callable `isEligible`), AND + * - It is either: + * - A "completeOnClick" type and is present in the completed list, OR + * - Not a "completeOnClick" type and is present in the dismissed list. + * + * @param array $todos The array of to-do definitions. + * @return bool True if all to-dos are completed or dismissed as expected, false otherwise. + */ + protected function are_all_todos_completed( array $todos ): bool { + $dismissed = $this->todos->get_dismissed_todos(); + $completed = $this->todos->get_completed_onclick_todos(); + + foreach ( $todos as $id => $todo ) { + if ( ! is_callable( $todo['isEligible'] ) || ! call_user_func( $todo['isEligible'] ) ) { + continue; + } + + $is_click_to_complete = $todo['action']['completeOnClick'] ?? false; + + if ( $is_click_to_complete && ! in_array( $id, $completed, true ) ) { + return false; + } + + if ( ! $is_click_to_complete && ! in_array( $id, $dismissed, true ) ) { + return false; + } + } + + return true; + } + } From 4e93aca57aaa916f0a41e4743333944f808dc57d Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 16 Jul 2025 19:14:24 +0400 Subject: [PATCH 3/5] Add appropriate services --- modules/ppcp-settings/services.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 0a00db31e..2b2a838f4 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -417,7 +417,8 @@ $services = array( 'settings.data.definition.todos' => static function ( ContainerInterface $container ) : TodosDefinition { return new TodosDefinition( $container->get( 'settings.service.todos_eligibilities' ), - $container->get( 'settings.data.general' ) + $container->get( 'settings.data.general' ), + $container->get( 'settings.data.todos' ) ); }, 'settings.data.definition.methods' => static function ( ContainerInterface $container ) : PaymentMethodsDefinition { From 0fc54d1df5203f489b067be40048a71dee490aaa Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Wed, 16 Jul 2025 19:14:46 +0400 Subject: [PATCH 4/5] Remove the option on plugin uninstall --- modules/ppcp-uninstall/services.php | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/ppcp-uninstall/services.php b/modules/ppcp-uninstall/services.php index 629f1164b..3256b4672 100644 --- a/modules/ppcp-uninstall/services.php +++ b/modules/ppcp-uninstall/services.php @@ -36,6 +36,7 @@ return array( WebhookRegistrar::KEY, 'ppcp_payment_tokens_migration_initialized', SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI, + SwitchSettingsUiEndpoint::OPTION_NAME_MIGRATION_IS_DONE, ); }, From 0eb932a73ed7311ab40ca48c71504bb4528faa6c Mon Sep 17 00:00:00 2001 From: Narek Zakarian Date: Tue, 5 Aug 2025 11:45:23 +0400 Subject: [PATCH 5/5] use boolean as option value --- modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php | 2 +- modules/ppcp-settings/src/Data/Definition/TodosDefinition.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php b/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php index a1bc218d0..62f2a5eaf 100644 --- a/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php +++ b/modules/ppcp-settings/src/Ajax/SwitchSettingsUiEndpoint.php @@ -72,7 +72,7 @@ class SwitchSettingsUiEndpoint { $this->settings_data_migration->migrate(); - update_option( self::OPTION_NAME_MIGRATION_IS_DONE, 'yes' ); + update_option( self::OPTION_NAME_MIGRATION_IS_DONE, true ); wp_send_json_success(); } catch ( Exception $error ) { wp_send_json_error( array( 'message' => $error->getMessage() ), 500 ); diff --git a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php index a8018842c..6c5bc4b0e 100644 --- a/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php +++ b/modules/ppcp-settings/src/Data/Definition/TodosDefinition.php @@ -256,7 +256,7 @@ class TodosDefinition { * @return bool True if the migration is marked as done, false otherwise. */ protected function is_settings_migration_done(): bool { - return 'yes' === get_option( SwitchSettingsUiEndpoint::OPTION_NAME_MIGRATION_IS_DONE ); + return '1' === get_option( SwitchSettingsUiEndpoint::OPTION_NAME_MIGRATION_IS_DONE ); } /**