Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default UI: Legacy for existing merchants, React for new merchants (4030) #2936

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
2 changes: 2 additions & 0 deletions modules/ppcp-settings/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) !== ''
);
},
);
38 changes: 32 additions & 6 deletions modules/ppcp-settings/src/Endpoint/SwitchSettingsUiEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Exception;
use Psr\Log\LoggerInterface;
use WooCommerce\PayPalCommerce\Button\Endpoint\RequestData;
use WooCommerce\PayPalCommerce\Settings\Data\OnboardingProfile;

/**
* Class SwitchSettingsUiEndpoint
Expand All @@ -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;
}

/**
Expand All @@ -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 ) {
Expand Down
8 changes: 7 additions & 1 deletion modules/ppcp-settings/src/SettingsModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
}

Expand Down Expand Up @@ -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',
/**
Expand Down
Loading