mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-04 08:47:23 +08:00
Merge branch 'trunk' into PCP-2186-apple-pay-button-preview
This commit is contained in:
commit
06087f7e67
22 changed files with 391 additions and 103 deletions
|
@ -1,8 +1,6 @@
|
|||
import ErrorHandler from "../../../../ppcp-button/resources/js/modules/ErrorHandler";
|
||||
import CartActionHandler
|
||||
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CartActionHandler";
|
||||
import onApprove
|
||||
from "../../../../ppcp-button/resources/js/modules/OnApproveHandler/onApproveForContinue";
|
||||
|
||||
class BaseHandler {
|
||||
|
||||
|
@ -11,6 +9,10 @@ class BaseHandler {
|
|||
this.ppcpConfig = ppcpConfig;
|
||||
}
|
||||
|
||||
shippingAllowed() {
|
||||
return true;
|
||||
}
|
||||
|
||||
transactionInfo() {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
|
@ -42,30 +44,32 @@ class BaseHandler {
|
|||
}
|
||||
|
||||
createOrder() {
|
||||
const errorHandler = new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
|
||||
const actionHandler = new CartActionHandler(
|
||||
this.ppcpConfig,
|
||||
errorHandler,
|
||||
);
|
||||
|
||||
return actionHandler.configuration().createOrder(null, null);
|
||||
return this.actionHandler().configuration().createOrder(null, null);
|
||||
}
|
||||
|
||||
approveOrderForContinue(data, actions) {
|
||||
const errorHandler = new ErrorHandler(
|
||||
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')
|
||||
);
|
||||
}
|
||||
|
||||
let onApproveHandler = onApprove({
|
||||
config: this.ppcpConfig
|
||||
}, errorHandler);
|
||||
|
||||
return onApproveHandler(data, actions);
|
||||
errorHandler() {
|
||||
return new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import CartBlockHandler from "./CartBlockHandler";
|
|||
import CheckoutBlockHandler from "./CheckoutBlockHandler";
|
||||
import MiniCartHandler from "./MiniCartHandler";
|
||||
import PreviewHandler from "./PreviewHandler";
|
||||
import PayNowHandler from "./PayNowHandler";
|
||||
|
||||
class ContextHandlerFactory {
|
||||
|
||||
|
@ -15,8 +16,9 @@ class ContextHandlerFactory {
|
|||
case 'cart':
|
||||
return new CartHandler(buttonConfig, ppcpConfig);
|
||||
case 'checkout':
|
||||
case 'pay-now': // same as 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':
|
||||
|
|
35
modules/ppcp-applepay/resources/js/Context/PayNowHandler.js
Normal file
35
modules/ppcp-applepay/resources/js/Context/PayNowHandler.js
Normal file
|
@ -0,0 +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";
|
||||
|
||||
class PayNowHandler extends BaseHandler {
|
||||
|
||||
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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default PayNowHandler;
|
|
@ -49,19 +49,14 @@ class SingleProductHandler extends BaseHandler {
|
|||
}
|
||||
|
||||
createOrder() {
|
||||
return this.actionHandler().configuration().createOrder();
|
||||
}
|
||||
|
||||
products() {
|
||||
return this.actionHandler().getProducts();
|
||||
return this.actionHandler().configuration().createOrder(null, null, {
|
||||
'updateCartOptions': {
|
||||
'keepShipping': true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
actionHandler() {
|
||||
const errorHandler = new ErrorHandler(
|
||||
this.ppcpConfig.labels.error.generic,
|
||||
document.querySelector('.woocommerce-notices-wrapper')
|
||||
);
|
||||
|
||||
return new SingleProductActionHandler(
|
||||
this.ppcpConfig,
|
||||
new UpdateCart(
|
||||
|
@ -69,10 +64,13 @@ class SingleProductHandler extends BaseHandler {
|
|||
this.ppcpConfig.ajax.change_cart.nonce,
|
||||
),
|
||||
document.querySelector('form.cart'),
|
||||
errorHandler,
|
||||
this.errorHandler(),
|
||||
);
|
||||
}
|
||||
|
||||
products() {
|
||||
return this.actionHandler().getProducts();
|
||||
}
|
||||
}
|
||||
|
||||
export default SingleProductHandler;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue