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;
use Inpsyde\PayPalCommerce\Button\Assets\SmartButton;
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\ChangeCartEndpoint;
use Inpsyde\PayPalCommerce\Button\Endpoint\CreateOrderEndpoint;
@ -12,13 +14,16 @@ use Inpsyde\PayPalCommerce\Button\Endpoint\RequestData;
use Inpsyde\PayPalCommerce\Button\Exception\RuntimeException;
return [
'button.smart-button' => function (ContainerInterface $container) : SmartButton {
$isSandbox = true;
return new SmartButton(
$container->get('button.url'),
$container->get('session.handler'),
$isSandbox
);
'button.smart-button' => function (ContainerInterface $container): SmartButtonInterface {
$settings = $container->get('wcgateway.settings');
if (wc_string_to_bool($settings->get('enabled'))) {
return new SmartButton(
$container->get('button.url'),
$container->get('session.handler'),
$settings
);
}
return new DisabledSmartButton();
},
'button.url' => function (ContainerInterface $container) : string {
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\CreateOrderEndpoint;
use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\WcGateway\Settings\Settings;
class SmartButton
class SmartButton implements SmartButtonInterface
{
private $moduleUrl;
private $sessionHandler;
private $isSandbox;
private $settingsContainer;
public function __construct(
string $moduleUrl,
SessionHandler $sessionHandler,
bool $isSandbox
Settings $settings
) {
$this->moduleUrl = $moduleUrl;
$this->sessionHandler = $sessionHandler;
$this->isSandbox = $isSandbox;
$this->settingsContainer = $settings;
}
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;
}