Do not execute current free trial flow if vault v3 enabled

This commit is contained in:
Emili Castells Guasch 2024-04-03 09:59:40 +02:00
parent 5cdb1bbce0
commit 2bf3c14feb
6 changed files with 37 additions and 9 deletions

View file

@ -137,7 +137,12 @@ const bootstrap = () => {
} }
const isFreeTrial = PayPalCommerceGateway.is_free_trial_cart; const isFreeTrial = PayPalCommerceGateway.is_free_trial_cart;
if (isFreeTrial && data.fundingSource !== 'card' && ! PayPalCommerceGateway.subscription_plan_id) { if (
isFreeTrial
&& data.fundingSource !== 'card'
&& ! PayPalCommerceGateway.subscription_plan_id
&& ! PayPalCommerceGateway.vault_v3_enabled
) {
freeTrialHandler.handle(); freeTrialHandler.handle();
return actions.reject(); return actions.reject();
} }

View file

@ -145,6 +145,7 @@ return array(
$container->get( 'button.early-wc-checkout-validation-enabled' ), $container->get( 'button.early-wc-checkout-validation-enabled' ),
$container->get( 'button.pay-now-contexts' ), $container->get( 'button.pay-now-contexts' ),
$container->get( 'wcgateway.funding-sources-without-redirect' ), $container->get( 'wcgateway.funding-sources-without-redirect' ),
$container->get('vaulting.vault-v3-enabled'),
$container->get( 'woocommerce.logger.woocommerce' ) $container->get( 'woocommerce.logger.woocommerce' )
); );
}, },

View file

@ -184,13 +184,6 @@ class SmartButton implements SmartButtonInterface {
*/ */
private $funding_sources_without_redirect; private $funding_sources_without_redirect;
/**
* The logger.
*
* @var LoggerInterface
*/
private $logger;
/** /**
* Session handler. * Session handler.
* *
@ -198,6 +191,20 @@ class SmartButton implements SmartButtonInterface {
*/ */
private $session_handler; private $session_handler;
/**
* Whether Vault v3 module is enabled.
*
* @var bool
*/
private $vault_v3_enabled;
/**
* The logger.
*
* @var LoggerInterface
*/
private $logger;
/** /**
* SmartButton constructor. * SmartButton constructor.
* *
@ -220,6 +227,7 @@ class SmartButton implements SmartButtonInterface {
* @param bool $early_validation_enabled Whether to execute WC validation of the checkout form. * @param bool $early_validation_enabled Whether to execute WC validation of the checkout form.
* @param array $pay_now_contexts The contexts that should have the Pay Now button. * @param array $pay_now_contexts The contexts that should have the Pay Now button.
* @param string[] $funding_sources_without_redirect The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back. * @param string[] $funding_sources_without_redirect The sources that do not cause issues about redirecting (on mobile, ...) and sometimes not returning back.
* @param bool $vault_v3_enabled Whether Vault v3 module is enabled.
* @param LoggerInterface $logger The logger. * @param LoggerInterface $logger The logger.
*/ */
public function __construct( public function __construct(
@ -242,6 +250,7 @@ class SmartButton implements SmartButtonInterface {
bool $early_validation_enabled, bool $early_validation_enabled,
array $pay_now_contexts, array $pay_now_contexts,
array $funding_sources_without_redirect, array $funding_sources_without_redirect,
bool $vault_v3_enabled,
LoggerInterface $logger LoggerInterface $logger
) { ) {
@ -264,6 +273,7 @@ class SmartButton implements SmartButtonInterface {
$this->early_validation_enabled = $early_validation_enabled; $this->early_validation_enabled = $early_validation_enabled;
$this->pay_now_contexts = $pay_now_contexts; $this->pay_now_contexts = $pay_now_contexts;
$this->funding_sources_without_redirect = $funding_sources_without_redirect; $this->funding_sources_without_redirect = $funding_sources_without_redirect;
$this->vault_v3_enabled = $vault_v3_enabled;
$this->logger = $logger; $this->logger = $logger;
} }
@ -1063,6 +1073,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
), ),
'cart_contains_subscription' => $this->subscription_helper->cart_contains_subscription(), 'cart_contains_subscription' => $this->subscription_helper->cart_contains_subscription(),
'subscription_plan_id' => $this->subscription_helper->paypal_subscription_id(), 'subscription_plan_id' => $this->subscription_helper->paypal_subscription_id(),
'vault_v3_enabled' => $this->vault_v3_enabled,
'variable_paypal_subscription_variations' => $this->subscription_helper->variable_paypal_subscription_variations(), 'variable_paypal_subscription_variations' => $this->subscription_helper->variable_paypal_subscription_variations(),
'subscription_product_allowed' => $this->subscription_helper->checkout_subscription_product_allowed(), 'subscription_product_allowed' => $this->subscription_helper->checkout_subscription_product_allowed(),
'locations_with_subscription_product' => $this->subscription_helper->locations_with_subscription_product(), 'locations_with_subscription_product' => $this->subscription_helper->locations_with_subscription_product(),

View file

@ -12,7 +12,7 @@ import ErrorHandler from "../../../ppcp-button/resources/js/modules/ErrorHandler
import {cardFieldStyles} from "../../../ppcp-button/resources/js/modules/Helper/CardFieldsHelper"; import {cardFieldStyles} from "../../../ppcp-button/resources/js/modules/Helper/CardFieldsHelper";
const errorHandler = new ErrorHandler( const errorHandler = new ErrorHandler(
PayPalCommerceGateway.labels.error.generic, ppcp_add_payment_method.labels.error.generic,
document.querySelector('.woocommerce-notices-wrapper') document.querySelector('.woocommerce-notices-wrapper')
); );

View file

@ -312,6 +312,14 @@ class SavePaymentMethodsModule implements ModuleInterface {
'nonce' => wp_create_nonce( SubscriptionChangePaymentMethod::nonce() ), 'nonce' => wp_create_nonce( SubscriptionChangePaymentMethod::nonce() ),
), ),
), ),
'labels' => array(
'error' => array(
'generic' => __(
'Something went wrong. Please try again or choose another payment source.',
'woocommerce-paypal-payments'
),
)
),
) )
); );
} catch ( RuntimeException $exception ) { } catch ( RuntimeException $exception ) {

View file

@ -64,4 +64,7 @@ return array(
$container->get( 'woocommerce.logger.woocommerce' ) $container->get( 'woocommerce.logger.woocommerce' )
); );
}, },
'vaulting.vault-v3-enabled' => static function( ContainerInterface $container ): bool {
return $container->has( 'save-payment-methods.eligible' ) && $container->get( 'save-payment-methods.eligible' );
},
); );