add reset button

This commit is contained in:
David Remer 2020-06-30 11:04:19 +03:00
parent cbca7491f5
commit 3b35d6a0ee
6 changed files with 71 additions and 19 deletions

View file

@ -73,10 +73,11 @@ return [
if ($state->currentState() === State::STATE_START) {
return new StartSettings();
}
$environment = $container->get('onboarding.environment');
if ($state->currentState() === State::STATE_PROGRESSIVE) {
return new ProgressiveSettings();
return new ProgressiveSettings($environment);
}
return new FullyOnboardedSettings();
return new FullyOnboardedSettings($environment);
},
'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor {

View file

@ -159,4 +159,23 @@ class WcGateway extends WcGatewayBase
ob_end_clean();
return $content;
}
public function generate_ppcp_info_html($type, $data) : string
{
ob_start();
?>
<tr valign="top">
<th scope="row" class="titledesc">
<?php echo wp_kses_post( $data['title'] ); ?>
</th>
<td class="forminp">
<?php echo wp_kses_post( $data['text'] ); ?>
</td>
</tr>
<?php
$content = ob_get_contents();
ob_end_clean();
return $content;
}
}

View file

@ -4,8 +4,17 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
use Inpsyde\PayPalCommerce\Onboarding\Environment;
class FullyOnboardedSettings extends StartSettings implements SettingsFields
{
use SettingsTrait;
public function __construct(Environment $environment)
{
$this->environment = $environment;
}
public function fields(): array
{
return array_merge(
@ -23,7 +32,7 @@ class FullyOnboardedSettings extends StartSettings implements SettingsFields
private function gateway(): array
{
return array_merge(
parent::fields(),
$this->defaultFields(),
[
'intent' => [
'title' => __('Intent', 'woocommerce-paypal-gateway'),

View file

@ -4,23 +4,33 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
class ProgressiveSettings extends StartSettings implements SettingsFields
use Inpsyde\PayPalCommerce\Onboarding\Environment;
class ProgressiveSettings implements SettingsFields
{
use SettingsTrait;
public function __construct(Environment $environment)
{
$this->environment = $environment;
}
public function fields(): array
{
return array_merge(
$fields = array_merge(
[
'onboarding' => [
'type' => 'ppcp_onboarding',
],
],
parent::fields(),
$this->defaultFields(),
[
'reset' => [
'type' => 'ppcp_reset',
],
]
);
return $fields;
}
}

View file

@ -4,11 +4,23 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
use Inpsyde\PayPalCommerce\Onboarding\Environment;
trait SettingsTrait
{
/**
* @var Environment
*/
private $environment;
private function defaultFields(): array
{
$isSandbox = ($this->environment) ? $this->environment->currentEnvironmentIs(Environment::SANDBOX) : false;
$sandbox = [
'type' => 'ppcp_info',
'title' => __('Sandbox'),
'text' => ($isSandbox) ? __('You are currently in the sandbox mode. Click Reset if you want to change your mode.', 'woocommerce-paypal-commerce-gateway') : __('You are in production mode. Click Reset if you want to change your mode.', 'woocommerce-paypal-commerce-gateway'),
];
return [
'enabled' => [
'title' => __('Enable/Disable', 'woocommerce-paypal-gateway'),
@ -45,15 +57,17 @@ trait SettingsTrait
'type' => 'title',
'description' => '',
],
'sandbox_on' => [
'title' => __('Enable Sandbox', 'woocommerce-paypal-gateway'),
'type' => 'checkbox',
'label' => __(
'For testing your integration, you can enable the sandbox.',
'merchant_email' => [
'title' => __('PayPal Email', 'woocommerce-paypal-gateway'),
'type' => 'email',
'description' => __(
'Please enter the email address with which you want to receive payments.',
'woocommerce-paypal-gateway'
),
'default' => 'yes',
'default' => '',
'desc_tip' => true,
],
'sandbox_on' => $sandbox,
];
}
}

View file

@ -13,15 +13,14 @@ class StartSettings implements SettingsFields
return array_merge(
$this->defaultFields(),
[
'merchant_email' => [
'title' => __('PayPal Email', 'woocommerce-paypal-gateway'),
'type' => 'email',
'description' => __(
'Please enter the email address with which you want to receive payments.',
'sandbox_on' => [
'title' => __('Enable Sandbox', 'woocommerce-paypal-gateway'),
'type' => 'checkbox',
'label' => __(
'For testing your integration, you can enable the sandbox.',
'woocommerce-paypal-gateway'
),
'default' => '',
'desc_tip' => true,
'default' => 'no',
],
]
);