Do not display gateways if subscription in cart and user is not logged in

This commit is contained in:
dinamiko 2021-10-25 16:27:05 +02:00
parent 1782c4fe16
commit 3c237b6315
6 changed files with 42 additions and 30 deletions

22
composer.lock generated
View file

@ -556,16 +556,16 @@
},
{
"name": "antecedent/patchwork",
"version": "2.1.15",
"version": "2.1.17",
"source": {
"type": "git",
"url": "https://github.com/antecedent/patchwork.git",
"reference": "0430ceaac7f447f1778c199ec19d7e4362a6f961"
"reference": "df5aba175a44c2996ced4edf8ec9f9081b5348c0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/antecedent/patchwork/zipball/0430ceaac7f447f1778c199ec19d7e4362a6f961",
"reference": "0430ceaac7f447f1778c199ec19d7e4362a6f961",
"url": "https://api.github.com/repos/antecedent/patchwork/zipball/df5aba175a44c2996ced4edf8ec9f9081b5348c0",
"reference": "df5aba175a44c2996ced4edf8ec9f9081b5348c0",
"shasum": ""
},
"require": {
@ -596,7 +596,7 @@
"runkit",
"testing"
],
"time": "2021-08-22T08:00:13+00:00"
"time": "2021-10-21T14:22:43+00:00"
},
{
"name": "brain/monkey",
@ -3532,16 +3532,16 @@
},
{
"name": "vimeo/psalm",
"version": "4.10.0",
"version": "4.11.1",
"source": {
"type": "git",
"url": "https://github.com/vimeo/psalm.git",
"reference": "916b098b008f6de4543892b1e0651c1c3b92cbfa"
"reference": "e33492398bd4e5e2ab60e331d445979bd83feecd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/916b098b008f6de4543892b1e0651c1c3b92cbfa",
"reference": "916b098b008f6de4543892b1e0651c1c3b92cbfa",
"url": "https://api.github.com/repos/vimeo/psalm/zipball/e33492398bd4e5e2ab60e331d445979bd83feecd",
"reference": "e33492398bd4e5e2ab60e331d445979bd83feecd",
"shasum": ""
},
"require": {
@ -3561,7 +3561,7 @@
"felixfbecker/advanced-json-rpc": "^3.0.3",
"felixfbecker/language-server-protocol": "^1.5",
"netresearch/jsonmapper": "^1.0 || ^2.0 || ^3.0 || ^4.0",
"nikic/php-parser": "^4.12",
"nikic/php-parser": "^4.13",
"openlss/lib-array2xml": "^1.0",
"php": "^7.1|^8",
"sebastian/diff": "^3.0 || ^4.0",
@ -3629,7 +3629,7 @@
"inspection",
"php"
],
"time": "2021-09-04T21:00:09+00:00"
"time": "2021-10-24T12:29:22+00:00"
},
{
"name": "webmozart/assert",

View file

@ -117,7 +117,6 @@ return array(
$early_order_handler = $container->get( 'button.helper.early-order-handler' );
$registration_needed = $container->get( 'button.current-user-must-register' );
$logger = $container->get( 'woocommerce.logger.woocommerce' );
$subscription_helper = $container->get( 'subscription.helper' );
return new CreateOrderEndpoint(
$request_data,
$cart_repository,
@ -128,8 +127,7 @@ return array(
$settings,
$early_order_handler,
$registration_needed,
$logger,
$subscription_helper
$logger
);
},
'button.helper.early-order-handler' => static function ( ContainerInterface $container ) : EarlyOrderHandler {

View file

@ -167,6 +167,10 @@ class SmartButton implements SmartButtonInterface {
*/
public function render_wrapper(): bool {
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
return false;
}
if ( $this->settings->has( 'enabled' ) && $this->settings->get( 'enabled' ) ) {
$this->render_button_wrapper_registrar();
$this->render_message_wrapper_registrar();
@ -373,6 +377,9 @@ class SmartButton implements SmartButtonInterface {
if ( ! is_checkout() && ! $buttons_enabled ) {
return false;
}
if ( ! $this->can_save_vault_token() && $this->has_subscriptions() ) {
return false;
}
$load_script = false;
if ( is_checkout() && $this->settings->has( 'dcc_enabled' ) && $this->settings->get( 'dcc_enabled' ) ) {
@ -576,7 +583,7 @@ class SmartButton implements SmartButtonInterface {
return false;
}
return true;
return is_user_logged_in();
}
/**

View file

@ -23,7 +23,6 @@ use WooCommerce\PayPalCommerce\ApiClient\Factory\PurchaseUnitFactory;
use WooCommerce\PayPalCommerce\ApiClient\Repository\CartRepository;
use WooCommerce\PayPalCommerce\Button\Helper\EarlyOrderHandler;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
@ -118,11 +117,6 @@ class CreateOrderEndpoint implements EndpointInterface {
*/
protected $logger;
/**
* @var SubscriptionHelper
*/
protected $subscription_helper;
/**
* CreateOrderEndpoint constructor.
*
@ -147,8 +141,7 @@ class CreateOrderEndpoint implements EndpointInterface {
Settings $settings,
EarlyOrderHandler $early_order_handler,
bool $registration_needed,
LoggerInterface $logger,
SubscriptionHelper $subscription_helper
LoggerInterface $logger
) {
$this->request_data = $request_data;
@ -161,7 +154,6 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->early_order_handler = $early_order_handler;
$this->registration_needed = $registration_needed;
$this->logger = $logger;
$this->subscription_helper = $subscription_helper;
}
/**
@ -203,7 +195,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->set_bn_code( $data );
if ( 'checkout' === $data['context'] ) {
if ( $this->registration_needed || $this->subscription_helper->cart_contains_subscription() || ( isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) ) {
if ( $this->registration_needed || ( isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) ) {
$this->process_checkout_form_when_creating_account( $data['form'], $wc_order );
}

View file

@ -117,7 +117,8 @@ return array(
'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
$session_handler = $container->get( 'session.handler' );
$settings = $container->get( 'wcgateway.settings' );
return new DisableGateways( $session_handler, $settings );
$subscription_helper = $container->get( 'subscription.helper' );
return new DisableGateways( $session_handler, $settings, $subscription_helper );
},
'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : '';

View file

@ -10,6 +10,7 @@ declare(strict_types=1);
namespace WooCommerce\PayPalCommerce\WcGateway\Checkout;
use WooCommerce\PayPalCommerce\Session\SessionHandler;
use WooCommerce\PayPalCommerce\Subscription\Helper\SubscriptionHelper;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use Psr\Container\ContainerInterface;
@ -19,7 +20,6 @@ use Psr\Container\ContainerInterface;
*/
class DisableGateways {
/**
* The Session Handler.
*
@ -34,19 +34,29 @@ class DisableGateways {
*/
private $settings;
/**
* The subscription helper
*
* @var SubscriptionHelper
*/
private $subscription_helper;
/**
* DisableGateways constructor.
*
* @param SessionHandler $session_handler The Session Handler.
* @param ContainerInterface $settings The Settings.
* @param SubscriptionHelper $subscription_helper The subscription helper.
*/
public function __construct(
SessionHandler $session_handler,
ContainerInterface $settings
ContainerInterface $settings,
SubscriptionHelper $subscription_helper
) {
$this->session_handler = $session_handler;
$this->settings = $settings;
$this->subscription_helper = $subscription_helper;
}
/**
@ -100,6 +110,10 @@ class DisableGateways {
return true;
}
if ( $this->subscription_helper->cart_contains_subscription() && ! is_user_logged_in() ) {
return true;
}
return false;
}