add a toggle to enable user adding credentials manually

This commit is contained in:
David Remer 2020-07-28 05:41:09 +03:00
parent a53e4d4187
commit 6a4b406568
5 changed files with 88 additions and 32 deletions

View file

@ -0,0 +1,21 @@
.optional {
display: none;
}
#field-client_secret,
#field-client_id {
display: none;
}
#field-toggle_manual_input button {
color: #0073aa;
transition-property: border, background, color;
transition-duration: .05s;
transition-timing-function: ease-in-out;
background: none;
border: none;
text-decoration: underline;
cursor: pointer;
margin: 0;
padding: 0;
}

View file

@ -0,0 +1,11 @@
(() => {
document.querySelector('#field-toggle_manual_input').addEventListener(
'click',
(event) => {
event.preventDefault();
document.querySelector('#field-toggle_manual_input').style.display = 'none';
document.querySelector('#field-client_id').style.display = 'table-row';
document.querySelector('#field-client_secret').style.display = 'table-row';
}
)
})()

View file

@ -28,7 +28,17 @@ class OnboardingAssets
public function register(): bool
{
if (!$this->shouldRender()) {
$url = $this->moduleUrl . '/assets/css/onboarding.css';
wp_register_style(
'ppcp-onboarding',
$url
);
$url = $this->moduleUrl . '/assets/js/settings.js';
wp_register_script(
'ppcp-settings',
$url
);
if (!$this->shouldRenderOnboardingScript()) {
return false;
}
@ -53,12 +63,15 @@ class OnboardingAssets
]
);
return true;
}
public function enqueue(): bool
{
if (! $this->shouldRender()) {
wp_enqueue_style('ppcp-onboarding');
wp_enqueue_script('ppcp-settings');
if (! $this->shouldRenderOnboardingScript()) {
return false;
}
@ -66,7 +79,7 @@ class OnboardingAssets
return true;
}
private function shouldRender(): bool
private function shouldRenderOnboardingScript(): bool
{
// phpcs:disable Inpsyde.CodeQuality.VariablesName.SnakeCaseVar
global $current_section;

View file

@ -160,6 +160,7 @@ return [
'merchant_email' => [
'title' => __('Email address', 'woocommerce-paypal-commerce-gateway'),
'type' => 'text',
'required' => true,
'desc_tip' => true,
'description' => __('The email address of your PayPal account.', 'woocommerce-paypal-commerce-gateway'),
'default' => '',
@ -179,6 +180,43 @@ return [
'hidden' => 'merchant_email',
'requirements' => [],
],
'toggle_manual_input' => [
'type' => 'ppcp-text',
'title' => __('Manual mode', 'woocommerce-paypla-commerce-gateway'),
'text' => '<button id="ppcp[toggle_manual_input]">' . __('Toggle to manual credential input', 'woocommerce-paypal-commerce-gateway') . '</button>',
'screens' => [
State::STATE_START,
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
],
'requirements' => [],
],
'client_id' => [
'title' => __('Client Id', 'woocommerce-paypal-commerce-gateway'),
'type' => 'text',
'desc_tip' => true,
'description' => __('The client id of your api ', 'woocommerce-paypal-commerce-gateway'),
'default' => false,
'screens' => [
State::STATE_START,
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
],
'requirements' => [],
],
'client_secret' => [
'title' => __('Secret Key', 'woocommerce-paypal-commerce-gateway'),
'type' => 'password',
'desc_tip' => true,
'description' => __('The secret key of your api', 'woocommerce-paypal-commerce-gateway'),
'default' => false,
'screens' => [
State::STATE_START,
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
],
'requirements' => [],
],
'title' => [
'title' => __('Title', 'woocommerce-paypal-commerce-gateway'),
'type' => 'text',
@ -491,34 +529,6 @@ return [
],
'requirements' => [],
],
'client_id' => [
'title' => __('Client Id', 'woocommerce-paypal-commerce-gateway'),
'type' => 'text',
'desc_tip' => true,
'label' => __('Enable logging', 'woocommerce-paypal-commerce-gateway'),
'description' => __('Enable logging of unexpected behavior. This can also log private data and should only be enabled in a development or stage environment.', 'woocommerce-paypal-commerce-gateway'),
'default' => false,
'screens' => [
State::STATE_START,
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
],
'requirements' => [],
],
'client_secret' => [
'title' => __('Secret Id', 'woocommerce-paypal-commerce-gateway'),
'type' => 'text',
'desc_tip' => true,
'label' => __('Enable logging', 'woocommerce-paypal-commerce-gateway'),
'description' => __('Enable logging of unexpected behavior. This can also log private data and should only be enabled in a development or stage environment.', 'woocommerce-paypal-commerce-gateway'),
'default' => false,
'screens' => [
State::STATE_START,
State::STATE_PROGRESSIVE,
State::STATE_ONBOARDED,
],
'requirements' => [],
],
];
},
];

View file

@ -76,8 +76,9 @@ class SettingsRenderer
}
$value = $this->settings->has($field) ? $this->settings->get($field) : null;
$id = 'ppcp[' . $field . ']';
?>
<tr valign="top">
<tr valign="top" id="<?php echo esc_attr('field-' . $field); ?>">
<th>
<label
for="<?php echo esc_attr($id); ?>"