🚧 Swap local object for official config object

This commit is contained in:
Philipp Stracker 2024-10-07 12:37:05 +02:00
parent 0a212edb89
commit 7c56d58fe4
No known key found for this signature in database

View file

@ -8,7 +8,10 @@ import FormValidator from '../../../ppcp-button/resources/js/modules/Helper/Form
import ErrorHandler from '../../../ppcp-button/resources/js/modules/ErrorHandler'; import ErrorHandler from '../../../ppcp-button/resources/js/modules/ErrorHandler';
import widgetBuilder from '../../../ppcp-button/resources/js/modules/Renderer/WidgetBuilder'; import widgetBuilder from '../../../ppcp-button/resources/js/modules/Renderer/WidgetBuilder';
import PaymentButton from '../../../ppcp-button/resources/js/modules/Renderer/PaymentButton'; import PaymentButton from '../../../ppcp-button/resources/js/modules/Renderer/PaymentButton';
import { PaymentMethods } from '../../../ppcp-button/resources/js/modules/Helper/CheckoutMethodState'; import {
PaymentContext,
PaymentMethods,
} from '../../../ppcp-button/resources/js/modules/Helper/CheckoutMethodState';
import { import {
combineStyles, combineStyles,
combineWrapperIds, combineWrapperIds,
@ -33,28 +36,6 @@ import {
* @property {string} lang - The locale; an empty string will apply the user-agent's language. * @property {string} lang - The locale; an empty string will apply the user-agent's language.
*/ */
/**
* List of valid context values that the button can have.
*
* @type {Object}
*/
const CONTEXT = {
Product: 'product',
Cart: 'cart',
Checkout: 'checkout',
PayNow: 'pay-now',
MiniCart: 'mini-cart',
BlockCart: 'cart-block',
BlockCheckout: 'checkout-block',
Preview: 'preview',
// Block editor contexts.
Blocks: [ 'cart-block', 'checkout-block' ],
// Custom gateway contexts.
Gateways: [ 'checkout', 'pay-now' ],
};
/** /**
* A payment button for Apple Pay. * A payment button for Apple Pay.
* *
@ -160,7 +141,7 @@ class ApplePayButton extends PaymentButton {
get isSeparateGateway() { get isSeparateGateway() {
return ( return (
this.buttonConfig.is_wc_gateway_enabled && this.buttonConfig.is_wc_gateway_enabled &&
CONTEXT.Gateways.includes( this.context ) PaymentContext.Gateways.includes( this.context )
); );
} }
@ -385,7 +366,7 @@ class ApplePayButton extends PaymentButton {
window.ppcpFundingSource = 'apple_pay'; window.ppcpFundingSource = 'apple_pay';
// Trigger woocommerce validation if we are in the checkout page. // Trigger woocommerce validation if we are in the checkout page.
if ( CONTEXT.Checkout === this.context ) { if ( PaymentContext.Checkout === this.context ) {
const checkoutFormSelector = 'form.woocommerce-checkout'; const checkoutFormSelector = 'form.woocommerce-checkout';
const errorHandler = new ErrorHandler( const errorHandler = new ErrorHandler(
PayPalCommerceGateway.labels.error.generic, PayPalCommerceGateway.labels.error.generic,
@ -447,7 +428,7 @@ class ApplePayButton extends PaymentButton {
return ( return (
this.contextHandler.shippingAllowed() && this.contextHandler.shippingAllowed() &&
this.buttonConfig.product.needShipping && this.buttonConfig.product.needShipping &&
( CONTEXT.Checkout !== this.context || ( PaymentContext.Checkout !== this.context ||
this.shouldUpdateButtonWithFormData() ) this.shouldUpdateButtonWithFormData() )
); );
} }
@ -458,7 +439,7 @@ class ApplePayButton extends PaymentButton {
* @return {boolean} True, when Apple Pay data should be submitted to WooCommerce. * @return {boolean} True, when Apple Pay data should be submitted to WooCommerce.
*/ */
shouldUpdateButtonWithFormData() { shouldUpdateButtonWithFormData() {
if ( CONTEXT.Checkout !== this.context ) { if ( PaymentContext.Checkout !== this.context ) {
return false; return false;
} }
return ( return (
@ -481,7 +462,7 @@ class ApplePayButton extends PaymentButton {
// Use WC form data mode in Checkout. // Use WC form data mode in Checkout.
return ( return (
CONTEXT.Checkout === this.context && PaymentContext.Checkout === this.context &&
! this.shouldUpdateButtonWithFormData() ! this.shouldUpdateButtonWithFormData()
); );
} }
@ -599,7 +580,7 @@ class ApplePayButton extends PaymentButton {
} }
refreshContextData() { refreshContextData() {
if ( CONTEXT.Product === this.context ) { if ( PaymentContext.Product === this.context ) {
// Refresh product data that makes the price change. // 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.products = this.contextHandler.products();
@ -761,7 +742,7 @@ class ApplePayButton extends PaymentButton {
this.refreshContextData(); this.refreshContextData();
switch ( this.context ) { switch ( this.context ) {
case CONTEXT.Product: case PaymentContext.Product:
return { return {
action: 'ppcp_update_shipping_contact', action: 'ppcp_update_shipping_contact',
product_id: productId, product_id: productId,
@ -773,11 +754,11 @@ class ApplePayButton extends PaymentButton {
'woocommerce-process-checkout-nonce': this.nonce, 'woocommerce-process-checkout-nonce': this.nonce,
}; };
case CONTEXT.Cart: case PaymentContext.Cart:
case CONTEXT.Checkout: case PaymentContext.Checkout:
case CONTEXT.BlockCart: case PaymentContext.BlockCart:
case CONTEXT.BlockCheckout: case PaymentContext.BlockCheckout:
case CONTEXT.MiniCart: case PaymentContext.MiniCart:
return { return {
action: 'ppcp_update_shipping_contact', action: 'ppcp_update_shipping_contact',
simplified_contact: event.shippingContact, simplified_contact: event.shippingContact,
@ -794,7 +775,7 @@ class ApplePayButton extends PaymentButton {
this.refreshContextData(); this.refreshContextData();
switch ( this.context ) { switch ( this.context ) {
case CONTEXT.Product: case PaymentContext.Product:
return { return {
action: 'ppcp_update_shipping_method', action: 'ppcp_update_shipping_method',
shipping_method: event.shippingMethod, shipping_method: event.shippingMethod,
@ -811,11 +792,11 @@ class ApplePayButton extends PaymentButton {
'woocommerce-process-checkout-nonce': this.nonce, 'woocommerce-process-checkout-nonce': this.nonce,
}; };
case CONTEXT.Cart: case PaymentContext.Cart:
case CONTEXT.Checkout: case PaymentContext.Checkout:
case CONTEXT.BlockCart: case PaymentContext.BlockCart:
case CONTEXT.BlockCheckout: case PaymentContext.BlockCheckout:
case CONTEXT.MiniCart: case PaymentContext.MiniCart:
return { return {
action: 'ppcp_update_shipping_method', action: 'ppcp_update_shipping_method',
shipping_method: event.shippingMethod, shipping_method: event.shippingMethod,