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/wepay-bank-account.js

56 lines
1.7 KiB
JavaScript
Raw Normal View History

2021-06-21 14:21:44 +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)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
class WePayBank {
initializeWePay() {
let environment = document.querySelector('meta[name="wepay-environment"]')?.content;
WePay.set_endpoint(environment === 'staging' ? 'stage' : 'production');
return this;
}
showBankPopup() {
WePay.bank_account.create({
client_id: document.querySelector('meta[name=wepay-client-id]')?.content,
2021-11-11 10:35:07 +01:00
email: document.querySelector('meta[name=contact-email]')?.content,
options: {
avoidMicrodeposits:true
}
2021-06-21 14:21:44 +02:00
}, function (data) {
if (data.error) {
errors.textContent = '';
errors.textContent = data.error_description;
errors.hidden = false;
} else {
document.querySelector('input[name="bank_account_id"]').value = data.bank_account_id;
document.getElementById('server_response').submit();
}
}, function (data) {
if (data.error) {
errors.textContent = '';
errors.textContent = data.error_description;
errors.hidden = false;
}
}
);
}
handle() {
this
.initializeWePay()
.showBankPopup();
}
}
document.addEventListener('DOMContentLoaded', () => {
new WePayBank().handle();
});