mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
announce subscription support in gateway and force checkout deactivation if no support
This commit is contained in:
parent
40b3e12057
commit
68fe89af4b
6 changed files with 44 additions and 13 deletions
|
@ -16,4 +16,11 @@ class DisabledSmartButton implements SmartButtonInterface
|
|||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function canSaveVaultToken(): bool {
|
||||
return false;
|
||||
}
|
||||
public function hasSubscription(): bool {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
'<div>
|
||||
|
||||
<label for="ppcp-vault-%1$s">%2$s</label>
|
||||
|
@ -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());
|
||||
|
|
|
@ -9,4 +9,8 @@ interface SmartButtonInterface
|
|||
public function renderWrapper(): bool;
|
||||
|
||||
public function enqueue(): bool;
|
||||
|
||||
public function canSaveVaultToken(): bool;
|
||||
|
||||
public function hasSubscription(): bool;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 = __(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue