2020-06-09 14:42:23 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-13 09:22:36 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-06-09 14:42:23 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AuthorizeACH {
|
|
|
|
constructor() {
|
|
|
|
this.errors = document.getElementById('errors');
|
|
|
|
this.key = document.querySelector(
|
|
|
|
'meta[name="stripe-publishable-key"]'
|
|
|
|
).content;
|
|
|
|
}
|
|
|
|
|
|
|
|
setupStripe = () => {
|
|
|
|
this.stripe = Stripe(this.key);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
getFormData = () => {
|
|
|
|
return {
|
|
|
|
country: document.getElementById('country').value,
|
|
|
|
currency: document.getElementById('currency').value,
|
|
|
|
routing_number: document.getElementById('routing-number').value,
|
|
|
|
account_number: document.getElementById('account-number').value,
|
|
|
|
account_holder_name: document.getElementById('account-holder-name')
|
|
|
|
.value,
|
|
|
|
account_holder_type: document.querySelector(
|
|
|
|
'input[name="account-holder-type"]:checked'
|
|
|
|
).value,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
handleError = (message) => {
|
2020-08-24 10:28:55 +02:00
|
|
|
document.getElementById('save-button').disabled = false;
|
2020-09-29 12:36:21 +02:00
|
|
|
document.querySelector('#save-button > svg').classList.add('hidden');
|
|
|
|
document.querySelector('#save-button > span').classList.remove('hidden');
|
2020-08-24 10:28:55 +02:00
|
|
|
|
2020-06-09 14:42:23 +02:00
|
|
|
this.errors.textContent = '';
|
|
|
|
this.errors.textContent = message;
|
|
|
|
this.errors.hidden = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSuccess = (response) => {
|
|
|
|
document.getElementById('gateway_response').value = JSON.stringify(
|
|
|
|
response
|
|
|
|
);
|
|
|
|
|
|
|
|
document.getElementById('server_response').submit();
|
|
|
|
};
|
|
|
|
|
|
|
|
handleSubmit = (e) => {
|
2020-08-24 10:28:55 +02:00
|
|
|
document.getElementById('save-button').disabled = true;
|
2020-09-29 12:36:21 +02:00
|
|
|
document.querySelector('#save-button > svg').classList.remove('hidden');
|
|
|
|
document.querySelector('#save-button > span').classList.add('hidden');
|
2021-01-21 15:53:37 +01:00
|
|
|
|
2020-06-09 14:42:23 +02:00
|
|
|
e.preventDefault();
|
2020-09-29 12:36:21 +02:00
|
|
|
|
2020-06-09 14:42:23 +02:00
|
|
|
this.errors.textContent = '';
|
|
|
|
this.errors.hidden = true;
|
|
|
|
|
|
|
|
this.stripe
|
|
|
|
.createToken('bank_account', this.getFormData())
|
|
|
|
.then((result) => {
|
|
|
|
if (result.hasOwnProperty('error')) {
|
|
|
|
return this.handleError(result.error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.handleSuccess(result);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
handle() {
|
|
|
|
document
|
2020-10-20 17:54:08 +02:00
|
|
|
.getElementById('save-button')
|
|
|
|
.addEventListener('click', (e) => this.handleSubmit(e));
|
2020-06-09 14:42:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
new AuthorizeACH().setupStripe().handle();
|