woocommerce-paypal-payments/modules/ppcp-googlepay/resources/js/Context/BaseHandler.js

72 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-08-29 14:57:10 +01:00
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) {
2023-08-29 14:57:10 +01:00
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
this.externalHandler = externalHandler;
2023-08-29 14:57:10 +01:00
}
2023-10-13 14:36:11 +01:00
shippingAllowed() {
return true;
}
2023-08-29 14:57:10 +01:00
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;
}
// handle script reload
const data = result.data;
resolve({
countryCode: data.country_code,
currencyCode: data.currency_code,
2023-08-29 14:57:10 +01:00
totalPriceStatus: 'FINAL',
totalPrice: data.total_str
2023-08-29 14:57:10 +01:00
});
});
});
}
createOrder() {
return this.actionHandler().configuration().createOrder(null, null);
}
2023-08-29 14:57:10 +01:00
approveOrder(data, actions) {
return this.actionHandler().configuration().onApprove(data, actions);
}
actionHandler() {
return new CartActionHandler(
2023-08-29 14:57:10 +01:00
this.ppcpConfig,
this.errorHandler(),
2023-08-29 14:57:10 +01:00
);
}
errorHandler() {
return new ErrorHandler(
2023-08-29 14:57:10 +01:00
this.ppcpConfig.labels.error.generic,
document.querySelector('.woocommerce-notices-wrapper')
);
}
}
export default BaseHandler;