1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +01:00
invoiceninja/resources/js/clients/payments/stripe-bacs.js

85 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-12-16 12:05:10 +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)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
class ProcessBACS {
constructor(key, stripeConnect) {
this.key = key;
this.errors = document.getElementById('errors');
this.stripeConnect = stripeConnect;
2022-12-17 07:05:19 +01:00
this.onlyAuthorization = onlyAuthorization;
2022-12-16 12:05:10 +01:00
}
setupStripe = () => {
if (this.stripeConnect){
2022-12-16 15:03:24 +01:00
// this.stripe.stripeAccount = this.stripeConnect;
2022-12-16 12:05:10 +01:00
2022-12-16 15:03:24 +01:00
this.stripe = Stripe(this.key, {
stripeAccount: this.stripeConnect,
2022-12-16 12:05:10 +01:00
});
}
else {
this.stripe = Stripe(this.key);
}
return this;
};
handle = () => {
2022-12-17 15:08:37 +01:00
2022-12-17 06:19:52 +01:00
if (this.onlyAuthorization) {
document.getElementById('authorize-bacs').addEventListener('click', (e) => {
document.getElementById('authorize-bacs').disabled = true;
document.querySelector('#authorize-bacs > svg').classList.remove('hidden');
document.querySelector('#authorize-bacs > span').classList.add('hidden');
2022-12-17 14:59:20 +01:00
location.href=document.querySelector('meta[name=stripe-redirect-url]').content;
2022-12-17 06:19:52 +01:00
});}
else{
2022-12-17 15:08:37 +01:00
Array.from(
document.getElementsByClassName('toggle-payment-with-token')
).forEach((element) =>
element.addEventListener('click', (element) => {
document.querySelector('input[name=token]').value =
element.target.dataset.token;
})
);
2022-12-17 06:47:43 +01:00
document.getElementById('pay-now').addEventListener('click', (e) => {
let payNowButton = document.getElementById('pay-now');
this.payNowButton = payNowButton;
this.payNowButton.disabled = true;
this.payNowButton.querySelector('svg').classList.remove('hidden');
this.payNowButton.querySelector('span').classList.add('hidden');
2022-12-22 11:06:00 +01:00
this.handleResult();
2022-12-17 06:39:16 +01:00
});
2022-12-17 06:19:52 +01:00
}
2022-12-16 12:05:10 +01:00
};
2022-12-22 11:06:00 +01:00
handleResult() {
2022-12-17 14:52:21 +01:00
document.querySelector(
'input[name="gateway_response"]'
2022-12-22 11:06:00 +01:00
).value = ocument.querySelector('input[name=token]').value;
2022-12-17 14:52:21 +01:00
document.getElementById('server-response').submit();
}
2022-12-16 12:05:10 +01:00
}
const publishableKey = document.querySelector(
'meta[name="stripe-publishable-key"]'
)?.content ?? '';
const stripeConnect =
document.querySelector('meta[name="stripe-account-id"]')?.content ?? '';
2022-12-17 06:19:52 +01:00
const onlyAuthorization =
document.querySelector('meta[name="only-authorization"]')?.content ?? '';
2022-12-16 12:05:10 +01:00
new ProcessBACS(publishableKey, stripeConnect).setupStripe().handle();