Don't render the button of the gateway is temporarily disabled

This commit is contained in:
Mészáros Róbert 2020-04-09 14:34:45 +03:00
parent d7f2e33e60
commit bc3234647c
4 changed files with 48 additions and 12 deletions

View file

@ -3,8 +3,10 @@ declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Button; namespace Inpsyde\PayPalCommerce\Button;
use Inpsyde\PayPalCommerce\Button\Assets\SmartButton;
use Dhii\Data\Container\ContainerInterface; use Dhii\Data\Container\ContainerInterface;
use Inpsyde\PayPalCommerce\Button\Assets\DisabledSmartButton;
use Inpsyde\PayPalCommerce\Button\Assets\SmartButton;
use Inpsyde\PayPalCommerce\Button\Assets\SmartButtonInterface;
use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
@ -12,13 +14,16 @@ use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException; use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
return [ return [
'button.smart-button' => function (ContainerInterface $container) : SmartButton { 'button.smart-button' => function (ContainerInterface $container): SmartButtonInterface {
$isSandbox = true; $settings = $container->get('wcgateway.settings');
return new SmartButton( if (wc_string_to_bool($settings->get('enabled'))) {
$container->get('button.url'), return new SmartButton(
$container->get('session.handler'), $container->get('button.url'),
$isSandbox $container->get('session.handler'),
); $settings
);
}
return new DisabledSmartButton();
}, },
'button.url' => function (ContainerInterface $container) : string { 'button.url' => function (ContainerInterface $container) : string {
return plugins_url( return plugins_url(

View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Button\Assets;
class DisabledSmartButton implements SmartButtonInterface
{
public function renderWrapper(): bool
{
return true;
}
public function enqueue(): bool
{
return true;
}
}

View file

@ -7,22 +7,24 @@ use Inpsyde\PayPalCommerce\Button\Endpoint\ApproveOrderEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\ChangeCartEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint; use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
use Inpsyde\PayPalCommerce\Session\SessionHandler; use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
class SmartButton class SmartButton implements SmartButtonInterface
{ {
private $moduleUrl; private $moduleUrl;
private $sessionHandler; private $sessionHandler;
private $isSandbox; private $settingsContainer;
public function __construct( public function __construct(
string $moduleUrl, string $moduleUrl,
SessionHandler $sessionHandler, SessionHandler $sessionHandler,
bool $isSandbox Settings $settings
) { ) {
$this->moduleUrl = $moduleUrl; $this->moduleUrl = $moduleUrl;
$this->sessionHandler = $sessionHandler; $this->sessionHandler = $sessionHandler;
$this->isSandbox = $isSandbox; $this->settingsContainer = $settings;
} }
public function renderWrapper() : bool public function renderWrapper() : bool

View file

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
namespace Inpsyde\PayPalCommerce\Button\Assets;
interface SmartButtonInterface
{
public function renderWrapper(): bool;
public function enqueue(): bool;
}