mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'refs/heads/trunk' into modularity-module-migration
# Conflicts: # composer.lock # modules/ppcp-axo/src/AxoModule.php # modules/ppcp-blocks/src/BlocksModule.php # modules/ppcp-compat/src/CompatModule.php # modules/ppcp-googlepay/src/GooglepayModule.php # modules/ppcp-order-tracking/src/OrderTrackingModule.php # modules/ppcp-wc-subscriptions/src/WcSubscriptionsModule.php
This commit is contained in:
commit
4d9f23e315
301 changed files with 33875 additions and 13196 deletions
|
@ -20,6 +20,9 @@ use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
|||
return array(
|
||||
'wcgateway.settings.fields' => function ( array $fields, ContainerInterface $container ): array {
|
||||
|
||||
// Used in various places to mark fields for the preview button.
|
||||
$apm_name = 'ApplePay';
|
||||
|
||||
// Eligibility check.
|
||||
if ( ! $container->has( 'applepay.eligible' ) || ! $container->get( 'applepay.eligible' ) ) {
|
||||
return $fields;
|
||||
|
@ -171,7 +174,7 @@ return array(
|
|||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
'custom_attributes' => array(
|
||||
'data-ppcp-display' => wp_json_encode(
|
||||
'data-ppcp-display' => wp_json_encode(
|
||||
array(
|
||||
$display_manager
|
||||
->rule()
|
||||
|
@ -183,10 +186,13 @@ return array(
|
|||
->action_visible( 'applepay_button_type' )
|
||||
->action_visible( 'applepay_button_language' )
|
||||
->action_visible( 'applepay_checkout_data_mode' )
|
||||
->action_visible( 'applepay_button_preview' )
|
||||
->action_class( 'applepay_button_enabled', 'active' )
|
||||
->to_array(),
|
||||
)
|
||||
),
|
||||
'data-ppcp-apm-name' => $apm_name,
|
||||
'data-ppcp-field-name' => 'is_enabled',
|
||||
),
|
||||
'classes' => array( 'ppcp-valign-label-middle', 'ppcp-align-label-center' ),
|
||||
),
|
||||
|
@ -253,56 +259,68 @@ return array(
|
|||
'requirements' => array(),
|
||||
),
|
||||
'applepay_button_type' => array(
|
||||
'title' => __( 'Button Label', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'select',
|
||||
'desc_tip' => true,
|
||||
'description' => __(
|
||||
'title' => __( 'Button Label', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'select',
|
||||
'desc_tip' => true,
|
||||
'description' => __(
|
||||
'This controls the label of the Apple Pay button.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'classes' => array( 'ppcp-field-indent' ),
|
||||
'class' => array(),
|
||||
'input_class' => array( 'wc-enhanced-select' ),
|
||||
'default' => 'pay',
|
||||
'options' => PropertiesDictionary::button_types(),
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
'classes' => array( 'ppcp-field-indent' ),
|
||||
'class' => array(),
|
||||
'input_class' => array( 'wc-enhanced-select' ),
|
||||
'default' => 'pay',
|
||||
'options' => PropertiesDictionary::button_types(),
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
'custom_attributes' => array(
|
||||
'data-ppcp-apm-name' => $apm_name,
|
||||
'data-ppcp-field-name' => 'type',
|
||||
),
|
||||
),
|
||||
'applepay_button_color' => array(
|
||||
'title' => __( 'Button Color', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'select',
|
||||
'desc_tip' => true,
|
||||
'description' => __(
|
||||
'title' => __( 'Button Color', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'select',
|
||||
'desc_tip' => true,
|
||||
'description' => __(
|
||||
'The Apple Pay Button may appear as a black button with white lettering, white button with black lettering, or a white button with black lettering and a black outline.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'label' => '',
|
||||
'input_class' => array( 'wc-enhanced-select' ),
|
||||
'classes' => array( 'ppcp-field-indent' ),
|
||||
'class' => array(),
|
||||
'default' => 'black',
|
||||
'options' => PropertiesDictionary::button_colors(),
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
'label' => '',
|
||||
'input_class' => array( 'wc-enhanced-select' ),
|
||||
'classes' => array( 'ppcp-field-indent' ),
|
||||
'class' => array(),
|
||||
'default' => 'black',
|
||||
'options' => PropertiesDictionary::button_colors(),
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
'custom_attributes' => array(
|
||||
'data-ppcp-apm-name' => $apm_name,
|
||||
'data-ppcp-field-name' => 'color',
|
||||
),
|
||||
),
|
||||
'applepay_button_language' => array(
|
||||
'title' => __( 'Button Language', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'select',
|
||||
'desc_tip' => true,
|
||||
'description' => __(
|
||||
'title' => __( 'Button Language', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'select',
|
||||
'desc_tip' => true,
|
||||
'description' => __(
|
||||
'The language and region used for the displayed Apple Pay button. The default value is the current language and region setting in a browser.',
|
||||
'woocommerce-paypal-payments'
|
||||
),
|
||||
'classes' => array( 'ppcp-field-indent' ),
|
||||
'class' => array(),
|
||||
'input_class' => array( 'wc-enhanced-select' ),
|
||||
'default' => 'en',
|
||||
'options' => PropertiesDictionary::button_languages(),
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
'classes' => array( 'ppcp-field-indent' ),
|
||||
'class' => array(),
|
||||
'input_class' => array( 'wc-enhanced-select' ),
|
||||
'default' => 'en',
|
||||
'options' => PropertiesDictionary::button_languages(),
|
||||
'screens' => array( State::STATE_ONBOARDED ),
|
||||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
'custom_attributes' => array(
|
||||
'data-ppcp-apm-name' => $apm_name,
|
||||
'data-ppcp-field-name' => 'language',
|
||||
),
|
||||
),
|
||||
'applepay_checkout_data_mode' => array(
|
||||
'title' => __( 'Send checkout billing and shipping data to Apple Pay', 'woocommerce-paypal-payments' ),
|
||||
|
@ -318,6 +336,21 @@ return array(
|
|||
'gateway' => 'dcc',
|
||||
'requirements' => array(),
|
||||
),
|
||||
'applepay_button_preview' => array(
|
||||
'type' => 'ppcp-preview',
|
||||
'preview' => array(
|
||||
'id' => 'ppcp' . $apm_name . 'ButtonPreview',
|
||||
'type' => 'button',
|
||||
'message' => __( 'Button Styling Preview', 'woocommerce-paypal-payments' ),
|
||||
'apm' => $apm_name,
|
||||
'single' => true,
|
||||
),
|
||||
'screens' => array(
|
||||
State::STATE_ONBOARDED,
|
||||
),
|
||||
'requirements' => array(),
|
||||
'gateway' => 'dcc',
|
||||
),
|
||||
)
|
||||
);
|
||||
},
|
||||
|
|
|
@ -4,23 +4,22 @@
|
|||
--apple-pay-button-min-height: 35px;
|
||||
--apple-pay-button-width: 100%;
|
||||
--apple-pay-button-max-width: 750px;
|
||||
--apple-pay-button-border-radius: 4px;
|
||||
--apple-pay-button-border-radius: var(--apm-button-border-radius);
|
||||
--apple-pay-button-overflow: hidden;
|
||||
--apple-pay-button-box-sizing: border-box;
|
||||
|
||||
.ppcp-width-min & {
|
||||
--apple-pay-button-height: 35px;
|
||||
}
|
||||
|
||||
.ppcp-width-300 & {
|
||||
--apple-pay-button-height: 45px;
|
||||
}
|
||||
|
||||
.ppcp-width-500 & {
|
||||
--apple-pay-button-height: 55px;
|
||||
}
|
||||
|
||||
&.ppcp-button-pill {
|
||||
--apple-pay-button-border-radius: 50px;
|
||||
}
|
||||
|
||||
&.ppcp-button-minicart {
|
||||
--apple-pay-button-display: block;
|
||||
}
|
||||
|
@ -46,4 +45,10 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
.ppcp-button-applepay {
|
||||
apple-pay-button {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,55 +1,52 @@
|
|||
import buttonModuleWatcher from "../../../ppcp-button/resources/js/modules/ButtonModuleWatcher";
|
||||
import ApplepayButton from "./ApplepayButton";
|
||||
import buttonModuleWatcher from '../../../ppcp-button/resources/js/modules/ButtonModuleWatcher';
|
||||
import ApplepayButton from './ApplepayButton';
|
||||
|
||||
class ApplepayManager {
|
||||
constructor( buttonConfig, ppcpConfig ) {
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
this.ApplePayConfig = null;
|
||||
this.buttons = [];
|
||||
|
||||
constructor(buttonConfig, ppcpConfig) {
|
||||
buttonModuleWatcher.watchContextBootstrap( ( bootstrap ) => {
|
||||
const button = new ApplepayButton(
|
||||
bootstrap.context,
|
||||
bootstrap.handler,
|
||||
buttonConfig,
|
||||
ppcpConfig
|
||||
);
|
||||
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
this.ApplePayConfig = null;
|
||||
this.buttons = [];
|
||||
this.buttons.push( button );
|
||||
|
||||
buttonModuleWatcher.watchContextBootstrap((bootstrap) => {
|
||||
const button = new ApplepayButton(
|
||||
bootstrap.context,
|
||||
bootstrap.handler,
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
);
|
||||
if ( this.ApplePayConfig ) {
|
||||
button.init( this.ApplePayConfig );
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
this.buttons.push(button);
|
||||
init() {
|
||||
( async () => {
|
||||
await this.config();
|
||||
for ( const button of this.buttons ) {
|
||||
button.init( this.ApplePayConfig );
|
||||
}
|
||||
} )();
|
||||
}
|
||||
|
||||
if (this.ApplePayConfig) {
|
||||
button.init(this.ApplePayConfig);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
init() {
|
||||
(async () => {
|
||||
await this.config();
|
||||
for (const button of this.buttons) {
|
||||
button.init(this.ApplePayConfig);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
reinit() {
|
||||
for (const button of this.buttons) {
|
||||
button.reinit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ApplePay configuration of the PayPal merchant.
|
||||
* @returns {Promise<null>}
|
||||
*/
|
||||
async config() {
|
||||
this.ApplePayConfig = await paypal.Applepay().config();
|
||||
return this.ApplePayConfig;
|
||||
}
|
||||
reinit() {
|
||||
for ( const button of this.buttons ) {
|
||||
button.reinit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets ApplePay configuration of the PayPal merchant.
|
||||
* @return {Promise<null>}
|
||||
*/
|
||||
async config() {
|
||||
this.ApplePayConfig = await paypal.Applepay().config();
|
||||
return this.ApplePayConfig;
|
||||
}
|
||||
}
|
||||
|
||||
export default ApplepayManager;
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import ApplepayButton from './ApplepayButton';
|
||||
|
||||
class ApplepayManagerBlockEditor {
|
||||
constructor( buttonConfig, ppcpConfig ) {
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
this.applePayConfig = null;
|
||||
}
|
||||
|
||||
init() {
|
||||
( async () => {
|
||||
await this.config();
|
||||
} )();
|
||||
}
|
||||
|
||||
async config() {
|
||||
try {
|
||||
this.applePayConfig = await paypal.Applepay().config();
|
||||
|
||||
const button = new ApplepayButton(
|
||||
this.ppcpConfig.context,
|
||||
null,
|
||||
this.buttonConfig,
|
||||
this.ppcpConfig
|
||||
);
|
||||
|
||||
button.init( this.applePayConfig );
|
||||
} catch ( error ) {
|
||||
console.error( 'Failed to initialize Apple Pay:', error );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ApplepayManagerBlockEditor;
|
|
@ -1,95 +1,80 @@
|
|||
import ErrorHandler from "../../../../ppcp-button/resources/js/modules/ErrorHandler";
|
||||
import CartActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CartActionHandler";
|
||||
import {isPayPalSubscription} from "../../../../ppcp-blocks/resources/js/Helper/Subscription";
|
||||
import ErrorHandler from '../../../../ppcp-button/resources/js/modules/ErrorHandler';
|
||||
import CartActionHandler from '../../../../ppcp-button/resources/js/modules/ActionHandler/CartActionHandler';
|
||||
|
||||
class BaseHandler {
|
||||
constructor( buttonConfig, ppcpConfig ) {
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
}
|
||||
|
||||
constructor(buttonConfig, ppcpConfig) {
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
}
|
||||
isVaultV3Mode() {
|
||||
return (
|
||||
this.ppcpConfig?.save_payment_methods?.id_token && // vault v3
|
||||
! this.ppcpConfig?.data_client_id?.paypal_subscriptions_enabled && // not PayPal Subscriptions mode
|
||||
this.ppcpConfig?.can_save_vault_token
|
||||
); // vault is enabled
|
||||
}
|
||||
|
||||
isVaultV3Mode() {
|
||||
return this.ppcpConfig?.save_payment_methods?.id_token // vault v3
|
||||
&& ! this.ppcpConfig?.data_client_id?.paypal_subscriptions_enabled // not PayPal Subscriptions mode
|
||||
&& this.ppcpConfig?.can_save_vault_token; // vault is enabled
|
||||
}
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.cart ) {
|
||||
return this.isVaultV3Mode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.cart ) {
|
||||
return this.isVaultV3Mode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
shippingAllowed() {
|
||||
return this.buttonConfig.product.needShipping;
|
||||
}
|
||||
|
||||
shippingAllowed() {
|
||||
return true;
|
||||
}
|
||||
transactionInfo() {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
const endpoint = this.ppcpConfig.ajax.cart_script_params.endpoint;
|
||||
const separator = endpoint.indexOf( '?' ) !== -1 ? '&' : '?';
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
const endpoint = this.ppcpConfig.ajax.cart_script_params.endpoint;
|
||||
const separator = (endpoint.indexOf('?') !== -1) ? '&' : '?';
|
||||
fetch( endpoint + separator + 'shipping=1', {
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
} )
|
||||
.then( ( result ) => result.json() )
|
||||
.then( ( result ) => {
|
||||
if ( ! result.success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(
|
||||
endpoint + separator + 'shipping=1',
|
||||
{
|
||||
method: 'GET',
|
||||
credentials: 'same-origin'
|
||||
}
|
||||
)
|
||||
.then(result => result.json())
|
||||
.then(result => {
|
||||
if (! result.success) {
|
||||
return;
|
||||
}
|
||||
// handle script reload
|
||||
const data = result.data;
|
||||
|
||||
// handle script reload
|
||||
const data = result.data;
|
||||
resolve( {
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
chosenShippingMethods:
|
||||
data.chosen_shipping_methods || null,
|
||||
shippingPackages: data.shipping_packages || null,
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
resolve({
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
chosenShippingMethods: data.chosen_shipping_methods || null,
|
||||
shippingPackages: data.shipping_packages || null,
|
||||
});
|
||||
createOrder() {
|
||||
return this.actionHandler().configuration().createOrder( null, null );
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
}
|
||||
approveOrder( data, actions ) {
|
||||
return this.actionHandler().configuration().onApprove( data, actions );
|
||||
}
|
||||
|
||||
createOrder() {
|
||||
return this.actionHandler().configuration().createOrder(null, null);
|
||||
}
|
||||
|
||||
approveOrder(data, actions) {
|
||||
return this.actionHandler().configuration().onApprove(data, actions);
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CartActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
);
|
||||
}
|
||||
|
||||
errorHandler() {
|
||||
return new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
}
|
||||
|
||||
errorHandler() {
|
||||
return new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
}
|
||||
actionHandler() {
|
||||
return new CartActionHandler( this.ppcpConfig, this.errorHandler() );
|
||||
}
|
||||
|
||||
errorHandler() {
|
||||
return new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector( '.woocommerce-notices-wrapper' )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default BaseHandler;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import BaseHandler from "./BaseHandler";
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class CartBlockHandler extends BaseHandler {
|
||||
|
||||
}
|
||||
class CartBlockHandler extends BaseHandler {}
|
||||
|
||||
export default CartBlockHandler;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import BaseHandler from "./BaseHandler";
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class CartHandler extends BaseHandler {
|
||||
|
||||
}
|
||||
class CartHandler extends BaseHandler {}
|
||||
|
||||
export default CartHandler;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import BaseHandler from "./BaseHandler";
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class CheckoutBlockHandler extends BaseHandler{
|
||||
|
||||
}
|
||||
class CheckoutBlockHandler extends BaseHandler {}
|
||||
|
||||
export default CheckoutBlockHandler;
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
import Spinner from "../../../../ppcp-button/resources/js/modules/Helper/Spinner";
|
||||
import CheckoutActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler";
|
||||
import BaseHandler from "./BaseHandler";
|
||||
import Spinner from '../../../../ppcp-button/resources/js/modules/Helper/Spinner';
|
||||
import CheckoutActionHandler from '../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler';
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class CheckoutHandler extends BaseHandler {
|
||||
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default CheckoutHandler;
|
||||
|
|
|
@ -1,34 +1,33 @@
|
|||
import SingleProductHandler from "./SingleProductHandler";
|
||||
import CartHandler from "./CartHandler";
|
||||
import CheckoutHandler from "./CheckoutHandler";
|
||||
import CartBlockHandler from "./CartBlockHandler";
|
||||
import CheckoutBlockHandler from "./CheckoutBlockHandler";
|
||||
import MiniCartHandler from "./MiniCartHandler";
|
||||
import PreviewHandler from "./PreviewHandler";
|
||||
import PayNowHandler from "./PayNowHandler";
|
||||
import SingleProductHandler from './SingleProductHandler';
|
||||
import CartHandler from './CartHandler';
|
||||
import CheckoutHandler from './CheckoutHandler';
|
||||
import CartBlockHandler from './CartBlockHandler';
|
||||
import CheckoutBlockHandler from './CheckoutBlockHandler';
|
||||
import MiniCartHandler from './MiniCartHandler';
|
||||
import PreviewHandler from './PreviewHandler';
|
||||
import PayNowHandler from './PayNowHandler';
|
||||
|
||||
class ContextHandlerFactory {
|
||||
|
||||
static create(context, buttonConfig, ppcpConfig) {
|
||||
switch (context) {
|
||||
case 'product':
|
||||
return new SingleProductHandler(buttonConfig, ppcpConfig);
|
||||
case 'cart':
|
||||
return new CartHandler(buttonConfig, ppcpConfig);
|
||||
case 'checkout':
|
||||
return new CheckoutHandler(buttonConfig, ppcpConfig);
|
||||
case 'pay-now':
|
||||
return new PayNowHandler(buttonConfig, ppcpConfig);
|
||||
case 'mini-cart':
|
||||
return new MiniCartHandler(buttonConfig, ppcpConfig);
|
||||
case 'cart-block':
|
||||
return new CartBlockHandler(buttonConfig, ppcpConfig);
|
||||
case 'checkout-block':
|
||||
return new CheckoutBlockHandler(buttonConfig, ppcpConfig);
|
||||
case 'preview':
|
||||
return new PreviewHandler(buttonConfig, ppcpConfig);
|
||||
}
|
||||
}
|
||||
static create( context, buttonConfig, ppcpConfig ) {
|
||||
switch ( context ) {
|
||||
case 'product':
|
||||
return new SingleProductHandler( buttonConfig, ppcpConfig );
|
||||
case 'cart':
|
||||
return new CartHandler( buttonConfig, ppcpConfig );
|
||||
case 'checkout':
|
||||
return new CheckoutHandler( buttonConfig, ppcpConfig );
|
||||
case 'pay-now':
|
||||
return new PayNowHandler( buttonConfig, ppcpConfig );
|
||||
case 'mini-cart':
|
||||
return new MiniCartHandler( buttonConfig, ppcpConfig );
|
||||
case 'cart-block':
|
||||
return new CartBlockHandler( buttonConfig, ppcpConfig );
|
||||
case 'checkout-block':
|
||||
return new CheckoutBlockHandler( buttonConfig, ppcpConfig );
|
||||
case 'preview':
|
||||
return new PreviewHandler( buttonConfig, ppcpConfig );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default ContextHandlerFactory;
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import BaseHandler from "./BaseHandler";
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class MiniCartHandler extends BaseHandler {
|
||||
|
||||
}
|
||||
class MiniCartHandler extends BaseHandler {}
|
||||
|
||||
export default MiniCartHandler;
|
||||
|
|
|
@ -1,42 +1,35 @@
|
|||
import Spinner from "../../../../ppcp-button/resources/js/modules/Helper/Spinner";
|
||||
import BaseHandler from "./BaseHandler";
|
||||
import CheckoutActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler";
|
||||
import Spinner from '../../../../ppcp-button/resources/js/modules/Helper/Spinner';
|
||||
import BaseHandler from './BaseHandler';
|
||||
import CheckoutActionHandler from '../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler';
|
||||
|
||||
class PayNowHandler extends BaseHandler {
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.payorder ) {
|
||||
return this.isVaultV3Mode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.payorder ) {
|
||||
return this.isVaultV3Mode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
transactionInfo() {
|
||||
return new Promise( async ( resolve, reject ) => {
|
||||
const data = this.ppcpConfig.pay_now;
|
||||
|
||||
shippingAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const data = this.ppcpConfig['pay_now'];
|
||||
|
||||
resolve({
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
resolve( {
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default PayNowHandler;
|
||||
|
|
|
@ -1,37 +1,35 @@
|
|||
import BaseHandler from "./BaseHandler";
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class PreviewHandler extends BaseHandler {
|
||||
constructor( buttonConfig, ppcpConfig, externalHandler ) {
|
||||
super( buttonConfig, ppcpConfig, externalHandler );
|
||||
}
|
||||
|
||||
constructor(buttonConfig, ppcpConfig, externalHandler) {
|
||||
super(buttonConfig, ppcpConfig, externalHandler);
|
||||
}
|
||||
transactionInfo() {
|
||||
// We need to return something as ApplePay button initialization expects valid data.
|
||||
return {
|
||||
countryCode: 'US',
|
||||
currencyCode: 'USD',
|
||||
totalPrice: '10.00',
|
||||
totalPriceStatus: 'FINAL',
|
||||
};
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
// We need to return something as ApplePay button initialization expects valid data.
|
||||
return {
|
||||
countryCode: "US",
|
||||
currencyCode: "USD",
|
||||
totalPrice: "10.00",
|
||||
totalPriceStatus: "FINAL"
|
||||
}
|
||||
}
|
||||
createOrder() {
|
||||
throw new Error( 'Create order fail. This is just a preview.' );
|
||||
}
|
||||
|
||||
createOrder() {
|
||||
throw new Error('Create order fail. This is just a preview.');
|
||||
}
|
||||
approveOrder( data, actions ) {
|
||||
throw new Error( 'Approve order fail. This is just a preview.' );
|
||||
}
|
||||
|
||||
approveOrder(data, actions) {
|
||||
throw new Error('Approve order fail. This is just a preview.');
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
throw new Error('Action handler fail. This is just a preview.');
|
||||
}
|
||||
|
||||
errorHandler() {
|
||||
throw new Error('Error handler fail. This is just a preview.');
|
||||
}
|
||||
actionHandler() {
|
||||
throw new Error( 'Action handler fail. This is just a preview.' );
|
||||
}
|
||||
|
||||
errorHandler() {
|
||||
throw new Error( 'Error handler fail. This is just a preview.' );
|
||||
}
|
||||
}
|
||||
|
||||
export default PreviewHandler;
|
||||
|
|
|
@ -1,83 +1,82 @@
|
|||
import SingleProductActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/SingleProductActionHandler";
|
||||
import SimulateCart from "../../../../ppcp-button/resources/js/modules/Helper/SimulateCart";
|
||||
import ErrorHandler from "../../../../ppcp-button/resources/js/modules/ErrorHandler";
|
||||
import UpdateCart from "../../../../ppcp-button/resources/js/modules/Helper/UpdateCart";
|
||||
import BaseHandler from "./BaseHandler";
|
||||
import SingleProductActionHandler from '../../../../ppcp-button/resources/js/modules/ActionHandler/SingleProductActionHandler';
|
||||
import SimulateCart from '../../../../ppcp-button/resources/js/modules/Helper/SimulateCart';
|
||||
import ErrorHandler from '../../../../ppcp-button/resources/js/modules/ErrorHandler';
|
||||
import UpdateCart from '../../../../ppcp-button/resources/js/modules/Helper/UpdateCart';
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class SingleProductHandler extends BaseHandler {
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.product ) {
|
||||
return this.isVaultV3Mode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.product ) {
|
||||
return this.isVaultV3Mode();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
transactionInfo() {
|
||||
const errorHandler = new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector( '.woocommerce-notices-wrapper' )
|
||||
);
|
||||
|
||||
transactionInfo() {
|
||||
const errorHandler = new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
function form() {
|
||||
return document.querySelector( 'form.cart' );
|
||||
}
|
||||
|
||||
function form() {
|
||||
return document.querySelector('form.cart');
|
||||
}
|
||||
const actionHandler = new SingleProductActionHandler(
|
||||
null,
|
||||
null,
|
||||
form(),
|
||||
errorHandler
|
||||
);
|
||||
|
||||
const actionHandler = new SingleProductActionHandler(
|
||||
null,
|
||||
null,
|
||||
form(),
|
||||
errorHandler,
|
||||
);
|
||||
const hasSubscriptions =
|
||||
PayPalCommerceGateway.data_client_id.has_subscriptions &&
|
||||
PayPalCommerceGateway.data_client_id.paypal_subscriptions_enabled;
|
||||
|
||||
const hasSubscriptions = PayPalCommerceGateway.data_client_id.has_subscriptions
|
||||
&& PayPalCommerceGateway.data_client_id.paypal_subscriptions_enabled;
|
||||
const products = hasSubscriptions
|
||||
? actionHandler.getSubscriptionProducts()
|
||||
: actionHandler.getProducts();
|
||||
|
||||
const products = hasSubscriptions
|
||||
? actionHandler.getSubscriptionProducts()
|
||||
: actionHandler.getProducts();
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
new SimulateCart(
|
||||
this.ppcpConfig.ajax.simulate_cart.endpoint,
|
||||
this.ppcpConfig.ajax.simulate_cart.nonce
|
||||
).simulate( ( data ) => {
|
||||
resolve( {
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
} );
|
||||
}, products );
|
||||
} );
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
(new SimulateCart(
|
||||
this.ppcpConfig.ajax.simulate_cart.endpoint,
|
||||
this.ppcpConfig.ajax.simulate_cart.nonce,
|
||||
)).simulate((data) => {
|
||||
createOrder() {
|
||||
return this.actionHandler()
|
||||
.configuration()
|
||||
.createOrder( null, null, {
|
||||
updateCartOptions: {
|
||||
keepShipping: true,
|
||||
},
|
||||
} );
|
||||
}
|
||||
|
||||
resolve({
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
actionHandler() {
|
||||
return new SingleProductActionHandler(
|
||||
this.ppcpConfig,
|
||||
new UpdateCart(
|
||||
this.ppcpConfig.ajax.change_cart.endpoint,
|
||||
this.ppcpConfig.ajax.change_cart.nonce
|
||||
),
|
||||
document.querySelector( 'form.cart' ),
|
||||
this.errorHandler()
|
||||
);
|
||||
}
|
||||
|
||||
}, products);
|
||||
});
|
||||
}
|
||||
|
||||
createOrder() {
|
||||
return this.actionHandler().configuration().createOrder(null, null, {
|
||||
'updateCartOptions': {
|
||||
'keepShipping': true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new SingleProductActionHandler(
|
||||
this.ppcpConfig,
|
||||
new UpdateCart(
|
||||
this.ppcpConfig.ajax.change_cart.endpoint,
|
||||
this.ppcpConfig.ajax.change_cart.nonce,
|
||||
),
|
||||
document.querySelector('form.cart'),
|
||||
this.errorHandler(),
|
||||
);
|
||||
}
|
||||
|
||||
products() {
|
||||
return this.actionHandler().getProducts();
|
||||
}
|
||||
products() {
|
||||
return this.actionHandler().getProducts();
|
||||
}
|
||||
}
|
||||
|
||||
export default SingleProductHandler;
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
export function createAppleErrors(errors) {
|
||||
const errorList = []
|
||||
for (const error of errors) {
|
||||
const {contactField = null, code = null, message = null} = error
|
||||
const appleError = contactField ? new ApplePayError(code, contactField, message) : new ApplePayError(code)
|
||||
errorList.push(appleError)
|
||||
}
|
||||
export function createAppleErrors( errors ) {
|
||||
const errorList = [];
|
||||
for ( const error of errors ) {
|
||||
const { contactField = null, code = null, message = null } = error;
|
||||
const appleError = contactField
|
||||
? new ApplePayError( code, contactField, message )
|
||||
: new ApplePayError( code );
|
||||
errorList.push( appleError );
|
||||
}
|
||||
|
||||
return errorList
|
||||
return errorList;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
export const buttonID = 'applepay-container';
|
||||
export const endpoints = {
|
||||
validation: '_apple_pay_validation',
|
||||
createOrderCart: '_apple_pay_create_order_cart',
|
||||
createOrderProduct: '_apple_pay_create_order_product',
|
||||
updateShippingMethod: '_apple_pay_update_shipping_contact',
|
||||
updateShippingContact: '_apple_pay_update_billing_contact',
|
||||
}
|
||||
validation: '_apple_pay_validation',
|
||||
createOrderCart: '_apple_pay_create_order_cart',
|
||||
createOrderProduct: '_apple_pay_create_order_product',
|
||||
updateShippingMethod: '_apple_pay_update_shipping_contact',
|
||||
updateShippingContact: '_apple_pay_update_billing_contact',
|
||||
};
|
||||
|
|
|
@ -1,148 +1,124 @@
|
|||
import {loadCustomScript} from "@paypal/paypal-js";
|
||||
import ApplepayButton from "./ApplepayButton";
|
||||
import widgetBuilder from "../../../ppcp-button/resources/js/modules/Renderer/WidgetBuilder";
|
||||
import ApplepayButton from './ApplepayButton';
|
||||
import PreviewButton from '../../../ppcp-button/resources/js/modules/Renderer/PreviewButton';
|
||||
import PreviewButtonManager from '../../../ppcp-button/resources/js/modules/Renderer/PreviewButtonManager';
|
||||
|
||||
(function ({
|
||||
buttonConfig,
|
||||
jQuery
|
||||
}) {
|
||||
/**
|
||||
* Accessor that creates and returns a single PreviewButtonManager instance.
|
||||
*/
|
||||
const buttonManager = () => {
|
||||
if ( ! ApplePayPreviewButtonManager.instance ) {
|
||||
ApplePayPreviewButtonManager.instance =
|
||||
new ApplePayPreviewButtonManager();
|
||||
}
|
||||
|
||||
let applePayConfig;
|
||||
let buttonQueue = [];
|
||||
let activeButtons = {};
|
||||
let bootstrapped = false;
|
||||
return ApplePayPreviewButtonManager.instance;
|
||||
};
|
||||
|
||||
// React to PayPal config changes.
|
||||
jQuery(document).on('ppcp_paypal_render_preview', (ev, ppcpConfig) => {
|
||||
if (bootstrapped) {
|
||||
createButton(ppcpConfig);
|
||||
} else {
|
||||
buttonQueue.push({
|
||||
ppcpConfig: JSON.parse(JSON.stringify(ppcpConfig))
|
||||
});
|
||||
}
|
||||
});
|
||||
/**
|
||||
* Manages all Apple Pay preview buttons on this page.
|
||||
*/
|
||||
class ApplePayPreviewButtonManager extends PreviewButtonManager {
|
||||
constructor() {
|
||||
const args = {
|
||||
methodName: 'ApplePay',
|
||||
buttonConfig: window.wc_ppcp_applepay_admin,
|
||||
};
|
||||
|
||||
// React to ApplePay config changes.
|
||||
jQuery([
|
||||
'#ppcp-applepay_button_enabled',
|
||||
'#ppcp-applepay_button_type',
|
||||
'#ppcp-applepay_button_color',
|
||||
'#ppcp-applepay_button_language'
|
||||
].join(',')).on('change', () => {
|
||||
for (const [selector, ppcpConfig] of Object.entries(activeButtons)) {
|
||||
createButton(ppcpConfig);
|
||||
}
|
||||
});
|
||||
super( args );
|
||||
}
|
||||
|
||||
// Maybe we can find a more elegant reload method when transitioning from styling modes.
|
||||
jQuery([
|
||||
'#ppcp-smart_button_enable_styling_per_location'
|
||||
].join(',')).on('change', () => {
|
||||
setTimeout(() => {
|
||||
for (const [selector, ppcpConfig] of Object.entries(activeButtons)) {
|
||||
createButton(ppcpConfig);
|
||||
}
|
||||
}, 100);
|
||||
});
|
||||
/**
|
||||
* Responsible for fetching and returning the PayPal configuration object for this payment
|
||||
* method.
|
||||
*
|
||||
* @param {{}} payPal - The PayPal SDK object provided by WidgetBuilder.
|
||||
* @return {Promise<{}>}
|
||||
*/
|
||||
async fetchConfig( payPal ) {
|
||||
const apiMethod = payPal?.Applepay()?.config;
|
||||
|
||||
const applyConfigOptions = function (buttonConfig) {
|
||||
buttonConfig.button = buttonConfig.button || {};
|
||||
buttonConfig.button.type = jQuery('#ppcp-applepay_button_type').val();
|
||||
buttonConfig.button.color = jQuery('#ppcp-applepay_button_color').val();
|
||||
buttonConfig.button.lang = jQuery('#ppcp-applepay_button_language').val();
|
||||
}
|
||||
if ( ! apiMethod ) {
|
||||
this.error(
|
||||
'configuration object cannot be retrieved from PayPal'
|
||||
);
|
||||
return {};
|
||||
}
|
||||
|
||||
const createButton = function (ppcpConfig) {
|
||||
const selector = ppcpConfig.button.wrapper + 'ApplePay';
|
||||
return await apiMethod();
|
||||
}
|
||||
|
||||
if (!jQuery('#ppcp-applepay_button_enabled').is(':checked')) {
|
||||
jQuery(selector).remove();
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* This method is responsible for creating a new PreviewButton instance and returning it.
|
||||
*
|
||||
* @param {string} wrapperId - CSS ID of the wrapper element.
|
||||
* @return {ApplePayPreviewButton}
|
||||
*/
|
||||
createButtonInstance( wrapperId ) {
|
||||
return new ApplePayPreviewButton( {
|
||||
selector: wrapperId,
|
||||
apiConfig: this.apiConfig,
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
buttonConfig = JSON.parse(JSON.stringify(buttonConfig));
|
||||
buttonConfig.button.wrapper = selector.replace('#', '');
|
||||
applyConfigOptions(buttonConfig);
|
||||
/**
|
||||
* A single Apple Pay preview button instance.
|
||||
*/
|
||||
class ApplePayPreviewButton extends PreviewButton {
|
||||
constructor( args ) {
|
||||
super( args );
|
||||
|
||||
const wrapperElement = `<div id="${selector.replace('#', '')}" class="ppcp-button-apm ppcp-button-applepay"></div>`;
|
||||
this.selector = `${ args.selector }ApplePay`;
|
||||
this.defaultAttributes = {
|
||||
button: {
|
||||
type: 'pay',
|
||||
color: 'black',
|
||||
lang: 'en',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
if (!jQuery(selector).length) {
|
||||
jQuery(ppcpConfig.button.wrapper).after(wrapperElement);
|
||||
} else {
|
||||
jQuery(selector).replaceWith(wrapperElement);
|
||||
}
|
||||
createNewWrapper() {
|
||||
const element = super.createNewWrapper();
|
||||
element.addClass( 'ppcp-button-applepay' );
|
||||
|
||||
const button = new ApplepayButton(
|
||||
'preview',
|
||||
null,
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
);
|
||||
return element;
|
||||
}
|
||||
|
||||
button.init(applePayConfig);
|
||||
createButton( buttonConfig ) {
|
||||
const button = new ApplepayButton(
|
||||
'preview',
|
||||
null,
|
||||
buttonConfig,
|
||||
this.ppcpConfig
|
||||
);
|
||||
|
||||
activeButtons[selector] = ppcpConfig;
|
||||
}
|
||||
button.init( this.apiConfig );
|
||||
}
|
||||
|
||||
const bootstrap = async function () {
|
||||
if (!widgetBuilder.paypal) {
|
||||
return;
|
||||
}
|
||||
/**
|
||||
* Merge form details into the config object for preview.
|
||||
* Mutates the previewConfig object; no return value.
|
||||
* @param buttonConfig
|
||||
* @param ppcpConfig
|
||||
*/
|
||||
dynamicPreviewConfig( buttonConfig, ppcpConfig ) {
|
||||
// The Apple Pay button expects the "wrapper" to be an ID without `#` prefix!
|
||||
buttonConfig.button.wrapper = buttonConfig.button.wrapper.replace(
|
||||
/^#/,
|
||||
''
|
||||
);
|
||||
|
||||
applePayConfig = await widgetBuilder.paypal.Applepay().config();
|
||||
// Merge the current form-values into the preview-button configuration.
|
||||
if ( ppcpConfig.button ) {
|
||||
buttonConfig.button.type = ppcpConfig.button.style.type;
|
||||
buttonConfig.button.color = ppcpConfig.button.style.color;
|
||||
buttonConfig.button.lang =
|
||||
ppcpConfig.button.style?.lang ||
|
||||
ppcpConfig.button.style.language;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We need to set bootstrapped here otherwise applePayConfig may not be set.
|
||||
bootstrapped = true;
|
||||
|
||||
let options;
|
||||
while (options = buttonQueue.pop()) {
|
||||
createButton(options.ppcpConfig);
|
||||
}
|
||||
|
||||
if (!window.ApplePaySession) {
|
||||
jQuery('body').addClass('ppcp-non-ios-device')
|
||||
}
|
||||
};
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
|
||||
if (typeof (buttonConfig) === 'undefined') {
|
||||
console.error('PayPal button could not be configured.');
|
||||
return;
|
||||
}
|
||||
|
||||
let paypalLoaded = false;
|
||||
let applePayLoaded = false;
|
||||
|
||||
const tryToBoot = () => {
|
||||
if (!bootstrapped && paypalLoaded && applePayLoaded) {
|
||||
bootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Load ApplePay SDK
|
||||
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
||||
applePayLoaded = true;
|
||||
tryToBoot();
|
||||
});
|
||||
|
||||
// Wait for PayPal to be loaded externally
|
||||
if (typeof widgetBuilder.paypal !== 'undefined') {
|
||||
paypalLoaded = true;
|
||||
tryToBoot();
|
||||
}
|
||||
|
||||
jQuery(document).on('ppcp-paypal-loaded', () => {
|
||||
paypalLoaded = true;
|
||||
tryToBoot();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
})({
|
||||
buttonConfig: window.wc_ppcp_applepay_admin,
|
||||
jQuery: window.jQuery
|
||||
});
|
||||
// Initialize the preview button manager.
|
||||
buttonManager();
|
||||
|
|
|
@ -1,72 +1,81 @@
|
|||
import {useEffect, useState} from '@wordpress/element';
|
||||
import {registerExpressPaymentMethod} from '@woocommerce/blocks-registry';
|
||||
import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading'
|
||||
import {cartHasSubscriptionProducts} from '../../../ppcp-blocks/resources/js/Helper/Subscription'
|
||||
import ApplepayManager from "./ApplepayManager";
|
||||
import {loadCustomScript} from "@paypal/paypal-js";
|
||||
import CheckoutHandler from "./Context/CheckoutHandler";
|
||||
import { useEffect, useState } from '@wordpress/element';
|
||||
import { registerExpressPaymentMethod } from '@woocommerce/blocks-registry';
|
||||
import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading';
|
||||
import { cartHasSubscriptionProducts } from '../../../ppcp-blocks/resources/js/Helper/Subscription';
|
||||
import { loadCustomScript } from '@paypal/paypal-js';
|
||||
import CheckoutHandler from './Context/CheckoutHandler';
|
||||
import ApplepayManager from './ApplepayManager';
|
||||
import ApplepayManagerBlockEditor from './ApplepayManagerBlockEditor';
|
||||
|
||||
const ppcpData = wc.wcSettings.getSetting('ppcp-gateway_data');
|
||||
const ppcpData = wc.wcSettings.getSetting( 'ppcp-gateway_data' );
|
||||
const ppcpConfig = ppcpData.scriptData;
|
||||
|
||||
const buttonData = wc.wcSettings.getSetting('ppcp-applepay_data');
|
||||
const buttonData = wc.wcSettings.getSetting( 'ppcp-applepay_data' );
|
||||
const buttonConfig = buttonData.scriptData;
|
||||
|
||||
if (typeof window.PayPalCommerceGateway === 'undefined') {
|
||||
window.PayPalCommerceGateway = ppcpConfig;
|
||||
if ( typeof window.PayPalCommerceGateway === 'undefined' ) {
|
||||
window.PayPalCommerceGateway = ppcpConfig;
|
||||
}
|
||||
|
||||
const ApplePayComponent = () => {
|
||||
const [bootstrapped, setBootstrapped] = useState(false);
|
||||
const [paypalLoaded, setPaypalLoaded] = useState(false);
|
||||
const [applePayLoaded, setApplePayLoaded] = useState(false);
|
||||
const ApplePayComponent = ( props ) => {
|
||||
const [ bootstrapped, setBootstrapped ] = useState( false );
|
||||
const [ paypalLoaded, setPaypalLoaded ] = useState( false );
|
||||
const [ applePayLoaded, setApplePayLoaded ] = useState( false );
|
||||
|
||||
const bootstrap = function () {
|
||||
const manager = new ApplepayManager(buttonConfig, ppcpConfig);
|
||||
manager.init();
|
||||
};
|
||||
const bootstrap = function () {
|
||||
const ManagerClass = props.isEditing
|
||||
? ApplepayManagerBlockEditor
|
||||
: ApplepayManager;
|
||||
const manager = new ManagerClass( buttonConfig, ppcpConfig );
|
||||
manager.init();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Load ApplePay SDK
|
||||
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
||||
setApplePayLoaded(true);
|
||||
});
|
||||
useEffect( () => {
|
||||
// Load ApplePay SDK
|
||||
loadCustomScript( { url: buttonConfig.sdk_url } ).then( () => {
|
||||
setApplePayLoaded( true );
|
||||
} );
|
||||
|
||||
// Load PayPal
|
||||
loadPaypalScript(ppcpConfig, () => {
|
||||
setPaypalLoaded(true);
|
||||
});
|
||||
}, []);
|
||||
ppcpConfig.url_params.components += ',applepay';
|
||||
|
||||
useEffect(() => {
|
||||
if (!bootstrapped && paypalLoaded && applePayLoaded) {
|
||||
setBootstrapped(true);
|
||||
bootstrap();
|
||||
}
|
||||
}, [paypalLoaded, applePayLoaded]);
|
||||
// Load PayPal
|
||||
loadPaypalScript( ppcpConfig, () => {
|
||||
setPaypalLoaded( true );
|
||||
} );
|
||||
}, [] );
|
||||
|
||||
return (
|
||||
<div id={buttonConfig.button.wrapper.replace('#', '')} className="ppcp-button-apm ppcp-button-applepay"></div>
|
||||
);
|
||||
}
|
||||
useEffect( () => {
|
||||
if ( ! bootstrapped && paypalLoaded && applePayLoaded ) {
|
||||
setBootstrapped( true );
|
||||
bootstrap();
|
||||
}
|
||||
}, [ paypalLoaded, applePayLoaded ] );
|
||||
|
||||
const features = ['products'];
|
||||
return (
|
||||
<div
|
||||
id={ buttonConfig.button.wrapper.replace( '#', '' ) }
|
||||
className="ppcp-button-apm ppcp-button-applepay"
|
||||
></div>
|
||||
);
|
||||
};
|
||||
|
||||
const features = [ 'products' ];
|
||||
|
||||
if (
|
||||
cartHasSubscriptionProducts(ppcpConfig)
|
||||
&& (new CheckoutHandler(buttonConfig, ppcpConfig)).isVaultV3Mode()
|
||||
cartHasSubscriptionProducts( ppcpConfig ) &&
|
||||
new CheckoutHandler( buttonConfig, ppcpConfig ).isVaultV3Mode()
|
||||
) {
|
||||
features.push('subscriptions');
|
||||
features.push( 'subscriptions' );
|
||||
}
|
||||
|
||||
registerExpressPaymentMethod({
|
||||
name: buttonData.id,
|
||||
label: <div dangerouslySetInnerHTML={{__html: buttonData.title}}/>,
|
||||
content: <ApplePayComponent isEditing={false}/>,
|
||||
edit: <ApplePayComponent isEditing={true}/>,
|
||||
ariaLabel: buttonData.title,
|
||||
canMakePayment: () => buttonData.enabled,
|
||||
supports: {
|
||||
features: features,
|
||||
},
|
||||
});
|
||||
registerExpressPaymentMethod( {
|
||||
name: buttonData.id,
|
||||
label: <div dangerouslySetInnerHTML={ { __html: buttonData.title } } />,
|
||||
content: <ApplePayComponent isEditing={ false } />,
|
||||
edit: <ApplePayComponent isEditing={ true } />,
|
||||
ariaLabel: buttonData.title,
|
||||
canMakePayment: () => buttonData.enabled,
|
||||
supports: {
|
||||
features,
|
||||
},
|
||||
} );
|
||||
|
|
|
@ -1,79 +1,62 @@
|
|||
import {loadCustomScript} from "@paypal/paypal-js";
|
||||
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
||||
import ApplepayManager from "./ApplepayManager";
|
||||
import { loadCustomScript } from '@paypal/paypal-js';
|
||||
import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading';
|
||||
import ApplepayManager from './ApplepayManager';
|
||||
import { setupButtonEvents } from '../../../ppcp-button/resources/js/modules/Helper/ButtonRefreshHelper';
|
||||
|
||||
(function ({
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
jQuery
|
||||
}) {
|
||||
( function ( { buttonConfig, ppcpConfig, jQuery } ) {
|
||||
let manager;
|
||||
|
||||
let manager;
|
||||
const bootstrap = function () {
|
||||
manager = new ApplepayManager( buttonConfig, ppcpConfig );
|
||||
manager.init();
|
||||
};
|
||||
|
||||
const bootstrap = function () {
|
||||
manager = new ApplepayManager(buttonConfig, ppcpConfig);
|
||||
manager.init();
|
||||
};
|
||||
setupButtonEvents( function () {
|
||||
if ( manager ) {
|
||||
manager.reinit();
|
||||
}
|
||||
} );
|
||||
|
||||
jQuery(document.body).on('updated_cart_totals updated_checkout', () => {
|
||||
if (manager) {
|
||||
manager.reinit();
|
||||
}
|
||||
});
|
||||
document.addEventListener( 'DOMContentLoaded', () => {
|
||||
if (
|
||||
typeof buttonConfig === 'undefined' ||
|
||||
typeof ppcpConfig === 'undefined'
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const isMiniCart = ppcpConfig.mini_cart_buttons_enabled;
|
||||
const isButton = jQuery( '#' + buttonConfig.button.wrapper ).length > 0;
|
||||
// If button wrapper is not present then there is no need to load the scripts.
|
||||
// minicart loads later?
|
||||
if ( ! isMiniCart && ! isButton ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use set timeout as it's unnecessary to refresh upon Minicart initial render.
|
||||
setTimeout(() => {
|
||||
jQuery(document.body).on('wc_fragments_loaded wc_fragments_refreshed', () => {
|
||||
if (manager) {
|
||||
manager.reinit();
|
||||
}
|
||||
});
|
||||
}, 1000);
|
||||
let bootstrapped = false;
|
||||
let paypalLoaded = false;
|
||||
let applePayLoaded = false;
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
if (
|
||||
(typeof (buttonConfig) === 'undefined') ||
|
||||
(typeof (ppcpConfig) === 'undefined')
|
||||
) {
|
||||
return;
|
||||
}
|
||||
const isMiniCart = ppcpConfig.mini_cart_buttons_enabled;
|
||||
const isButton = jQuery('#' + buttonConfig.button.wrapper).length > 0;
|
||||
// If button wrapper is not present then there is no need to load the scripts.
|
||||
// minicart loads later?
|
||||
if (!isMiniCart && !isButton) {
|
||||
return;
|
||||
}
|
||||
const tryToBoot = () => {
|
||||
if ( ! bootstrapped && paypalLoaded && applePayLoaded ) {
|
||||
bootstrapped = true;
|
||||
bootstrap();
|
||||
}
|
||||
};
|
||||
|
||||
let bootstrapped = false;
|
||||
let paypalLoaded = false;
|
||||
let applePayLoaded = false;
|
||||
// Load ApplePay SDK
|
||||
loadCustomScript( { url: buttonConfig.sdk_url } ).then( () => {
|
||||
applePayLoaded = true;
|
||||
tryToBoot();
|
||||
} );
|
||||
|
||||
const tryToBoot = () => {
|
||||
if (!bootstrapped && paypalLoaded && applePayLoaded) {
|
||||
bootstrapped = true;
|
||||
bootstrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Load ApplePay SDK
|
||||
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
||||
applePayLoaded = true;
|
||||
tryToBoot();
|
||||
});
|
||||
|
||||
// Load PayPal
|
||||
loadPaypalScript(ppcpConfig, () => {
|
||||
paypalLoaded = true;
|
||||
tryToBoot();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
})({
|
||||
buttonConfig: window.wc_ppcp_applepay,
|
||||
ppcpConfig: window.PayPalCommerceGateway,
|
||||
jQuery: window.jQuery
|
||||
});
|
||||
// Load PayPal
|
||||
loadPaypalScript( ppcpConfig, () => {
|
||||
paypalLoaded = true;
|
||||
tryToBoot();
|
||||
} );
|
||||
} );
|
||||
} )( {
|
||||
buttonConfig: window.wc_ppcp_applepay,
|
||||
ppcpConfig: window.PayPalCommerceGateway,
|
||||
jQuery: window.jQuery,
|
||||
} );
|
||||
|
|
|
@ -24,32 +24,33 @@ use WooCommerce\PayPalCommerce\Onboarding\State;
|
|||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
|
||||
return array(
|
||||
'applepay.eligible' => static function ( ContainerInterface $container ): bool {
|
||||
'applepay.eligible' => static function ( ContainerInterface $container ): bool {
|
||||
$apm_applies = $container->get( 'applepay.helpers.apm-applies' );
|
||||
assert( $apm_applies instanceof ApmApplies );
|
||||
|
||||
return $apm_applies->for_country_currency();
|
||||
return $apm_applies->for_country() && $apm_applies->for_currency();
|
||||
},
|
||||
'applepay.helpers.apm-applies' => static function ( ContainerInterface $container ) : ApmApplies {
|
||||
'applepay.helpers.apm-applies' => static function ( ContainerInterface $container ) : ApmApplies {
|
||||
return new ApmApplies(
|
||||
$container->get( 'applepay.supported-country-currency-matrix' ),
|
||||
$container->get( 'applepay.supported-countries' ),
|
||||
$container->get( 'applepay.supported-currencies' ),
|
||||
$container->get( 'api.shop.currency' ),
|
||||
$container->get( 'api.shop.country' )
|
||||
);
|
||||
},
|
||||
'applepay.status-cache' => static function( ContainerInterface $container ): Cache {
|
||||
'applepay.status-cache' => static function( ContainerInterface $container ): Cache {
|
||||
return new Cache( 'ppcp-paypal-apple-status-cache' );
|
||||
},
|
||||
|
||||
// We assume it's a referral if we can check product status without API request failures.
|
||||
'applepay.is_referral' => static function ( ContainerInterface $container ): bool {
|
||||
'applepay.is_referral' => static function ( ContainerInterface $container ): bool {
|
||||
$status = $container->get( 'applepay.apple-product-status' );
|
||||
assert( $status instanceof AppleProductStatus );
|
||||
|
||||
return ! $status->has_request_failure();
|
||||
},
|
||||
|
||||
'applepay.availability_notice' => static function ( ContainerInterface $container ): AvailabilityNotice {
|
||||
'applepay.availability_notice' => static function ( ContainerInterface $container ): AvailabilityNotice {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
|
||||
return new AvailabilityNotice(
|
||||
|
@ -63,17 +64,17 @@ return array(
|
|||
);
|
||||
},
|
||||
|
||||
'applepay.has_validated' => static function ( ContainerInterface $container ): bool {
|
||||
'applepay.has_validated' => static function ( ContainerInterface $container ): bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return $settings->has( 'applepay_validated' );
|
||||
},
|
||||
|
||||
'applepay.is_validated' => static function ( ContainerInterface $container ): bool {
|
||||
'applepay.is_validated' => static function ( ContainerInterface $container ): bool {
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return $settings->has( 'applepay_validated' ) ? $settings->get( 'applepay_validated' ) === true : false;
|
||||
},
|
||||
|
||||
'applepay.apple-product-status' => SingletonDecorator::make(
|
||||
'applepay.apple-product-status' => SingletonDecorator::make(
|
||||
static function( ContainerInterface $container ): AppleProductStatus {
|
||||
return new AppleProductStatus(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
|
@ -83,7 +84,7 @@ return array(
|
|||
);
|
||||
}
|
||||
),
|
||||
'applepay.available' => static function ( ContainerInterface $container ): bool {
|
||||
'applepay.available' => static function ( ContainerInterface $container ): bool {
|
||||
if ( apply_filters( 'woocommerce_paypal_payments_applepay_validate_product_status', true ) ) {
|
||||
$status = $container->get( 'applepay.apple-product-status' );
|
||||
assert( $status instanceof AppleProductStatus );
|
||||
|
@ -94,10 +95,10 @@ return array(
|
|||
}
|
||||
return true;
|
||||
},
|
||||
'applepay.server_supported' => static function ( ContainerInterface $container ): bool {
|
||||
'applepay.server_supported' => static function ( ContainerInterface $container ): bool {
|
||||
return ! empty( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] !== 'off';
|
||||
},
|
||||
'applepay.is_browser_supported' => static function ( ContainerInterface $container ): bool {
|
||||
'applepay.is_browser_supported' => static function ( ContainerInterface $container ): bool {
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$user_agent = wp_unslash( $_SERVER['HTTP_USER_AGENT'] ?? '' );
|
||||
if ( $user_agent ) {
|
||||
|
@ -127,7 +128,7 @@ return array(
|
|||
}
|
||||
return false;
|
||||
},
|
||||
'applepay.url' => static function ( ContainerInterface $container ): string {
|
||||
'applepay.url' => static function ( ContainerInterface $container ): string {
|
||||
$path = realpath( __FILE__ );
|
||||
if ( false === $path ) {
|
||||
return '';
|
||||
|
@ -137,13 +138,13 @@ return array(
|
|||
dirname( $path, 3 ) . '/woocommerce-paypal-payments.php'
|
||||
);
|
||||
},
|
||||
'applepay.sdk_script_url' => static function ( ContainerInterface $container ): string {
|
||||
'applepay.sdk_script_url' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://applepay.cdn-apple.com/jsapi/v1/apple-pay-sdk.js';
|
||||
},
|
||||
'applepay.data_to_scripts' => static function ( ContainerInterface $container ): DataToAppleButtonScripts {
|
||||
'applepay.data_to_scripts' => static function ( ContainerInterface $container ): DataToAppleButtonScripts {
|
||||
return new DataToAppleButtonScripts( $container->get( 'applepay.sdk_script_url' ), $container->get( 'wcgateway.settings' ) );
|
||||
},
|
||||
'applepay.button' => static function ( ContainerInterface $container ): ApplePayButton {
|
||||
'applepay.button' => static function ( ContainerInterface $container ): ApplePayButton {
|
||||
return new ApplePayButton(
|
||||
$container->get( 'wcgateway.settings' ),
|
||||
$container->get( 'woocommerce.logger.woocommerce' ),
|
||||
|
@ -155,7 +156,7 @@ return array(
|
|||
$container->get( 'button.helper.cart-products' )
|
||||
);
|
||||
},
|
||||
'applepay.blocks-payment-method' => static function ( ContainerInterface $container ): PaymentMethodTypeInterface {
|
||||
'applepay.blocks-payment-method' => static function ( ContainerInterface $container ): PaymentMethodTypeInterface {
|
||||
return new BlocksPaymentMethod(
|
||||
'ppcp-applepay',
|
||||
$container->get( 'applepay.url' ),
|
||||
|
@ -164,781 +165,103 @@ return array(
|
|||
$container->get( 'blocks.method' )
|
||||
);
|
||||
},
|
||||
|
||||
/**
|
||||
* The matrix which countries and currency combinations can be used for ApplePay.
|
||||
* The list of which countries can be used for ApplePay.
|
||||
*/
|
||||
'applepay.supported-country-currency-matrix' => static function ( ContainerInterface $container ) : array {
|
||||
'applepay.supported-countries' => static function ( ContainerInterface $container ) : array {
|
||||
/**
|
||||
* Returns which countries and currency combinations can be used for ApplePay.
|
||||
* Returns which countries can be used for ApplePay.
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_applepay_supported_country_currency_matrix',
|
||||
'woocommerce_paypal_payments_applepay_supported_countries',
|
||||
// phpcs:disable Squiz.Commenting.InlineComment
|
||||
array(
|
||||
'AU' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'AT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'BE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'BG' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'CA' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'CY' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'CZ' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'DK' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'EE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'FI' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'FR' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'DE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'GR' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'HU' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'IT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LV' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LI' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'LU' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'MT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NO' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'NL' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'PL' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'PT' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'RO' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'SK' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'SI' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'ES' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'SE' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'GB' => array(
|
||||
'AUD',
|
||||
'BRL',
|
||||
'CAD',
|
||||
'CHF',
|
||||
'CZK',
|
||||
'DKK',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'HKD',
|
||||
'HUF',
|
||||
'ILS',
|
||||
'JPY',
|
||||
'MXN',
|
||||
'NOK',
|
||||
'NZD',
|
||||
'PHP',
|
||||
'PLN',
|
||||
'SEK',
|
||||
'SGD',
|
||||
'THB',
|
||||
'TWD',
|
||||
'USD',
|
||||
),
|
||||
'US' => array(
|
||||
'AUD',
|
||||
'CAD',
|
||||
'EUR',
|
||||
'GBP',
|
||||
'JPY',
|
||||
'USD',
|
||||
),
|
||||
'AU', // Australia
|
||||
'AT', // Austria
|
||||
'BE', // Belgium
|
||||
'BG', // Bulgaria
|
||||
'CA', // Canada
|
||||
'CN', // China
|
||||
'CY', // Cyprus
|
||||
'CZ', // Czech Republic
|
||||
'DK', // Denmark
|
||||
'EE', // Estonia
|
||||
'FI', // Finland
|
||||
'FR', // France
|
||||
'DE', // Germany
|
||||
'GR', // Greece
|
||||
'HU', // Hungary
|
||||
'IE', // Ireland
|
||||
'IT', // Italy
|
||||
'LV', // Latvia
|
||||
'LI', // Liechtenstein
|
||||
'LT', // Lithuania
|
||||
'LU', // Luxembourg
|
||||
'MT', // Malta
|
||||
'NL', // Netherlands
|
||||
'NO', // Norway
|
||||
'PL', // Poland
|
||||
'PT', // Portugal
|
||||
'RO', // Romania
|
||||
'SK', // Slovakia
|
||||
'SI', // Slovenia
|
||||
'ES', // Spain
|
||||
'SE', // Sweden
|
||||
'US', // United States
|
||||
'GB', // United Kingdom
|
||||
)
|
||||
// phpcs:enable Squiz.Commenting.InlineComment
|
||||
);
|
||||
},
|
||||
|
||||
'applepay.enable-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
/**
|
||||
* The list of which currencies can be used for ApplePay.
|
||||
*/
|
||||
'applepay.supported-currencies' => static function ( ContainerInterface $container ) : array {
|
||||
/**
|
||||
* Returns which currencies can be used for ApplePay.
|
||||
*/
|
||||
return apply_filters(
|
||||
'woocommerce_paypal_payments_applepay_supported_currencies',
|
||||
// phpcs:disable Squiz.Commenting.InlineComment
|
||||
array(
|
||||
'AUD', // Australian Dollar
|
||||
'BRL', // Brazilian Real
|
||||
'CAD', // Canadian Dollar
|
||||
'CHF', // Swiss Franc
|
||||
'CZK', // Czech Koruna
|
||||
'DKK', // Danish Krone
|
||||
'EUR', // Euro
|
||||
'GBP', // British Pound Sterling
|
||||
'HKD', // Hong Kong Dollar
|
||||
'HUF', // Hungarian Forint
|
||||
'ILS', // Israeli New Shekel
|
||||
'JPY', // Japanese Yen
|
||||
'MXN', // Mexican Peso
|
||||
'NOK', // Norwegian Krone
|
||||
'NZD', // New Zealand Dollar
|
||||
'PHP', // Philippine Peso
|
||||
'PLN', // Polish Zloty
|
||||
'SEK', // Swedish Krona
|
||||
'SGD', // Singapore Dollar
|
||||
'THB', // Thai Baht
|
||||
'TWD', // New Taiwan Dollar
|
||||
'USD', // United States Dollar
|
||||
)
|
||||
// phpcs:enable Squiz.Commenting.InlineComment
|
||||
);
|
||||
},
|
||||
|
||||
'applepay.enable-url-sandbox' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.sandbox.paypal.com/bizsignup/add-product?product=payment_methods&capabilities=APPLE_PAY';
|
||||
},
|
||||
|
||||
'applepay.enable-url-live' => static function ( ContainerInterface $container ): string {
|
||||
'applepay.enable-url-live' => static function ( ContainerInterface $container ): string {
|
||||
return 'https://www.paypal.com/bizsignup/add-product?product=payment_methods&capabilities=APPLE_PAY';
|
||||
},
|
||||
|
||||
'applepay.settings.connection.status-text' => static function ( ContainerInterface $container ): string {
|
||||
'applepay.settings.connection.status-text' => static function ( ContainerInterface $container ): string {
|
||||
$state = $container->get( 'onboarding.state' );
|
||||
if ( $state->current_state() < State::STATE_ONBOARDED ) {
|
||||
return '';
|
||||
|
@ -964,7 +287,7 @@ return array(
|
|||
: $container->get( 'applepay.enable-url-sandbox' );
|
||||
|
||||
$button_url = $enabled
|
||||
? admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway#field-alternative_payment_methods' )
|
||||
? admin_url( 'admin.php?page=wc-settings&tab=checkout§ion=ppcp-gateway&ppcp-tab=ppcp-credit-card-gateway#ppcp-applepay_button_enabled' )
|
||||
: $enable_url;
|
||||
|
||||
return sprintf(
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -620,13 +620,18 @@ class ApplePayButton implements ButtonInterface {
|
|||
): array {
|
||||
|
||||
$shipping_methods_array = array();
|
||||
$shipping_methods = WC()->shipping->calculate_shipping(
|
||||
/**
|
||||
* The argument is defined only in docblock.
|
||||
*
|
||||
* @psalm-suppress InvalidScalarArgument
|
||||
*/
|
||||
$shipping_methods = WC()->shipping->calculate_shipping(
|
||||
$this->getShippingPackages(
|
||||
$customer_address,
|
||||
$cart->get_total( 'edit' )
|
||||
)
|
||||
);
|
||||
$done = false;
|
||||
$done = false;
|
||||
foreach ( $shipping_methods[0]['rates'] as $rate ) {
|
||||
$shipping_methods_array[] = array(
|
||||
'label' => $rate->get_label(),
|
||||
|
@ -1044,17 +1049,9 @@ class ApplePayButton implements ButtonInterface {
|
|||
}
|
||||
|
||||
/**
|
||||
* Enqueues scripts/styles for admin.
|
||||
* Enqueues scripts for admin.
|
||||
*/
|
||||
public function enqueue_admin(): void {
|
||||
wp_register_style(
|
||||
'wc-ppcp-applepay-admin',
|
||||
untrailingslashit( $this->module_url ) . '/assets/css/styles.css',
|
||||
array(),
|
||||
$this->version
|
||||
);
|
||||
wp_enqueue_style( 'wc-ppcp-applepay-admin' );
|
||||
|
||||
wp_register_script(
|
||||
'wc-ppcp-applepay-admin',
|
||||
untrailingslashit( $this->module_url ) . '/assets/js/boot-admin.js',
|
||||
|
@ -1071,6 +1068,19 @@ class ApplePayButton implements ButtonInterface {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueues styles for admin.
|
||||
*/
|
||||
public function enqueue_admin_styles(): void {
|
||||
wp_register_style(
|
||||
'wc-ppcp-applepay-admin',
|
||||
untrailingslashit( $this->module_url ) . '/assets/css/styles.css',
|
||||
array(),
|
||||
$this->version
|
||||
);
|
||||
wp_enqueue_style( 'wc-ppcp-applepay-admin' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the script data.
|
||||
*
|
||||
|
|
|
@ -103,12 +103,18 @@ class BlocksPaymentMethod extends AbstractPaymentMethodType {
|
|||
public function get_payment_method_data() {
|
||||
$paypal_data = $this->paypal_payment_method->get_payment_method_data();
|
||||
|
||||
if ( is_admin() ) {
|
||||
$script_data = $this->button->script_data_for_admin();
|
||||
} else {
|
||||
$script_data = $this->button->script_data();
|
||||
}
|
||||
|
||||
return array(
|
||||
'id' => $this->name,
|
||||
'title' => $paypal_data['title'], // TODO : see if we should use another.
|
||||
'description' => $paypal_data['description'], // TODO : see if we should use another.
|
||||
'enabled' => $paypal_data['enabled'], // This button is enabled when PayPal buttons are.
|
||||
'scriptData' => $this->button->script_data(),
|
||||
'scriptData' => $script_data,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,14 +69,13 @@ class DataToAppleButtonScripts {
|
|||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the appropriate admin data to send to ApplePay script
|
||||
*
|
||||
* @return array
|
||||
* @throws NotFoundException When the setting is not found.
|
||||
*/
|
||||
public function apple_pay_script_data_for_admin(): array {
|
||||
public function apple_pay_script_data_for_admin() : array {
|
||||
$base_location = wc_get_base_location();
|
||||
$shop_country_code = $base_location['country'];
|
||||
$currency_code = get_woocommerce_currency();
|
||||
|
@ -250,11 +249,13 @@ class DataToAppleButtonScripts {
|
|||
$lang = $this->settings->has( 'applepay_button_language' ) ? $this->settings->get( 'applepay_button_language' ) : '';
|
||||
$lang = apply_filters( 'woocommerce_paypal_payments_applepay_button_language', $lang );
|
||||
$checkout_data_mode = $this->settings->has( 'applepay_checkout_data_mode' ) ? $this->settings->get( 'applepay_checkout_data_mode' ) : PropertiesDictionary::BILLING_DATA_MODE_DEFAULT;
|
||||
$is_enabled = $this->settings->has( 'applepay_button_enabled' ) && $this->settings->get( 'applepay_button_enabled' );
|
||||
|
||||
return array(
|
||||
'sdk_url' => $this->sdk_url,
|
||||
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false,
|
||||
'is_debug' => defined( 'WP_DEBUG' ) && WP_DEBUG,
|
||||
'is_admin' => true,
|
||||
'is_enabled' => $is_enabled,
|
||||
'preferences' => array(
|
||||
'checkout_data_mode' => $checkout_data_mode,
|
||||
),
|
||||
|
|
|
@ -16,11 +16,18 @@ namespace WooCommerce\PayPalCommerce\Applepay\Helper;
|
|||
class ApmApplies {
|
||||
|
||||
/**
|
||||
* The matrix which countries and currency combinations can be used for ApplePay.
|
||||
* The list of which countries can be used for ApplePay.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $allowed_country_currency_matrix;
|
||||
private $allowed_countries;
|
||||
|
||||
/**
|
||||
* The list of which currencies can be used for ApplePay.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $allowed_currencies;
|
||||
|
||||
/**
|
||||
* 3-letter currency code of the shop.
|
||||
|
@ -37,32 +44,41 @@ class ApmApplies {
|
|||
private $country;
|
||||
|
||||
/**
|
||||
* ApmApplies constructor.
|
||||
* DccApplies constructor.
|
||||
*
|
||||
* @param array $allowed_country_currency_matrix The matrix which countries and currency combinations can be used for ApplePay.
|
||||
* @param array $allowed_countries The list of which countries can be used for ApplePay.
|
||||
* @param array $allowed_currencies The list of which currencies can be used for ApplePay.
|
||||
* @param string $currency 3-letter currency code of the shop.
|
||||
* @param string $country 2-letter country code of the shop.
|
||||
*/
|
||||
public function __construct(
|
||||
array $allowed_country_currency_matrix,
|
||||
array $allowed_countries,
|
||||
array $allowed_currencies,
|
||||
string $currency,
|
||||
string $country
|
||||
) {
|
||||
$this->allowed_country_currency_matrix = $allowed_country_currency_matrix;
|
||||
$this->currency = $currency;
|
||||
$this->country = $country;
|
||||
$this->allowed_countries = $allowed_countries;
|
||||
$this->allowed_currencies = $allowed_currencies;
|
||||
$this->currency = $currency;
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether ApplePay can be used in the current country and the current currency used.
|
||||
* Returns whether ApplePay can be used in the current country used.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function for_country_currency(): bool {
|
||||
if ( ! in_array( $this->country, array_keys( $this->allowed_country_currency_matrix ), true ) ) {
|
||||
return false;
|
||||
}
|
||||
return in_array( $this->currency, $this->allowed_country_currency_matrix[ $this->country ], true );
|
||||
public function for_country(): bool {
|
||||
return in_array( $this->country, $this->allowed_countries, true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether ApplePay can be used in the current currency used.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function for_currency(): bool {
|
||||
return in_array( $this->currency, $this->allowed_currencies, true );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue