1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/resources/js/clients/payment_methods/authorize-authorize-card.js

89 lines
2.7 KiB
JavaScript
Raw Normal View History

2020-06-09 05:54:09 +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)
2020-06-09 05:54:09 +02:00
*
* @license https://opensource.org/licenses/AAL
*/
class AuthorizeAuthorizeCard {
2020-06-09 13:53:23 +02:00
constructor(publicKey, loginId) {
this.publicKey = publicKey;
this.loginId = loginId;
2020-06-09 05:54:09 +02:00
this.cardHolderName = document.getElementById("cardholder_name");
this.cardButton = document.getElementById("card_button");
}
handleAuthorization() {
2021-01-26 14:31:52 +01:00
var myCard = $('#my-card');
2020-06-09 05:54:09 +02:00
var authData = {};
2020-06-09 13:53:23 +02:00
authData.clientKey = this.publicKey;
authData.apiLoginID = this.loginId;
2021-01-26 14:31:52 +01:00
var cardData = {};
cardData.cardNumber = myCard.CardJs('cardNumber').replace(/[^\d]/g, '');
cardData.month = myCard.CardJs('expiryMonth');
cardData.year = myCard.CardJs('expiryYear');;
2020-06-09 05:54:09 +02:00
cardData.cardCode = document.getElementById("cvv").value;
var secureData = {};
2020-06-09 05:54:09 +02:00
secureData.authData = authData;
secureData.cardData = cardData;
2020-09-29 13:13:50 +02:00
document.getElementById('card_button').disabled = true;
document.querySelector('#card_button > svg').classList.remove('hidden');
document.querySelector('#card_button > span').classList.add('hidden');
2020-06-09 05:54:09 +02:00
2020-06-09 14:54:22 +02:00
Accept.dispatchData(secureData, this.responseHandler);
return false;
2020-06-09 05:54:09 +02:00
}
responseHandler(response) {
if (response.messages.resultCode === "Error") {
var i = 0;
2021-01-26 14:31:52 +01:00
var $errors = $('#errors'); // get the reference of the div
$errors.show().html("<p>" + response.messages.message[i].code + ": " + response.messages.message[i].text + "</p>");
2020-09-29 13:13:50 +02:00
document.getElementById('card_button').disabled = false;
document.querySelector('#card_button > svg').classList.add('hidden');
document.querySelector('#card_button > span').classList.remove('hidden');
2020-06-09 05:54:09 +02:00
}
2020-06-09 14:54:22 +02:00
else if(response.messages.resultCode === "Ok"){
2021-01-26 14:31:52 +01:00
2020-06-09 14:57:01 +02:00
document.getElementById("dataDescriptor").value = response.opaqueData.dataDescriptor;
document.getElementById("dataValue").value = response.opaqueData.dataValue;
2020-06-09 14:54:22 +02:00
document.getElementById("server_response").submit();
2020-06-09 05:54:09 +02:00
}
2020-06-09 14:54:22 +02:00
return false;
2020-06-09 05:54:09 +02:00
}
handle() {
this.cardButton.addEventListener("click", () => {
2020-06-17 15:27:11 +02:00
this.cardButton.disabled = !this.cardButton.disabled;
this.handleAuthorization();
2020-06-09 05:54:09 +02:00
});
2020-06-16 18:09:43 +02:00
2020-06-09 05:54:09 +02:00
return this;
}
}
const publicKey = document.querySelector(
'meta[name="authorize-public-key"]'
).content;
2020-06-09 13:53:23 +02:00
const loginId = document.querySelector(
2020-06-09 14:54:22 +02:00
'meta[name="authorize-login-id"]'
2020-06-09 13:53:23 +02:00
).content;
2020-06-09 05:54:09 +02:00
/** @handle */
2021-01-26 14:31:52 +01:00
new AuthorizeAuthorizeCard(publicKey, loginId).handle();