1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 07:02:34 +01:00
invoiceninja/resources/js/clients/payment_methods/authorize-checkout-card.js

54 lines
1.4 KiB
JavaScript
Raw Normal View History

2021-10-14 18:45:48 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
2022-06-08 06:25:44 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2021-10-14 18:45:48 +02:00
*/
class CheckoutCreditCardAuthorization {
constructor() {
2023-12-07 03:59:36 +01:00
// this.button = document.querySelector('#pay-button');
this.button = document.getElementById('pay-button');
2021-10-14 18:45:48 +02:00
}
init() {
this.frames = Frames.init(
document.querySelector('meta[name=public-key]').content
);
}
handle() {
this.init();
Frames.addEventHandler(
Frames.Events.CARD_VALIDATION_CHANGED,
(event) => {
this.button.disabled = !Frames.isCardValid();
}
);
Frames.addEventHandler(Frames.Events.CARD_TOKENIZED, (event) => {
document.querySelector(
'input[name="gateway_response"]'
).value = JSON.stringify(event);
document.getElementById('server_response').submit();
});
document
.querySelector('#authorization-form')
.addEventListener('submit', (event) => {
this.button.disabled = true;
event.preventDefault();
Frames.submitCard();
});
}
}
new CheckoutCreditCardAuthorization().handle();