mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-31 06:52:50 +08:00
Don't render the button of the gateway is temporarily disabled
This commit is contained in:
parent
d7f2e33e60
commit
bc3234647c
4 changed files with 48 additions and 12 deletions
|
@ -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(
|
||||
|
|
18
modules.local/ppcp-button/src/Assets/DisabledSmartButton.php
Normal file
18
modules.local/ppcp-button/src/Assets/DisabledSmartButton.php
Normal 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;
|
||||
}
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Inpsyde\PayPalCommerce\Button\Assets;
|
||||
|
||||
interface SmartButtonInterface
|
||||
{
|
||||
public function renderWrapper(): bool;
|
||||
|
||||
public function enqueue(): bool;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue