Fix sandbox checkbox

Sometimes the state of UI may get restored after page reload and will not match the server settings
This commit is contained in:
Alex P 2022-02-08 10:25:01 +02:00
parent cb2adfd044
commit 44cb17107c
3 changed files with 18 additions and 0 deletions

View file

@ -257,6 +257,11 @@ function ppcp_onboarding_productionCallback(...args) {
}
);
const isSandboxInBackend = PayPalCommerceGatewayOnboarding.current_env === 'sandbox';
if (sandboxSwitchElement.checked !== isSandboxInBackend) {
sandboxSwitchElement.checked = isSandboxInBackend;
}
updateOptionsState();
const settingsContainer = document.querySelector('#mainform .form-table');

View file

@ -132,6 +132,7 @@ return array(
return new OnboardingAssets(
$container->get( 'onboarding.url' ),
$state,
$container->get( 'onboarding.environment' ),
$login_seller_endpoint
);
},

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\Onboarding\Assets;
use WooCommerce\PayPalCommerce\Onboarding\Endpoint\LoginSellerEndpoint;
use WooCommerce\PayPalCommerce\Onboarding\Environment;
use WooCommerce\PayPalCommerce\Onboarding\State;
/**
@ -31,6 +32,13 @@ class OnboardingAssets {
*/
private $state;
/**
* The Environment.
*
* @var Environment
*/
private $environment;
/**
* The LoginSeller Endpoint.
*
@ -43,16 +51,19 @@ class OnboardingAssets {
*
* @param string $module_url The URL to the module.
* @param State $state The State object.
* @param Environment $environment The Environment.
* @param LoginSellerEndpoint $login_seller_endpoint The LoginSeller endpoint.
*/
public function __construct(
string $module_url,
State $state,
Environment $environment,
LoginSellerEndpoint $login_seller_endpoint
) {
$this->module_url = untrailingslashit( $module_url );
$this->state = $state;
$this->environment = $environment;
$this->login_seller_endpoint = $login_seller_endpoint;
}
@ -109,6 +120,7 @@ class OnboardingAssets {
'sandbox_state' => State::get_state_name( $this->state->sandbox_state() ),
'production_state' => State::get_state_name( $this->state->production_state() ),
'current_state' => State::get_state_name( $this->state->current_state() ),
'current_env' => $this->environment->current_environment(),
'error_messages' => array(
'no_credentials' => __( 'Enter the credentials.', 'woocommerce-paypal-payments' ),
),