announce subscription support in gateway and force checkout deactivation if no support

This commit is contained in:
David Remer 2020-07-23 16:01:02 +03:00
parent 40b3e12057
commit 68fe89af4b
6 changed files with 44 additions and 13 deletions

View file

@ -28,18 +28,23 @@ return [
$notice = $container->get('wcgateway.notice.authorize-order-action');
$settings = $container->get('wcgateway.settings');
$smartButton = $container->get('button.smart-button');
$supportsSubscription = $smartButton->canSaveVaultToken();
return new WcGateway(
$settingsRenderer,
$orderProcessor,
$authorizedPayments,
$notice,
$settings
$settings,
$supportsSubscription
);
},
'wcgateway.disabler' => static function (ContainerInterface $container): DisableGateways {
$sessionHandler = $container->get('session.handler');
$settings = $container->get('wcgateway.settings');
return new DisableGateways($sessionHandler, $settings);
$smartButton = $container->get('button.smart-button');
$subscriptionDisable = ! $smartButton->canSaveVaultToken() && $smartButton->hasSubscription();
return new DisableGateways($sessionHandler, $settings, $subscriptionDisable);
},
'wcgateway.settings' => static function (ContainerInterface $container): Settings {
return new Settings();

View file

@ -13,13 +13,16 @@ class DisableGateways
private $sessionHandler;
private $settings;
private $subscriptionDisable;
public function __construct(
SessionHandler $sessionHandler,
ContainerInterface $settings
ContainerInterface $settings,
bool $subscriptionDisable
) {
$this->sessionHandler = $sessionHandler;
$this->settings = $settings;
$this->subscriptionDisable = $subscriptionDisable;
}
public function handler(array $methods): array
@ -34,6 +37,12 @@ class DisableGateways
unset($methods[WcGateway::ID]);
return $methods;
}
if ($this->subscriptionDisable) {
unset($methods[WcGateway::ID]);
return $methods;
}
if (! $this->needsToDisableGateways()) {
return $methods;
}

View file

@ -10,6 +10,7 @@ use Inpsyde\PayPalCommerce\ApiClient\Entity\Order;
use Inpsyde\PayPalCommerce\ApiClient\Entity\OrderStatus;
use Inpsyde\PayPalCommerce\ApiClient\Factory\OrderFactory;
use Inpsyde\PayPalCommerce\ApiClient\Repository\CartRepository;
use Inpsyde\PayPalCommerce\Button\Assets\SmartButton;
use Inpsyde\PayPalCommerce\Onboarding\Render\OnboardingRenderer;
use Inpsyde\PayPalCommerce\Session\SessionHandler;
use Inpsyde\PayPalCommerce\WcGateway\Notice\AuthorizeOrderActionNotice;
@ -40,7 +41,8 @@ class WcGateway extends \WC_Payment_Gateway
OrderProcessor $orderProcessor,
AuthorizedPaymentsProcessor $authorizedPayments,
AuthorizeOrderActionNotice $notice,
ContainerInterface $config
ContainerInterface $config,
bool $supportsSubscription
) {
$this->id = self::ID;
@ -49,6 +51,9 @@ class WcGateway extends \WC_Payment_Gateway
$this->notice = $notice;
$this->settingsRenderer = $settingsRenderer;
$this->config = $config;
if ($supportsSubscription) {
$this->supports = array('subscriptions', 'products');
}
$this->method_title = __('PayPal Payments', 'woocommerce-paypal-commerce-gateway');
$this->method_description = __(