2020-06-10 17:38:10 +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-10 17:38:10 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
2020-12-02 15:33:43 +01:00
|
|
|
const paymentWithToken = document.getElementById('toggle-payment-with-token');
|
|
|
|
const paymentWithCreditCard = document.getElementById(
|
|
|
|
'toggle-payment-with-credit-card'
|
|
|
|
);
|
|
|
|
const payButton = document.getElementById('pay-button');
|
|
|
|
const form = document.getElementById('payment-form');
|
|
|
|
const publicKey =
|
|
|
|
document.querySelector('meta[name="public-key"]').content ?? '';
|
|
|
|
|
|
|
|
if (paymentWithToken) {
|
|
|
|
paymentWithToken.addEventListener('click', () => {
|
2020-11-01 15:56:17 +01:00
|
|
|
document.getElementById('save-card--container').style.display = 'none';
|
|
|
|
document.getElementById('checkout--container').style.display = 'none';
|
|
|
|
document.getElementById('pay-now-with-token--container').style.display =
|
|
|
|
'block';
|
|
|
|
|
|
|
|
document.querySelector('input[name=pay_with_token]').value = true;
|
|
|
|
});
|
2020-12-02 15:33:43 +01:00
|
|
|
}
|
2020-11-01 15:56:17 +01:00
|
|
|
|
2020-12-02 15:33:43 +01:00
|
|
|
if (paymentWithCreditCard) {
|
|
|
|
paymentWithCreditCard.addEventListener('click', () => {
|
2020-11-01 15:56:17 +01:00
|
|
|
document.getElementById('save-card--container').style.display = 'grid';
|
|
|
|
document.getElementById('checkout--container').style.display = 'block';
|
|
|
|
document.getElementById('pay-now-with-token--container').style.display =
|
|
|
|
'none';
|
|
|
|
|
|
|
|
document.querySelector('input[name=pay_with_token]').value = false;
|
|
|
|
});
|
2020-12-02 15:33:43 +01:00
|
|
|
}
|
2020-11-01 15:56:17 +01:00
|
|
|
|
|
|
|
const completePayment = (data = null) => {
|
|
|
|
if (data) {
|
|
|
|
document.querySelector(
|
|
|
|
'input[name="gateway_response"]'
|
2020-12-02 15:33:43 +01:00
|
|
|
).value = JSON.stringify(data);
|
2020-11-01 15:56:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
document.querySelector(
|
|
|
|
'input[name="store_card"]'
|
|
|
|
).value = document.querySelector(
|
|
|
|
'input[name=token-billing-checkbox]:checked'
|
|
|
|
).value;
|
|
|
|
|
|
|
|
document.getElementById('server-response').submit();
|
|
|
|
};
|
|
|
|
|
2020-12-02 15:33:43 +01:00
|
|
|
if (document.getElementById('pay-now-with-token')) {
|
|
|
|
document
|
|
|
|
.getElementById('pay-now-with-token')
|
|
|
|
.addEventListener('click', completePayment);
|
|
|
|
}
|
2020-11-01 15:56:17 +01:00
|
|
|
|
2020-12-02 15:33:43 +01:00
|
|
|
// window.CKOConfig = {
|
|
|
|
// publicKey: document.querySelector('meta[name="public-key"]').content,
|
|
|
|
// customerEmail: document.querySelector('meta[name="customer-email"]')
|
|
|
|
// .content,
|
|
|
|
// value: document.querySelector('meta[name="value"]').content,
|
|
|
|
// currency: document.querySelector('meta[name="currency"]').content,
|
|
|
|
// paymentMode: 'cards',
|
|
|
|
// cardFormMode: 'cardTokenisation',
|
|
|
|
// cardTokenised: function(event) {
|
|
|
|
// completePayment(event);
|
|
|
|
// },
|
|
|
|
// };
|
|
|
|
|
|
|
|
Frames.init(publicKey);
|
|
|
|
|
|
|
|
Frames.addEventHandler(Frames.Events.CARD_VALIDATION_CHANGED, function(event) {
|
|
|
|
payButton.disabled = !Frames.isCardValid();
|
|
|
|
});
|
|
|
|
|
|
|
|
Frames.addEventHandler(Frames.Events.CARD_TOKENIZED, function(event) {
|
|
|
|
completePayment(event)
|
|
|
|
});
|
|
|
|
|
|
|
|
form.addEventListener('submit', function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
Frames.submitCard();
|
|
|
|
});
|