disable WcGateway if no merchant_email is present

This commit is contained in:
David Remer 2020-07-02 14:37:08 +03:00
parent 45348788a3
commit 250e127afc
2 changed files with 15 additions and 3 deletions

View file

@ -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();

View file

@ -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]];
}