From 2bf3c14feb33b1d6fabebb0d61d75f27b62fec15 Mon Sep 17 00:00:00 2001 From: Emili Castells Guasch Date: Wed, 3 Apr 2024 09:59:40 +0200 Subject: [PATCH] Do not execute current free trial flow if vault v3 enabled --- modules/ppcp-button/resources/js/button.js | 7 +++++- modules/ppcp-button/services.php | 1 + .../ppcp-button/src/Assets/SmartButton.php | 25 +++++++++++++------ .../resources/js/add-payment-method.js | 2 +- .../src/SavePaymentMethodsModule.php | 8 ++++++ modules/ppcp-vaulting/services.php | 3 +++ 6 files changed, 37 insertions(+), 9 deletions(-) diff --git a/modules/ppcp-button/resources/js/button.js b/modules/ppcp-button/resources/js/button.js index 0f5d573ce..d0e1a8543 100644 --- a/modules/ppcp-button/resources/js/button.js +++ b/modules/ppcp-button/resources/js/button.js @@ -137,7 +137,12 @@ const bootstrap = () => { } 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(); return actions.reject(); } diff --git a/modules/ppcp-button/services.php b/modules/ppcp-button/services.php index a812dc53e..13c130c2a 100644 --- a/modules/ppcp-button/services.php +++ b/modules/ppcp-button/services.php @@ -145,6 +145,7 @@ return array( $container->get( 'button.early-wc-checkout-validation-enabled' ), $container->get( 'button.pay-now-contexts' ), $container->get( 'wcgateway.funding-sources-without-redirect' ), + $container->get('vaulting.vault-v3-enabled'), $container->get( 'woocommerce.logger.woocommerce' ) ); }, diff --git a/modules/ppcp-button/src/Assets/SmartButton.php b/modules/ppcp-button/src/Assets/SmartButton.php index c33bdcf47..e2c64ac0c 100644 --- a/modules/ppcp-button/src/Assets/SmartButton.php +++ b/modules/ppcp-button/src/Assets/SmartButton.php @@ -184,13 +184,6 @@ class SmartButton implements SmartButtonInterface { */ private $funding_sources_without_redirect; - /** - * The logger. - * - * @var LoggerInterface - */ - private $logger; - /** * Session handler. * @@ -198,6 +191,20 @@ class SmartButton implements SmartButtonInterface { */ private $session_handler; + /** + * Whether Vault v3 module is enabled. + * + * @var bool + */ + private $vault_v3_enabled; + + /** + * The logger. + * + * @var LoggerInterface + */ + private $logger; + /** * 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 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 bool $vault_v3_enabled Whether Vault v3 module is enabled. * @param LoggerInterface $logger The logger. */ public function __construct( @@ -242,6 +250,7 @@ class SmartButton implements SmartButtonInterface { bool $early_validation_enabled, array $pay_now_contexts, array $funding_sources_without_redirect, + bool $vault_v3_enabled, LoggerInterface $logger ) { @@ -264,6 +273,7 @@ class SmartButton implements SmartButtonInterface { $this->early_validation_enabled = $early_validation_enabled; $this->pay_now_contexts = $pay_now_contexts; $this->funding_sources_without_redirect = $funding_sources_without_redirect; + $this->vault_v3_enabled = $vault_v3_enabled; $this->logger = $logger; } @@ -1063,6 +1073,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages ), 'cart_contains_subscription' => $this->subscription_helper->cart_contains_subscription(), '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(), 'subscription_product_allowed' => $this->subscription_helper->checkout_subscription_product_allowed(), 'locations_with_subscription_product' => $this->subscription_helper->locations_with_subscription_product(), diff --git a/modules/ppcp-save-payment-methods/resources/js/add-payment-method.js b/modules/ppcp-save-payment-methods/resources/js/add-payment-method.js index 8aca64f7c..6178bd92c 100644 --- a/modules/ppcp-save-payment-methods/resources/js/add-payment-method.js +++ b/modules/ppcp-save-payment-methods/resources/js/add-payment-method.js @@ -12,7 +12,7 @@ import ErrorHandler from "../../../ppcp-button/resources/js/modules/ErrorHandler import {cardFieldStyles} from "../../../ppcp-button/resources/js/modules/Helper/CardFieldsHelper"; const errorHandler = new ErrorHandler( - PayPalCommerceGateway.labels.error.generic, + ppcp_add_payment_method.labels.error.generic, document.querySelector('.woocommerce-notices-wrapper') ); diff --git a/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php b/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php index 59010f6ca..f93a75a66 100644 --- a/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php +++ b/modules/ppcp-save-payment-methods/src/SavePaymentMethodsModule.php @@ -312,6 +312,14 @@ class SavePaymentMethodsModule implements ModuleInterface { '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 ) { diff --git a/modules/ppcp-vaulting/services.php b/modules/ppcp-vaulting/services.php index 7d3c5e485..45355225d 100644 --- a/modules/ppcp-vaulting/services.php +++ b/modules/ppcp-vaulting/services.php @@ -64,4 +64,7 @@ return array( $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' ); + }, );