From bc3234647c8c5f715c23426d98d83ee8f31f99ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20R=C3=B3bert?= Date: Thu, 9 Apr 2020 14:34:45 +0300 Subject: [PATCH] Don't render the button of the gateway is temporarily disabled --- modules.local/ppcp-button/services.php | 21 ++++++++++++------- .../src/Assets/DisabledSmartButton.php | 18 ++++++++++++++++ .../ppcp-button/src/Assets/SmartButton.php | 10 +++++---- .../src/Assets/SmartButtonInterface.php | 11 ++++++++++ 4 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 modules.local/ppcp-button/src/Assets/DisabledSmartButton.php create mode 100644 modules.local/ppcp-button/src/Assets/SmartButtonInterface.php diff --git a/modules.local/ppcp-button/services.php b/modules.local/ppcp-button/services.php index 9395d2f60..0312be207 100644 --- a/modules.local/ppcp-button/services.php +++ b/modules.local/ppcp-button/services.php @@ -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( diff --git a/modules.local/ppcp-button/src/Assets/DisabledSmartButton.php b/modules.local/ppcp-button/src/Assets/DisabledSmartButton.php new file mode 100644 index 000000000..bb404a0fe --- /dev/null +++ b/modules.local/ppcp-button/src/Assets/DisabledSmartButton.php @@ -0,0 +1,18 @@ +moduleUrl = $moduleUrl; $this->sessionHandler = $sessionHandler; - $this->isSandbox = $isSandbox; + $this->settingsContainer = $settings; } public function renderWrapper() : bool diff --git a/modules.local/ppcp-button/src/Assets/SmartButtonInterface.php b/modules.local/ppcp-button/src/Assets/SmartButtonInterface.php new file mode 100644 index 000000000..a9047210b --- /dev/null +++ b/modules.local/ppcp-button/src/Assets/SmartButtonInterface.php @@ -0,0 +1,11 @@ +