mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
disable WcGateway if no merchant_email is present
This commit is contained in:
parent
45348788a3
commit
250e127afc
2 changed files with 15 additions and 3 deletions
|
@ -36,7 +36,8 @@ return [
|
|||
},
|
||||
'wcgateway.disabler' => static function (ContainerInterface $container): DisableGateways {
|
||||
$sessionHandler = $container->get('session.handler');
|
||||
return new DisableGateways($sessionHandler);
|
||||
$settings = $container->get('wcgateway.settings');
|
||||
return new DisableGateways($sessionHandler, $settings);
|
||||
},
|
||||
'wcgateway.settings' => static function (ContainerInterface $container): Settings {
|
||||
return new Settings();
|
||||
|
|
|
@ -6,22 +6,33 @@ namespace Inpsyde\PayPalCommerce\WcGateway\Checkout;
|
|||
|
||||
use Inpsyde\PayPalCommerce\Session\SessionHandler;
|
||||
use Inpsyde\PayPalCommerce\WcGateway\Gateway\WcGateway;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class DisableGateways
|
||||
{
|
||||
|
||||
private $sessionHandler;
|
||||
public function __construct(SessionHandler $sessionHandler)
|
||||
{
|
||||
private $settings;
|
||||
public function __construct(
|
||||
SessionHandler $sessionHandler,
|
||||
ContainerInterface $settings
|
||||
) {
|
||||
$this->sessionHandler = $sessionHandler;
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
public function handler(array $methods): array
|
||||
{
|
||||
if (! $this->settings->has('merchant_email') || ! is_email($this->settings->get('merchant_email'))) {
|
||||
unset($methods[WcGateway::ID]);
|
||||
return $methods;
|
||||
}
|
||||
if (! $this->needsToDisableGateways()) {
|
||||
return $methods;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return [WcGateway::ID => $methods[WcGateway::ID]];
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue