Refactor GooglePay contect handlers to reuse action handlers.

This commit is contained in:
Pedro Silva 2023-09-06 17:54:08 +01:00
parent 318217acb9
commit c6379ca980
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
8 changed files with 78 additions and 64 deletions

View file

@ -1,14 +1,13 @@
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 {
constructor(buttonConfig, ppcpConfig) {
constructor(buttonConfig, ppcpConfig, externalHandler) {
this.buttonConfig = buttonConfig;
this.ppcpConfig = ppcpConfig;
this.externalHandler = externalHandler;
}
transactionInfo() {
@ -42,30 +41,25 @@ 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);
}
}