1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/public/build/assets/authorize-authorize-card-39be6d93.js
Benjamin Beganović dfd12adb56 Authorize.net: Upgrade authorize to use Simple Card (#95)
* update authorize view

* update js

* assets rebuild
2024-09-04 18:36:32 +02:00

10 lines
2.6 KiB
JavaScript
Vendored

/**
* 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 o{constructor(e,t){this.publicKey=e,this.loginId=t,this.cardHolderName=document.getElementById("cardholder_name"),this.cardButton=document.getElementById("card_button"),this.sc=createSimpleCard({fields:{card:{number:"#number",date:"#date",cvv:"#cvv"}}}),this.sc.mount()}handleAuthorization(){var r,n,s,c;if(this.cvvRequired=="1"&&document.getElementById("cvv").value.length<3){const d=document.getElementById("errors");d&&(d.innerText="CVV is required",d.style.display="block"),document.getElementById("pay-now").disabled=!1,document.querySelector("#pay-now > svg").classList.add("hidden"),document.querySelector("#pay-now > span").classList.remove("hidden");return}var e={};e.clientKey=this.publicKey,e.apiLoginID=this.loginId;var t={};t.cardNumber=(r=this.sc.value("number"))==null?void 0:r.replace(/[^\d]/g,""),t.month=(n=this.sc.value("month"))==null?void 0:n.replace(/[^\d]/g,""),t.year=`20${(s=this.sc.value("year"))==null?void 0:s.replace(/[^\d]/g,"")}`,t.cardCode=(c=this.sc.value("cvv"))==null?void 0:c.replace(/[^\d]/g,"");var a={};return a.authData=e,a.cardData=t,document.getElementById("card_button").disabled=!0,document.querySelector("#card_button > svg").classList.remove("hidden"),document.querySelector("#card_button > span").classList.add("hidden"),Accept.dispatchData(a,this.responseHandler),!1}responseHandler(e){if(e.messages.resultCode==="Error"){var t=0;const a=document.getElementById("errors");a&&(a.innerText=`${e.messages.message[t].code}: ${e.messages.message[t].text}`,a.style.display="block"),document.getElementById("card_button").disabled=!1,document.querySelector("#card_button > svg").classList.add("hidden"),document.querySelector("#card_button > span").classList.remove("hidden")}else e.messages.resultCode==="Ok"&&(document.getElementById("dataDescriptor").value=e.opaqueData.dataDescriptor,document.getElementById("dataValue").value=e.opaqueData.dataValue,document.getElementById("server_response").submit());return!1}handle(){return this.cardButton.addEventListener("click",()=>{this.cardButton.disabled=!this.cardButton.disabled,this.handleAuthorization()}),this}}const u=document.querySelector('meta[name="authorize-public-key"]').content,l=document.querySelector('meta[name="authorize-login-id"]').content;document.querySelector('meta[name="authnet-require-cvv"]').content;new o(u,l).handle();