mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-15 15:42:51 +01:00
0de492d96f
* stripe: ach * stripe: klarna * stripe: bank transfer * assets build * stripe: bacs * stripe: bancontact * stripe: becs * stripe: eps * stripe: fpx * stripe: giropay * stripe: ideal * stripe: przelewy24 * stripe: sepa * stripe: sofort * assets build * assets build * pass context payload into livewirePaymentView * update checkout.com * update livewire method interface * stripe: acss * align methods with interface (array $data)
81 lines
2.5 KiB
JavaScript
Vendored
81 lines
2.5 KiB
JavaScript
Vendored
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
import { wait } from '../wait';
|
|
|
|
wait('#stripe-acss-authorize').then(() => authorize());
|
|
|
|
function authorize() {
|
|
let stripe;
|
|
|
|
const account_id = document.querySelector(
|
|
'meta[name="stripe-account-id"]'
|
|
)?.content;
|
|
|
|
const publishable_key = document.querySelector(
|
|
'meta[name="stripe-publishable-key"]'
|
|
)?.content;
|
|
|
|
if (account_id && account_id.length > 0) {
|
|
stripe = Stripe(publishable_key, {
|
|
stripeAccount: account_id,
|
|
});
|
|
} else {
|
|
stripe = Stripe(publishable_key);
|
|
}
|
|
|
|
const accountholderName = document.getElementById('acss-name');
|
|
const email = document.getElementById('acss-email-address');
|
|
const submitButton = document.getElementById('authorize-acss');
|
|
const clientSecret = document.querySelector('meta[name="stripe-pi-client-secret"]')?.content;
|
|
const errors = document.getElementById('errors');
|
|
|
|
submitButton.addEventListener('click', async (event) => {
|
|
event.preventDefault();
|
|
errors.hidden = true;
|
|
submitButton.disabled = true;
|
|
|
|
const validEmailRegex =
|
|
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
|
|
|
if (email.value.length < 3 || !email.value.match(validEmailRegex)) {
|
|
errors.textContent = 'Please enter a valid email address.';
|
|
errors.hidden = false;
|
|
submitButton.disabled = false;
|
|
return;
|
|
}
|
|
|
|
if (accountholderName.value.length < 3) {
|
|
errors.textContent = 'Please enter a name for the account holder.';
|
|
errors.hidden = false;
|
|
submitButton.disabled = false;
|
|
return;
|
|
}
|
|
|
|
const { setupIntent, error } = await stripe.confirmAcssDebitSetup(
|
|
clientSecret,
|
|
{
|
|
payment_method: {
|
|
billing_details: {
|
|
name: accountholderName.value,
|
|
email: email.value,
|
|
},
|
|
},
|
|
}
|
|
);
|
|
|
|
// Handle next step based on SetupIntent's status.
|
|
document.getElementById('gateway_response').value = JSON.stringify(
|
|
setupIntent ?? error
|
|
);
|
|
document.getElementById('server_response').submit();
|
|
});
|
|
}
|