mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
78 lines
2.5 KiB
JavaScript
78 lines
2.5 KiB
JavaScript
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 {
|
|
|
|
transactionInfo() {
|
|
const errorHandler = new ErrorHandler(
|
|
this.ppcpConfig.labels.error.generic,
|
|
document.querySelector('.woocommerce-notices-wrapper')
|
|
);
|
|
|
|
function form() {
|
|
return document.querySelector('form.cart');
|
|
}
|
|
|
|
const actionHandler = new SingleProductActionHandler(
|
|
null,
|
|
null,
|
|
form(),
|
|
errorHandler,
|
|
);
|
|
|
|
const hasSubscriptions = PayPalCommerceGateway.data_client_id.has_subscriptions
|
|
&& PayPalCommerceGateway.data_client_id.paypal_subscriptions_enabled;
|
|
|
|
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);
|
|
});
|
|
}
|
|
|
|
createOrder() {
|
|
return this.actionHandler().configuration().createOrder();
|
|
}
|
|
|
|
products() {
|
|
return this.actionHandler().getProducts();
|
|
}
|
|
|
|
actionHandler() {
|
|
const errorHandler = new ErrorHandler(
|
|
this.ppcpConfig.labels.error.generic,
|
|
document.querySelector('.woocommerce-notices-wrapper')
|
|
);
|
|
|
|
return new SingleProductActionHandler(
|
|
this.ppcpConfig,
|
|
new UpdateCart(
|
|
this.ppcpConfig.ajax.change_cart.endpoint,
|
|
this.ppcpConfig.ajax.change_cart.nonce,
|
|
),
|
|
document.querySelector('form.cart'),
|
|
errorHandler,
|
|
);
|
|
}
|
|
|
|
}
|
|
|
|
export default SingleProductHandler;
|