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) { if ($state->currentState() === State::STATE_START) {
return new StartSettings(); return new StartSettings();
} }
$environment = $container->get('onboarding.environment');
if ($state->currentState() === State::STATE_PROGRESSIVE) { 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 { 'wcgateway.order-processor' => static function (ContainerInterface $container): OrderProcessor {

View file

@ -159,4 +159,23 @@ class WcGateway extends WcGatewayBase
ob_end_clean(); ob_end_clean();
return $content; 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; namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
use Inpsyde\PayPalCommerce\Onboarding\Environment;
class FullyOnboardedSettings extends StartSettings implements SettingsFields class FullyOnboardedSettings extends StartSettings implements SettingsFields
{ {
use SettingsTrait;
public function __construct(Environment $environment)
{
$this->environment = $environment;
}
public function fields(): array public function fields(): array
{ {
return array_merge( return array_merge(
@ -23,7 +32,7 @@ class FullyOnboardedSettings extends StartSettings implements SettingsFields
private function gateway(): array private function gateway(): array
{ {
return array_merge( return array_merge(
parent::fields(), $this->defaultFields(),
[ [
'intent' => [ 'intent' => [
'title' => __('Intent', 'woocommerce-paypal-gateway'), 'title' => __('Intent', 'woocommerce-paypal-gateway'),

View file

@ -4,23 +4,33 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Settings; 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 public function fields(): array
{ {
return array_merge( $fields = array_merge(
[ [
'onboarding' => [ 'onboarding' => [
'type' => 'ppcp_onboarding', 'type' => 'ppcp_onboarding',
], ],
], ],
parent::fields(), $this->defaultFields(),
[ [
'reset' => [ 'reset' => [
'type' => 'ppcp_reset', 'type' => 'ppcp_reset',
], ],
] ]
); );
return $fields;
} }
} }

View file

@ -4,11 +4,23 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\WcGateway\Settings; namespace Inpsyde\PayPalCommerce\WcGateway\Settings;
use Inpsyde\PayPalCommerce\Onboarding\Environment;
trait SettingsTrait trait SettingsTrait
{ {
/**
* @var Environment
*/
private $environment;
private function defaultFields(): array 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 [ return [
'enabled' => [ 'enabled' => [
'title' => __('Enable/Disable', 'woocommerce-paypal-gateway'), 'title' => __('Enable/Disable', 'woocommerce-paypal-gateway'),
@ -45,15 +57,17 @@ trait SettingsTrait
'type' => 'title', 'type' => 'title',
'description' => '', 'description' => '',
], ],
'sandbox_on' => [ 'merchant_email' => [
'title' => __('Enable Sandbox', 'woocommerce-paypal-gateway'), 'title' => __('PayPal Email', 'woocommerce-paypal-gateway'),
'type' => 'checkbox', 'type' => 'email',
'label' => __( 'description' => __(
'For testing your integration, you can enable the sandbox.', 'Please enter the email address with which you want to receive payments.',
'woocommerce-paypal-gateway' '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( return array_merge(
$this->defaultFields(), $this->defaultFields(),
[ [
'merchant_email' => [ 'sandbox_on' => [
'title' => __('PayPal Email', 'woocommerce-paypal-gateway'), 'title' => __('Enable Sandbox', 'woocommerce-paypal-gateway'),
'type' => 'email', 'type' => 'checkbox',
'description' => __( 'label' => __(
'Please enter the email address with which you want to receive payments.', 'For testing your integration, you can enable the sandbox.',
'woocommerce-paypal-gateway' 'woocommerce-paypal-gateway'
), ),
'default' => '', 'default' => 'no',
'desc_tip' => true,
], ],
] ]
); );