mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Merge branch 'trunk' of github.com:woocommerce/woocommerce-paypal-payments into PCP-2645-when-selecting-google-pay-as-a-payment-option-in-safari-a-developer-error-is-displayed
This commit is contained in:
commit
6a91e422eb
142 changed files with 13592 additions and 11332 deletions
|
@ -1,79 +1,68 @@
|
|||
import ErrorHandler from "../../../../ppcp-button/resources/js/modules/ErrorHandler";
|
||||
import CartActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CartActionHandler";
|
||||
import ErrorHandler from '../../../../ppcp-button/resources/js/modules/ErrorHandler';
|
||||
import CartActionHandler from '../../../../ppcp-button/resources/js/modules/ActionHandler/CartActionHandler';
|
||||
|
||||
class BaseHandler {
|
||||
constructor( buttonConfig, ppcpConfig, externalHandler ) {
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
this.externalHandler = externalHandler;
|
||||
}
|
||||
|
||||
constructor(buttonConfig, ppcpConfig, externalHandler) {
|
||||
this.buttonConfig = buttonConfig;
|
||||
this.ppcpConfig = ppcpConfig;
|
||||
this.externalHandler = externalHandler;
|
||||
}
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.cart ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.cart ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
shippingAllowed() {
|
||||
// Status of the shipping settings in WooCommerce.
|
||||
return this.buttonConfig.shipping.configured;
|
||||
}
|
||||
|
||||
shippingAllowed() {
|
||||
// Status of the shipping settings in WooCommerce.
|
||||
return this.buttonConfig.shipping.configured;
|
||||
}
|
||||
transactionInfo() {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
fetch( this.ppcpConfig.ajax.cart_script_params.endpoint, {
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
} )
|
||||
.then( ( result ) => result.json() )
|
||||
.then( ( result ) => {
|
||||
if ( ! result.success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
// handle script reload
|
||||
const data = result.data;
|
||||
|
||||
fetch(
|
||||
this.ppcpConfig.ajax.cart_script_params.endpoint,
|
||||
{
|
||||
method: 'GET',
|
||||
credentials: 'same-origin',
|
||||
}
|
||||
)
|
||||
.then(result => result.json())
|
||||
.then(result => {
|
||||
if (! result.success) {
|
||||
return;
|
||||
}
|
||||
resolve( {
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str,
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
|
||||
// handle script reload
|
||||
const data = result.data;
|
||||
createOrder() {
|
||||
return this.actionHandler().configuration().createOrder( null, null );
|
||||
}
|
||||
|
||||
resolve({
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
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')
|
||||
);
|
||||
}
|
||||
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,15 +1,13 @@
|
|||
import BaseHandler from "./BaseHandler";
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class CartBlockHandler extends BaseHandler {
|
||||
createOrder() {
|
||||
return this.externalHandler.createOrder();
|
||||
}
|
||||
|
||||
createOrder() {
|
||||
return this.externalHandler.createOrder();
|
||||
}
|
||||
|
||||
approveOrder(data, actions) {
|
||||
return this.externalHandler.onApprove(data, actions);
|
||||
}
|
||||
|
||||
approveOrder( data, actions ) {
|
||||
return this.externalHandler.onApprove( data, actions );
|
||||
}
|
||||
}
|
||||
|
||||
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,15 +1,13 @@
|
|||
import BaseHandler from "./BaseHandler";
|
||||
import BaseHandler from './BaseHandler';
|
||||
|
||||
class CheckoutBlockHandler extends BaseHandler{
|
||||
|
||||
createOrder() {
|
||||
return this.externalHandler.createOrder();
|
||||
}
|
||||
|
||||
approveOrder(data, actions) {
|
||||
return this.externalHandler.onApprove(data, actions);
|
||||
}
|
||||
class CheckoutBlockHandler extends BaseHandler {
|
||||
createOrder() {
|
||||
return this.externalHandler.createOrder();
|
||||
}
|
||||
|
||||
approveOrder( data, actions ) {
|
||||
return this.externalHandler.onApprove( data, actions );
|
||||
}
|
||||
}
|
||||
|
||||
export default CheckoutBlockHandler;
|
||||
|
|
|
@ -1,60 +1,64 @@
|
|||
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 FormValidator from "../../../../ppcp-button/resources/js/modules/Helper/FormValidator";
|
||||
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 FormValidator from '../../../../ppcp-button/resources/js/modules/Helper/FormValidator';
|
||||
|
||||
class CheckoutHandler extends BaseHandler {
|
||||
transactionInfo() {
|
||||
return new Promise( async ( resolve, reject ) => {
|
||||
try {
|
||||
const spinner = new Spinner();
|
||||
const errorHandler = this.errorHandler();
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const formSelector =
|
||||
this.ppcpConfig.context === 'checkout'
|
||||
? 'form.checkout'
|
||||
: 'form#order_review';
|
||||
const formValidator = this.ppcpConfig
|
||||
.early_checkout_validation_enabled
|
||||
? new FormValidator(
|
||||
this.ppcpConfig.ajax.validate_checkout.endpoint,
|
||||
this.ppcpConfig.ajax.validate_checkout.nonce
|
||||
)
|
||||
: null;
|
||||
|
||||
try {
|
||||
const spinner = new Spinner();
|
||||
const errorHandler = this.errorHandler();
|
||||
if ( ! formValidator ) {
|
||||
resolve( super.transactionInfo() );
|
||||
return;
|
||||
}
|
||||
|
||||
const formSelector = this.ppcpConfig.context === 'checkout' ? 'form.checkout' : 'form#order_review';
|
||||
const formValidator = this.ppcpConfig.early_checkout_validation_enabled ?
|
||||
new FormValidator(
|
||||
this.ppcpConfig.ajax.validate_checkout.endpoint,
|
||||
this.ppcpConfig.ajax.validate_checkout.nonce,
|
||||
) : null;
|
||||
formValidator
|
||||
.validate( document.querySelector( formSelector ) )
|
||||
.then( ( errors ) => {
|
||||
if ( errors.length > 0 ) {
|
||||
spinner.unblock();
|
||||
errorHandler.clear();
|
||||
errorHandler.messages( errors );
|
||||
|
||||
if (!formValidator) {
|
||||
resolve(super.transactionInfo());
|
||||
return;
|
||||
}
|
||||
// fire WC event for other plugins
|
||||
jQuery( document.body ).trigger( 'checkout_error', [
|
||||
errorHandler.currentHtml(),
|
||||
] );
|
||||
|
||||
formValidator.validate(document.querySelector(formSelector)).then((errors) => {
|
||||
if (errors.length > 0) {
|
||||
spinner.unblock();
|
||||
errorHandler.clear();
|
||||
errorHandler.messages(errors);
|
||||
|
||||
// fire WC event for other plugins
|
||||
jQuery( document.body ).trigger( 'checkout_error' , [ errorHandler.currentHtml() ] );
|
||||
|
||||
reject();
|
||||
} else {
|
||||
resolve(super.transactionInfo());
|
||||
}
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
reject();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
reject();
|
||||
} else {
|
||||
resolve( super.transactionInfo() );
|
||||
}
|
||||
} );
|
||||
} catch ( error ) {
|
||||
console.error( error );
|
||||
reject();
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
return new CheckoutActionHandler(
|
||||
this.ppcpConfig,
|
||||
this.errorHandler(),
|
||||
new Spinner()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default CheckoutHandler;
|
||||
|
|
|
@ -1,34 +1,65 @@
|
|||
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 PayNowHandler from "./PayNowHandler";
|
||||
import PreviewHandler from "./PreviewHandler";
|
||||
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 PayNowHandler from './PayNowHandler';
|
||||
import PreviewHandler from './PreviewHandler';
|
||||
|
||||
class ContextHandlerFactory {
|
||||
|
||||
static create(context, buttonConfig, ppcpConfig, externalActionHandler) {
|
||||
switch (context) {
|
||||
case 'product':
|
||||
return new SingleProductHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'cart':
|
||||
return new CartHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'checkout':
|
||||
return new CheckoutHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'pay-now':
|
||||
return new PayNowHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'mini-cart':
|
||||
return new MiniCartHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'cart-block':
|
||||
return new CartBlockHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'checkout-block':
|
||||
return new CheckoutBlockHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
case 'preview':
|
||||
return new PreviewHandler(buttonConfig, ppcpConfig, externalActionHandler);
|
||||
}
|
||||
}
|
||||
static create( context, buttonConfig, ppcpConfig, externalActionHandler ) {
|
||||
switch ( context ) {
|
||||
case 'product':
|
||||
return new SingleProductHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
case 'cart':
|
||||
return new CartHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
case 'checkout':
|
||||
return new CheckoutHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
case 'pay-now':
|
||||
return new PayNowHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
case 'mini-cart':
|
||||
return new MiniCartHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
case 'cart-block':
|
||||
return new CartBlockHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
case 'checkout-block':
|
||||
return new CheckoutBlockHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
case 'preview':
|
||||
return new PreviewHandler(
|
||||
buttonConfig,
|
||||
ppcpConfig,
|
||||
externalActionHandler
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,38 +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 false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.payorder ) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
transactionInfo() {
|
||||
return new Promise( async ( resolve, reject ) => {
|
||||
const data = this.ppcpConfig.pay_now;
|
||||
|
||||
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,31 +1,29 @@
|
|||
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() {
|
||||
throw new Error( 'Transaction info fail. This is just a preview.' );
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
throw new Error('Transaction info fail. This is just a preview.');
|
||||
}
|
||||
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,80 +1,78 @@
|
|||
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 false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
validateContext() {
|
||||
if ( this.ppcpConfig?.locations_with_subscription_product?.product ) {
|
||||
return false;
|
||||
}
|
||||
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) => {
|
||||
|
||||
resolve({
|
||||
countryCode: data.country_code,
|
||||
currencyCode: data.currency_code,
|
||||
totalPriceStatus: 'FINAL',
|
||||
totalPrice: data.total_str
|
||||
});
|
||||
|
||||
}, 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(),
|
||||
);
|
||||
}
|
||||
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()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default SingleProductHandler;
|
||||
|
|
|
@ -247,6 +247,7 @@ class GooglepayButton {
|
|||
this.log( 'onButtonClick', this.context );
|
||||
|
||||
const paymentDataRequest = this.paymentDataRequest();
|
||||
|
||||
this.log(
|
||||
'onButtonClick: paymentDataRequest',
|
||||
paymentDataRequest,
|
||||
|
|
|
@ -1,38 +1,31 @@
|
|||
|
||||
class UpdatePaymentData {
|
||||
constructor( config ) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
constructor(config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
update(paymentData) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(
|
||||
this.config.endpoint,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
nonce: this.config.nonce,
|
||||
paymentData: paymentData,
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
.then(result => result.json())
|
||||
.then(result => {
|
||||
if (!result.success) {
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(result.data);
|
||||
});
|
||||
});
|
||||
}
|
||||
update( paymentData ) {
|
||||
return new Promise( ( resolve, reject ) => {
|
||||
fetch( this.config.endpoint, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify( {
|
||||
nonce: this.config.nonce,
|
||||
paymentData,
|
||||
} ),
|
||||
} )
|
||||
.then( ( result ) => result.json() )
|
||||
.then( ( result ) => {
|
||||
if ( ! result.success ) {
|
||||
return;
|
||||
}
|
||||
|
||||
resolve( result.data );
|
||||
} );
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
export default UpdatePaymentData;
|
||||
|
|
|
@ -102,6 +102,7 @@ class GooglePayPreviewButton extends PreviewButton {
|
|||
this.ppcpConfig,
|
||||
null
|
||||
);
|
||||
|
||||
const button = new GooglepayButton(
|
||||
'preview',
|
||||
null,
|
||||
|
|
|
@ -1,63 +1,69 @@
|
|||
import {useEffect, useState} from '@wordpress/element';
|
||||
import {registerExpressPaymentMethod, registerPaymentMethod} from '@woocommerce/blocks-registry';
|
||||
import {loadPaypalScript} from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading'
|
||||
import GooglepayManager from "./GooglepayManager";
|
||||
import {loadCustomScript} from "@paypal/paypal-js";
|
||||
import { useEffect, useState } from '@wordpress/element';
|
||||
import {
|
||||
registerExpressPaymentMethod,
|
||||
registerPaymentMethod,
|
||||
} from '@woocommerce/blocks-registry';
|
||||
import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading';
|
||||
import GooglepayManager from './GooglepayManager';
|
||||
import { loadCustomScript } from '@paypal/paypal-js';
|
||||
|
||||
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-googlepay_data');
|
||||
const buttonData = wc.wcSettings.getSetting( 'ppcp-googlepay_data' );
|
||||
const buttonConfig = buttonData.scriptData;
|
||||
|
||||
if (typeof window.PayPalCommerceGateway === 'undefined') {
|
||||
window.PayPalCommerceGateway = ppcpConfig;
|
||||
if ( typeof window.PayPalCommerceGateway === 'undefined' ) {
|
||||
window.PayPalCommerceGateway = ppcpConfig;
|
||||
}
|
||||
|
||||
const GooglePayComponent = () => {
|
||||
const [bootstrapped, setBootstrapped] = useState(false);
|
||||
const [paypalLoaded, setPaypalLoaded] = useState(false);
|
||||
const [googlePayLoaded, setGooglePayLoaded] = useState(false);
|
||||
const [ bootstrapped, setBootstrapped ] = useState( false );
|
||||
const [ paypalLoaded, setPaypalLoaded ] = useState( false );
|
||||
const [ googlePayLoaded, setGooglePayLoaded ] = useState( false );
|
||||
|
||||
const bootstrap = function () {
|
||||
const manager = new GooglepayManager(buttonConfig, ppcpConfig);
|
||||
manager.init();
|
||||
};
|
||||
const bootstrap = function () {
|
||||
const manager = new GooglepayManager( buttonConfig, ppcpConfig );
|
||||
manager.init();
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
// Load GooglePay SDK
|
||||
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
||||
setGooglePayLoaded(true);
|
||||
});
|
||||
useEffect( () => {
|
||||
// Load GooglePay SDK
|
||||
loadCustomScript( { url: buttonConfig.sdk_url } ).then( () => {
|
||||
setGooglePayLoaded( true );
|
||||
} );
|
||||
|
||||
// Load PayPal
|
||||
loadPaypalScript(ppcpConfig, () => {
|
||||
setPaypalLoaded(true);
|
||||
});
|
||||
}, []);
|
||||
// Load PayPal
|
||||
loadPaypalScript( ppcpConfig, () => {
|
||||
setPaypalLoaded( true );
|
||||
} );
|
||||
}, [] );
|
||||
|
||||
useEffect(() => {
|
||||
if (!bootstrapped && paypalLoaded && googlePayLoaded) {
|
||||
setBootstrapped(true);
|
||||
bootstrap();
|
||||
}
|
||||
}, [paypalLoaded, googlePayLoaded]);
|
||||
useEffect( () => {
|
||||
if ( ! bootstrapped && paypalLoaded && googlePayLoaded ) {
|
||||
setBootstrapped( true );
|
||||
bootstrap();
|
||||
}
|
||||
}, [ paypalLoaded, googlePayLoaded ] );
|
||||
|
||||
return (
|
||||
<div id={buttonConfig.button.wrapper.replace('#', '')} className="ppcp-button-apm ppcp-button-googlepay"></div>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<div
|
||||
id={ buttonConfig.button.wrapper.replace( '#', '' ) }
|
||||
className="ppcp-button-apm ppcp-button-googlepay"
|
||||
></div>
|
||||
);
|
||||
};
|
||||
|
||||
const features = ['products'];
|
||||
const features = [ 'products' ];
|
||||
|
||||
registerExpressPaymentMethod({
|
||||
name: buttonData.id,
|
||||
label: <div dangerouslySetInnerHTML={{__html: buttonData.title}}/>,
|
||||
content: <GooglePayComponent isEditing={false}/>,
|
||||
edit: <GooglePayComponent isEditing={true}/>,
|
||||
ariaLabel: buttonData.title,
|
||||
canMakePayment: () => buttonData.enabled,
|
||||
supports: {
|
||||
features: features,
|
||||
},
|
||||
});
|
||||
registerExpressPaymentMethod( {
|
||||
name: buttonData.id,
|
||||
label: <div dangerouslySetInnerHTML={ { __html: buttonData.title } } />,
|
||||
content: <GooglePayComponent isEditing={ false } />,
|
||||
edit: <GooglePayComponent isEditing={ true } />,
|
||||
ariaLabel: buttonData.title,
|
||||
canMakePayment: () => buttonData.enabled,
|
||||
supports: {
|
||||
features,
|
||||
},
|
||||
} );
|
||||
|
|
|
@ -1,65 +1,56 @@
|
|||
import {loadCustomScript} from "@paypal/paypal-js";
|
||||
import {loadPaypalScript} from "../../../ppcp-button/resources/js/modules/Helper/ScriptLoading";
|
||||
import GooglepayManager from "./GooglepayManager";
|
||||
import {setupButtonEvents} from '../../../ppcp-button/resources/js/modules/Helper/ButtonRefreshHelper';
|
||||
import { loadCustomScript } from '@paypal/paypal-js';
|
||||
import { loadPaypalScript } from '../../../ppcp-button/resources/js/modules/Helper/ScriptLoading';
|
||||
import GooglepayManager from './GooglepayManager';
|
||||
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 GooglepayManager( buttonConfig, ppcpConfig );
|
||||
manager.init();
|
||||
};
|
||||
|
||||
const bootstrap = function () {
|
||||
manager = new GooglepayManager(buttonConfig, ppcpConfig);
|
||||
manager.init();
|
||||
};
|
||||
setupButtonEvents( function () {
|
||||
if ( manager ) {
|
||||
manager.reinit();
|
||||
}
|
||||
} );
|
||||
|
||||
setupButtonEvents(function() {
|
||||
if (manager) {
|
||||
manager.reinit();
|
||||
}
|
||||
});
|
||||
document.addEventListener( 'DOMContentLoaded', () => {
|
||||
if (
|
||||
typeof buttonConfig === 'undefined' ||
|
||||
typeof ppcpConfig === 'undefined'
|
||||
) {
|
||||
// No PayPal buttons present on this page.
|
||||
return;
|
||||
}
|
||||
|
||||
document.addEventListener(
|
||||
'DOMContentLoaded',
|
||||
() => {
|
||||
if (
|
||||
(typeof (buttonConfig) === 'undefined') ||
|
||||
(typeof (ppcpConfig) === 'undefined')
|
||||
) {
|
||||
// No PayPal buttons present on this page.
|
||||
return;
|
||||
}
|
||||
let bootstrapped = false;
|
||||
let paypalLoaded = false;
|
||||
let googlePayLoaded = false;
|
||||
|
||||
let bootstrapped = false;
|
||||
let paypalLoaded = false;
|
||||
let googlePayLoaded = false;
|
||||
const tryToBoot = () => {
|
||||
if ( ! bootstrapped && paypalLoaded && googlePayLoaded ) {
|
||||
bootstrapped = true;
|
||||
bootstrap();
|
||||
}
|
||||
};
|
||||
|
||||
const tryToBoot = () => {
|
||||
if (!bootstrapped && paypalLoaded && googlePayLoaded) {
|
||||
bootstrapped = true;
|
||||
bootstrap();
|
||||
}
|
||||
}
|
||||
// Load GooglePay SDK
|
||||
loadCustomScript( { url: buttonConfig.sdk_url } ).then( () => {
|
||||
googlePayLoaded = true;
|
||||
tryToBoot();
|
||||
} );
|
||||
|
||||
// Load GooglePay SDK
|
||||
loadCustomScript({ url: buttonConfig.sdk_url }).then(() => {
|
||||
googlePayLoaded = true;
|
||||
tryToBoot();
|
||||
});
|
||||
|
||||
// Load PayPal
|
||||
loadPaypalScript(ppcpConfig, () => {
|
||||
paypalLoaded = true;
|
||||
tryToBoot();
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
})({
|
||||
buttonConfig: window.wc_ppcp_googlepay,
|
||||
ppcpConfig: window.PayPalCommerceGateway,
|
||||
jQuery: window.jQuery
|
||||
});
|
||||
// Load PayPal
|
||||
loadPaypalScript( ppcpConfig, () => {
|
||||
paypalLoaded = true;
|
||||
tryToBoot();
|
||||
} );
|
||||
} );
|
||||
} )( {
|
||||
buttonConfig: window.wc_ppcp_googlepay,
|
||||
ppcpConfig: window.PayPalCommerceGateway,
|
||||
jQuery: window.jQuery,
|
||||
} );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue