mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-08 21:52:55 +08:00
new/old settings UI vs new/existing users
This commit is contained in:
parent
ba7fbb0943
commit
d8006cb3d0
3 changed files with 42 additions and 7 deletions
|
@ -196,6 +196,8 @@ return array(
|
|||
return new SwitchSettingsUiEndpoint(
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
$container->get( 'button.request-data' ),
|
||||
$container->get( 'settings.data.onboarding' ),
|
||||
$container->get( 'api.merchant_id' ) !== ''
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -12,6 +12,7 @@ namespace WooCommerce\PayPalCommerce\Settings\Endpoint;
|
|||
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 @@ class SwitchSettingsUiEndpoint {
|
|||
|
||||
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 ) {
|
||||
|
|
|
@ -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,13 @@ class SettingsModule implements ServiceModule, ExecutableModule {
|
|||
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',
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue