2022-12-05 08:42:28 +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 ProcessKlarna {
|
|
|
|
constructor(key, stripeConnect) {
|
|
|
|
this.key = key;
|
|
|
|
this.errors = document.getElementById('errors');
|
|
|
|
this.stripeConnect = stripeConnect;
|
|
|
|
}
|
|
|
|
|
|
|
|
setupStripe = () => {
|
|
|
|
|
|
|
|
if (this.stripeConnect){
|
2022-12-08 08:55:58 +01:00
|
|
|
// this.stripe.stripeAccount = this.stripeConnect;
|
2022-12-05 08:42:28 +01:00
|
|
|
|
2022-12-08 08:55:58 +01:00
|
|
|
this.stripe = Stripe(this.key, {
|
|
|
|
stripeAccount: this.stripeConnect,
|
2022-12-05 08:42:28 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
this.stripe = Stripe(this.key);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
handle = () => {
|
|
|
|
document.getElementById('pay-now').addEventListener('click', (e) => {
|
|
|
|
let errors = document.getElementById('errors');
|
|
|
|
|
|
|
|
document.getElementById('pay-now').disabled = true;
|
|
|
|
document.querySelector('#pay-now > svg').classList.remove('hidden');
|
|
|
|
document.querySelector('#pay-now > span').classList.add('hidden');
|
|
|
|
|
|
|
|
this.stripe.confirmKlarnaPayment(
|
|
|
|
document.querySelector('meta[name=pi-client-secret').content,
|
|
|
|
{
|
|
|
|
payment_method: {
|
|
|
|
billing_details: {
|
2022-12-08 08:55:58 +01:00
|
|
|
name: document.querySelector('meta[name=name]').content,
|
|
|
|
email: document.querySelector('meta[name=email]').content,
|
2022-12-07 13:01:16 +01:00
|
|
|
address: {
|
2022-12-08 08:55:58 +01:00
|
|
|
line1: document.querySelector('meta[name=address-1]').content,
|
|
|
|
line2: document.querySelector('meta[name=address-2]').content,
|
|
|
|
city: document.querySelector('meta[name=city]').content,
|
|
|
|
postal_code: document.querySelector('meta[name=plz]').content,
|
|
|
|
state: document.querySelector('meta[name=state]').content,
|
|
|
|
country: document.querySelector('meta[name=country]').content,
|
|
|
|
}
|
2022-12-05 08:42:28 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
return_url: document.querySelector(
|
|
|
|
'meta[name="return-url"]'
|
|
|
|
).content,
|
|
|
|
}
|
2022-12-08 08:55:58 +01:00
|
|
|
);
|
2022-12-05 08:42:28 +01:00
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const publishableKey = document.querySelector(
|
|
|
|
'meta[name="stripe-publishable-key"]'
|
|
|
|
)?.content ?? '';
|
|
|
|
|
|
|
|
const stripeConnect =
|
|
|
|
document.querySelector('meta[name="stripe-account-id"]')?.content ?? '';
|
|
|
|
|
|
|
|
new ProcessKlarna(publishableKey, stripeConnect).setupStripe().handle();
|