2023-08-28 17:19:07 +01:00
|
|
|
import Spinner from "../../../../ppcp-button/resources/js/modules/Helper/Spinner";
|
2023-09-06 17:54:08 +01:00
|
|
|
import BaseHandler from "./BaseHandler";
|
2023-08-28 17:19:07 +01:00
|
|
|
import CheckoutActionHandler
|
|
|
|
from "../../../../ppcp-button/resources/js/modules/ActionHandler/CheckoutActionHandler";
|
2023-09-07 17:56:14 +01:00
|
|
|
import FormValidator from "../../../../ppcp-button/resources/js/modules/Helper/FormValidator";
|
2023-08-28 17:19:07 +01:00
|
|
|
|
2023-08-29 14:57:10 +01:00
|
|
|
class CheckoutHandler extends BaseHandler {
|
2023-08-28 17:19:07 +01:00
|
|
|
|
2023-10-13 14:36:11 +01:00
|
|
|
shippingAllowed() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-07 17:56:14 +01:00
|
|
|
transactionInfo() {
|
|
|
|
return new Promise(async (resolve, reject) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
const spinner = new Spinner();
|
|
|
|
const errorHandler = this.errorHandler();
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if (!formValidator) {
|
|
|
|
resolve(super.transactionInfo());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-09-06 17:54:08 +01:00
|
|
|
actionHandler() {
|
|
|
|
return new CheckoutActionHandler(
|
2023-08-28 17:19:07 +01:00
|
|
|
this.ppcpConfig,
|
2023-09-06 17:54:08 +01:00
|
|
|
this.errorHandler(),
|
|
|
|
new Spinner()
|
2023-08-28 17:19:07 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export default CheckoutHandler;
|