diff --git a/modules.local/ppcp-button/src/Assets/DisabledSmartButton.php b/modules.local/ppcp-button/src/Assets/DisabledSmartButton.php
index a4331b3ef..94d3483e2 100644
--- a/modules.local/ppcp-button/src/Assets/DisabledSmartButton.php
+++ b/modules.local/ppcp-button/src/Assets/DisabledSmartButton.php
@@ -16,4 +16,11 @@ class DisabledSmartButton implements SmartButtonInterface
{
return true;
}
+
+ public function canSaveVaultToken(): bool {
+ return false;
+ }
+ public function hasSubscription(): bool {
+ return false;
+ }
}
diff --git a/modules.local/ppcp-button/src/Assets/SmartButton.php b/modules.local/ppcp-button/src/Assets/SmartButton.php
index 39779f20f..b3b2602a6 100644
--- a/modules.local/ppcp-button/src/Assets/SmartButton.php
+++ b/modules.local/ppcp-button/src/Assets/SmartButton.php
@@ -60,7 +60,7 @@ class SmartButton implements SmartButtonInterface
public function renderWrapper(): bool
{
- if (! $this->saveVaultToken() && $this->hasSubscription()) {
+ if (! $this->canSaveVaultToken() && $this->hasSubscription()) {
return false;
}
$buttonRenderer = static function () {
@@ -116,10 +116,11 @@ class SmartButton implements SmartButtonInterface
31
);
}
+ $dccNotEnabledOnProductPage = $this->settings->has('dcc_single_product_enabled') &&
+ !$this->settings->get('dcc_single_product_enabled');
if (
(is_product() || wc_post_content_has_shortcode('product_page'))
- && $this->settings->has('dcc_single_product_enabled')
- && $this->settings->get('dcc_single_product_enabled')
+ && ! $dccNotEnabledOnProductPage
) {
add_action(
'woocommerce_single_product_summary',
@@ -181,7 +182,7 @@ class SmartButton implements SmartButtonInterface
public function enqueue(): bool
{
- if (! $this->saveVaultToken() && $this->hasSubscription()) {
+ if (! $this->canSaveVaultToken() && $this->hasSubscription()) {
return false;
}
wp_enqueue_style(
@@ -228,7 +229,7 @@ class SmartButton implements SmartButtonInterface
) {
return;
}
- $saveCard = $this->saveVaultToken() ? sprintf(
+ $saveCard = $this->canSaveVaultToken() ? sprintf(
'
@@ -271,7 +272,7 @@ class SmartButton implements SmartButtonInterface
}
// phpcs:enable Inpsyde.CodeQuality.FunctionLength.TooLong
- private function saveVaultToken(): bool
+ public function canSaveVaultToken(): bool
{
if (! $this->settings->has('client_id') || ! $this->settings->get('client_id')) {
@@ -283,7 +284,7 @@ class SmartButton implements SmartButtonInterface
return is_user_logged_in();
}
- private function hasSubscription(): bool
+ public function hasSubscription(): bool
{
if (is_product()) {
@@ -388,7 +389,7 @@ class SmartButton implements SmartButtonInterface
//ToDo: Update date on releases.
'integration-date' => date('Y-m-d'),
'components' => implode(',', $this->components()),
- 'vault' => $this->dccIsEnabled() || $this->saveVaultToken() ? 'true' : 'false',
+ 'vault' => $this->dccIsEnabled() || $this->canSaveVaultToken() ? 'true' : 'false',
'commit' => is_checkout() ? 'true' : 'false',
'intent' => ($this->settings->has('intent')) ? $this->settings->get('intent') : 'capture',
];
@@ -416,7 +417,7 @@ class SmartButton implements SmartButtonInterface
if (!is_user_logged_in()) {
return $attributes;
}
- if (! $this->dccIsEnabled() && ! $this->saveVaultToken()) {
+ if (! $this->dccIsEnabled() && ! $this->canSaveVaultToken()) {
return $attributes;
}
$clientToken = $this->identityToken->generateForCustomer((int) get_current_user_id());
diff --git a/modules.local/ppcp-button/src/Assets/SmartButtonInterface.php b/modules.local/ppcp-button/src/Assets/SmartButtonInterface.php
index 90e5c581d..53cdf2345 100644
--- a/modules.local/ppcp-button/src/Assets/SmartButtonInterface.php
+++ b/modules.local/ppcp-button/src/Assets/SmartButtonInterface.php
@@ -9,4 +9,8 @@ interface SmartButtonInterface
public function renderWrapper(): bool;
public function enqueue(): bool;
+
+ public function canSaveVaultToken(): bool;
+
+ public function hasSubscription(): bool;
}
diff --git a/modules.local/ppcp-wc-gateway/services.php b/modules.local/ppcp-wc-gateway/services.php
index 696a96733..0dbe38e53 100644
--- a/modules.local/ppcp-wc-gateway/services.php
+++ b/modules.local/ppcp-wc-gateway/services.php
@@ -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();
diff --git a/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php b/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php
index d5b328a98..eebe62f00 100644
--- a/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php
+++ b/modules.local/ppcp-wc-gateway/src/Checkout/DisableGateways.php
@@ -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;
}
diff --git a/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php b/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php
index 87714e04d..2dfa83b34 100644
--- a/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php
+++ b/modules.local/ppcp-wc-gateway/src/Gateway/WcGateway.php
@@ -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 = __(