Merge pull request #1835 from woocommerce/PCP-2217-hide-apple-pay-google-pay-for-subscription-type-products

Hide Apple Pay & Google Pay for subscription type products (2217)
This commit is contained in:
Emili Castells 2023-11-15 12:02:24 +01:00 committed by GitHub
commit 4fb9e50a91
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 1 deletions

View file

@ -42,6 +42,10 @@ class ApplepayButton {
return;
}
if (!this.contextHandler.validateContext()) {
return;
}
this.log('Init', this.context);
this.initEventHandlers();
this.isInitialized = true;
@ -263,7 +267,7 @@ class ApplepayButton {
switch (this.context) {
case 'product':
// Refresh product data that makes the price change.
this.productQuantity = document.querySelector('input.qty').value;
this.productQuantity = document.querySelector('input.qty')?.value;
this.products = this.contextHandler.products();
this.log('Products updated', this.products);
break;

View file

@ -9,6 +9,13 @@ class BaseHandler {
this.ppcpConfig = ppcpConfig;
}
validateContext() {
if ( this.ppcpConfig?.locations_with_subscription_product?.cart ) {
return false;
}
return true;
}
shippingAllowed() {
return true;
}

View file

@ -5,6 +5,13 @@ import CheckoutActionHandler
class PayNowHandler extends BaseHandler {
validateContext() {
if ( this.ppcpConfig?.locations_with_subscription_product?.payorder ) {
return false;
}
return true;
}
shippingAllowed() {
return false;
}

View file

@ -7,6 +7,13 @@ import BaseHandler from "./BaseHandler";
class SingleProductHandler extends BaseHandler {
validateContext() {
if ( this.ppcpConfig?.locations_with_subscription_product?.product ) {
return false;
}
return true;
}
transactionInfo() {
const errorHandler = new ErrorHandler(
this.ppcpConfig.labels.error.generic,

View file

@ -973,6 +973,7 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
'subscription_plan_id' => $this->subscription_helper->paypal_subscription_id(),
'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(),
'enforce_vault' => $this->has_subscriptions(),
'can_save_vault_token' => $this->can_save_vault_token(),
'is_free_trial_cart' => $is_free_trial_cart,

View file

@ -10,6 +10,13 @@ class BaseHandler {
this.externalHandler = externalHandler;
}
validateContext() {
if ( this.ppcpConfig?.locations_with_subscription_product?.cart ) {
return false;
}
return true;
}
shippingAllowed() {
return true;
}

View file

@ -5,6 +5,13 @@ import CheckoutActionHandler
class PayNowHandler extends BaseHandler {
validateContext() {
if ( this.ppcpConfig?.locations_with_subscription_product?.payorder ) {
return false;
}
return true;
}
shippingAllowed() {
return false;
}

View file

@ -7,6 +7,13 @@ import BaseHandler from "./BaseHandler";
class SingleProductHandler extends BaseHandler {
validateContext() {
if ( this.ppcpConfig?.locations_with_subscription_product?.product ) {
return false;
}
return true;
}
transactionInfo() {
const errorHandler = new ErrorHandler(
this.ppcpConfig.labels.error.generic,

View file

@ -40,6 +40,10 @@ class GooglepayButton {
return;
}
if (!this.contextHandler.validateContext()) {
return;
}
this.googlePayConfig = config;
this.allowedPaymentMethods = config.allowedPaymentMethods;
this.baseCardPaymentMethod = this.allowedPaymentMethods[0];

View file

@ -271,4 +271,17 @@ class SubscriptionHelper {
return true;
}
/**
* Returns the locations on the page which have subscription products.
*
* @return array
*/
public function locations_with_subscription_product(): array {
return array(
'product' => is_product() && $this->current_product_is_subscription(),
'payorder' => is_wc_endpoint_url( 'order-pay' ) && $this->order_pay_contains_subscription(),
'cart' => $this->cart_contains_subscription(),
);
}
}