1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-22 09:21:34 +02:00
invoiceninja/resources/js/clients/invoices/payment.js

112 lines
3.4 KiB
JavaScript
Raw Normal View History

2020-03-23 18:10:42 +01:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2020-03-23 18:10:42 +01:00
*
* @license https://opensource.org/licenses/AAL
*/
class Payment {
constructor(displayTerms, displaySignature) {
this.shouldDisplayTerms = displayTerms;
this.shouldDisplaySignature = displaySignature;
this.termsAccepted = false;
}
handleMethodSelect(element) {
2020-05-18 14:06:13 +02:00
document.getElementById("company_gateway_id").value =
element.dataset.companyGatewayId;
document.getElementById("payment_method_id").value =
element.dataset.gatewayTypeId;
2020-03-23 18:10:42 +01:00
if (this.shouldDisplaySignature && !this.shouldDisplayTerms) {
this.displayTerms();
2020-05-18 14:06:13 +02:00
document
.getElementById("accept-terms-button")
.addEventListener("click", () => {
this.termsAccepted = true;
this.submitForm();
});
2020-03-23 18:10:42 +01:00
}
if (!this.shouldDisplaySignature && this.shouldDisplayTerms) {
this.displaySignature();
2020-05-18 14:06:13 +02:00
document
.getElementById("signature-next-step")
.addEventListener("click", () => {
document.querySelector('input[name="signature"').value = this.signaturePad.toDataURL();
this.submitForm();
});
2020-03-23 18:10:42 +01:00
}
if (this.shouldDisplaySignature && this.shouldDisplayTerms) {
this.displaySignature();
2020-05-18 14:06:13 +02:00
document
.getElementById("signature-next-step")
.addEventListener("click", () => {
this.displayTerms();
document
.getElementById("accept-terms-button")
.addEventListener("click", () => {
document.querySelector('input[name="signature"').value = this.signaturePad.toDataURL();
this.termsAccepted = true;
this.submitForm();
});
2020-03-23 18:10:42 +01:00
});
}
if (!this.shouldDisplaySignature && !this.shouldDisplayTerms) {
this.submitForm();
}
}
submitForm() {
2020-05-18 14:06:13 +02:00
document.getElementById("payment-form").submit();
2020-03-23 18:10:42 +01:00
}
displayTerms() {
2020-05-18 14:06:13 +02:00
let displayTermsModal = document.getElementById("displayTermsModal");
displayTermsModal.removeAttribute("style");
2020-03-23 18:10:42 +01:00
}
displaySignature() {
2020-05-18 14:06:13 +02:00
let displaySignatureModal = document.getElementById(
"displaySignatureModal"
);
displaySignatureModal.removeAttribute("style");
const signaturePad = new SignaturePad(
document.getElementById("signature-pad"),
{
penColor: "rgb(0, 0, 0)"
}
);
this.signaturePad = signaturePad;
2020-03-23 18:10:42 +01:00
}
handle() {
2020-05-18 14:06:13 +02:00
document
.querySelectorAll(".dropdown-gateway-button")
.forEach(element => {
element.addEventListener("click", () =>
this.handleMethodSelect(element)
);
});
2020-03-23 18:10:42 +01:00
}
}
const signature = document.querySelector(
'meta[name="require-invoice-signature"]'
).content;
2020-05-18 14:06:13 +02:00
const terms = document.querySelector('meta[name="show-invoice-terms"]').content;
2020-03-23 18:10:42 +01:00
new Payment(Boolean(+signature), Boolean(+terms)).handle();