diff --git a/modules/ppcp-settings/services.php b/modules/ppcp-settings/services.php index 349c13350..89afdfc47 100644 --- a/modules/ppcp-settings/services.php +++ b/modules/ppcp-settings/services.php @@ -196,6 +196,8 @@ return new SwitchSettingsUiEndpoint( $container->get( 'woocommerce.logger.woocommerce' ), $container->get( 'button.request-data' ), + $container->get( 'settings.data.onboarding' ), + $container->get( 'api.merchant_id' ) !== '' ); }, ); diff --git a/modules/ppcp-settings/src/Endpoint/SwitchSettingsUiEndpoint.php b/modules/ppcp-settings/src/Endpoint/SwitchSettingsUiEndpoint.php index 244c26dfe..03057297f 100644 --- a/modules/ppcp-settings/src/Endpoint/SwitchSettingsUiEndpoint.php +++ b/modules/ppcp-settings/src/Endpoint/SwitchSettingsUiEndpoint.php @@ -12,6 +12,7 @@ use Exception; use Psr\Log\LoggerInterface; use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData; +use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile; /** * Class SwitchSettingsUiEndpoint @@ -37,18 +38,38 @@ class SwitchSettingsUiEndpoint { */ protected LoggerInterface $logger; + /** + * The Onboarding profile. + * + * @var OnboardingProfile + */ + protected OnboardingProfile $onboarding_profile; + + /** + * True if the merchant is onboarded, otherwise false. + * + * @var bool + */ + protected bool $is_onboarded; + /** * SwitchSettingsUiEndpoint constructor. * - * @param LoggerInterface $logger The logger. - * @param RequestData $request_data The Request data. + * @param LoggerInterface $logger The logger. + * @param RequestData $request_data The Request data. + * @param OnboardingProfile $onboarding_profile The Onboarding profile. + * @param bool $is_onboarded True if the merchant is onboarded, otherwise false. */ public function __construct( LoggerInterface $logger, - RequestData $request_data + RequestData $request_data, + OnboardingProfile $onboarding_profile, + bool $is_onboarded ) { - $this->logger = $logger; - $this->request_data = $request_data; + $this->logger = $logger; + $this->request_data = $request_data; + $this->onboarding_profile = $onboarding_profile; + $this->is_onboarded = $is_onboarded; } /** @@ -62,7 +83,12 @@ public function handle_request(): void { try { $this->request_data->read_request( $this->nonce() ); - update_option( self::OPTION_NAME_SHOULD_USE_OLD_UI, false ); + update_option( self::OPTION_NAME_SHOULD_USE_OLD_UI, 'no' ); + + if ( $this->is_onboarded ) { + $this->onboarding_profile->set_completed( true ); + $this->onboarding_profile->save(); + } wp_send_json_success(); } catch ( Exception $error ) { diff --git a/modules/ppcp-settings/src/SettingsModule.php b/modules/ppcp-settings/src/SettingsModule.php index f2d7267e0..ecfa3c662 100644 --- a/modules/ppcp-settings/src/SettingsModule.php +++ b/modules/ppcp-settings/src/SettingsModule.php @@ -29,7 +29,7 @@ class SettingsModule implements ServiceModule, ExecutableModule { public static function should_use_the_old_ui() : bool { return apply_filters( 'woocommerce_paypal_payments_should_use_the_old_ui', - (bool) get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI ) === true + get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI ) === 'yes' ); } @@ -100,6 +100,12 @@ static function () use ( $container ) { return true; } + add_action( + 'woocommerce_paypal_payments_gateway_migrate_on_update', + static fn () => ! get_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI ) + && update_option( SwitchSettingsUiEndpoint::OPTION_NAME_SHOULD_USE_OLD_UI, 'yes' ) + ); + add_action( 'admin_enqueue_scripts', /**