Display PayPal buttons when not logged in and subscription in the cart

This commit is contained in:
dinamiko 2021-10-22 12:49:04 +02:00
parent 8aa11ead78
commit 1782c4fe16
3 changed files with 14 additions and 12 deletions

View file

@ -117,6 +117,7 @@ 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,
@ -127,7 +128,8 @@ return array(
$settings,
$early_order_handler,
$registration_needed,
$logger
$logger,
$subscription_helper
);
},
'button.helper.early-order-handler' => static function ( ContainerInterface $container ) : EarlyOrderHandler {

View file

@ -167,10 +167,6 @@ 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();
@ -377,9 +373,6 @@ 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' ) ) {
@ -583,7 +576,7 @@ class SmartButton implements SmartButtonInterface {
return false;
}
return is_user_logged_in();
return true;
}
/**

View file

@ -23,6 +23,7 @@ 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;
@ -31,7 +32,6 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
*/
class CreateOrderEndpoint implements EndpointInterface {
const ENDPOINT = 'ppc-create-order';
/**
@ -118,6 +118,11 @@ class CreateOrderEndpoint implements EndpointInterface {
*/
protected $logger;
/**
* @var SubscriptionHelper
*/
protected $subscription_helper;
/**
* CreateOrderEndpoint constructor.
*
@ -142,7 +147,8 @@ class CreateOrderEndpoint implements EndpointInterface {
Settings $settings,
EarlyOrderHandler $early_order_handler,
bool $registration_needed,
LoggerInterface $logger
LoggerInterface $logger,
SubscriptionHelper $subscription_helper
) {
$this->request_data = $request_data;
@ -155,6 +161,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->early_order_handler = $early_order_handler;
$this->registration_needed = $registration_needed;
$this->logger = $logger;
$this->subscription_helper = $subscription_helper;
}
/**
@ -196,7 +203,7 @@ class CreateOrderEndpoint implements EndpointInterface {
$this->set_bn_code( $data );
if ( 'checkout' === $data['context'] ) {
if ( $this->registration_needed || ( isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) ) {
if ( $this->registration_needed || $this->subscription_helper->cart_contains_subscription() || ( isset( $data['createaccount'] ) && '1' === $data['createaccount'] ) ) {
$this->process_checkout_form_when_creating_account( $data['form'], $wc_order );
}