2020-06-16 14:41:56 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
class AuthorizeAuthorizeCard {
|
|
|
|
|
|
|
|
constructor(publicKey, loginId) {
|
|
|
|
this.publicKey = publicKey;
|
|
|
|
this.loginId = loginId;
|
|
|
|
this.cardHolderName = document.getElementById("cardholder_name");
|
|
|
|
this.cardButton = document.getElementById("card_button");
|
|
|
|
this.payNowButton = document.getElementsByClassName("pay_now_button");
|
|
|
|
}
|
|
|
|
|
|
|
|
handleAuthorization = () => {
|
|
|
|
|
2020-06-17 02:55:56 +02:00
|
|
|
var myCard = $('#my-card');
|
|
|
|
|
2020-06-16 14:41:56 +02:00
|
|
|
var authData = {};
|
|
|
|
authData.clientKey = this.publicKey;
|
|
|
|
authData.apiLoginID = this.loginId;
|
|
|
|
|
|
|
|
var cardData = {};
|
2020-06-17 02:55:56 +02:00
|
|
|
cardData.cardNumber = myCard.CardJs('cardNumber');
|
|
|
|
cardData.month = myCard.CardJs('expiryMonth');
|
|
|
|
cardData.year = myCard.CardJs('expiryYear');;
|
2020-06-16 14:41:56 +02:00
|
|
|
cardData.cardCode = document.getElementById("cvv").value;
|
|
|
|
|
|
|
|
var secureData = {};
|
|
|
|
secureData.authData = authData;
|
|
|
|
secureData.cardData = cardData;
|
|
|
|
// If using banking information instead of card information,
|
|
|
|
// send the bankData object instead of the cardData object.
|
|
|
|
//
|
|
|
|
// secureData.bankData = bankData;
|
|
|
|
|
|
|
|
Accept.dispatchData(secureData, this.responseHandler);
|
2020-06-17 03:26:58 +02:00
|
|
|
|
|
|
|
return false;
|
2020-06-16 14:41:56 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
handlePayNowAction(token_hashed_id) {
|
|
|
|
|
|
|
|
document.getElementById("token").value = token_hashed_id;
|
|
|
|
document.getElementById("server_response").submit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
responseHandler(response) {
|
|
|
|
|
2020-06-17 13:15:24 +02:00
|
|
|
|
2020-06-16 14:41:56 +02:00
|
|
|
if (response.messages.resultCode === "Error") {
|
|
|
|
var i = 0;
|
2020-06-17 02:55:56 +02: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-06-16 14:41:56 +02:00
|
|
|
}
|
|
|
|
else if(response.messages.resultCode === "Ok"){
|
|
|
|
|
|
|
|
document.getElementById("dataDescriptor").value = response.opaqueData.dataDescriptor;
|
|
|
|
document.getElementById("dataValue").value = response.opaqueData.dataValue;
|
2020-06-17 03:26:58 +02:00
|
|
|
document.getElementById("store_card").value = document.getElementById("store_card_checkbox").checked;
|
2020-06-16 14:41:56 +02:00
|
|
|
document.getElementById("server_response").submit();
|
|
|
|
|
|
|
|
}
|
2020-06-17 13:15:24 +02:00
|
|
|
|
|
|
|
this.cardButton.disabled=false;
|
2020-06-16 14:41:56 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handle = () => {
|
|
|
|
|
|
|
|
|
|
|
|
if(this.cardButton)
|
|
|
|
{
|
|
|
|
this.cardButton.addEventListener("click", () => {
|
|
|
|
|
2020-06-17 13:15:24 +02:00
|
|
|
this.cardButton.disabled = true;
|
|
|
|
|
2020-06-16 14:41:56 +02:00
|
|
|
this.handleAuthorization();
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if(this.payNowButton)
|
|
|
|
{
|
|
|
|
|
|
|
|
for(let item of this.payNowButton) {
|
|
|
|
|
|
|
|
item.addEventListener('click', () => {
|
2020-06-17 13:15:24 +02:00
|
|
|
item.disabled = true;
|
2020-06-16 14:41:56 +02:00
|
|
|
this.handlePayNowAction(item.dataset.id);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const publicKey = document.querySelector(
|
|
|
|
'meta[name="authorize-public-key"]'
|
|
|
|
).content;
|
|
|
|
|
|
|
|
const loginId = document.querySelector(
|
|
|
|
'meta[name="authorize-login-id"]'
|
|
|
|
).content;
|
|
|
|
|
|
|
|
/** @handle */
|
|
|
|
new AuthorizeAuthorizeCard(publicKey, loginId).handle();
|