1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/public/build/assets/square-credit-card-9e88c754.js
2024-10-10 12:52:14 +11:00

10 lines
4.2 KiB
JavaScript
Vendored

import{i as c,w as d}from"./wait-8f4ae121.js";/**
* 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 s{constructor(){this.appId=document.querySelector("meta[name=square-appId]").content,this.locationId=document.querySelector("meta[name=square-locationId]").content,this.isLoaded=!1}async init(){this.payments=Square.payments(this.appId,this.locationId),this.card=await this.payments.card(),await this.card.attach("#card-container"),this.isLoaded=!0;let t=document.querySelector(".sq-card-iframe-container");t&&t.setAttribute("style","150px !important"),document.querySelector(".toggle-payment-with-token")&&document.getElementById("card-container").classList.add("hidden")}async completePaymentWithoutToken(t){document.getElementById("errors").hidden=!0,t.target.parentElement.disabled=!0;let n=document.getElementById("pay-now");this.payNowButton=n,this.payNowButton.disabled=!0,this.payNowButton.querySelector("svg").classList.remove("hidden"),this.payNowButton.querySelector("span").classList.add("hidden");let a=await this.card.tokenize(),o;try{const e={amount:document.querySelector("meta[name=amount]").content,billingContact:JSON.parse(document.querySelector("meta[name=square_contact]").content),currencyCode:document.querySelector("meta[name=currencyCode]").content,intent:"CHARGE"};o=(await this.payments.verifyBuyer(a.token,e)).token}catch{t.target.parentElement.disabled=!0}if(document.querySelector('input[name="verificationToken"]').value=o,a.status==="OK"){document.getElementById("sourceId").value=a.token;let e=document.querySelector('input[name="token-billing-checkbox"]:checked');return e&&(document.querySelector('input[name="store_card"]').value=e.value),document.getElementById("server_response").submit()}document.getElementById("errors").textContent=a.errors[0].message,document.getElementById("errors").hidden=!1,t.target.parentElement.disabled=!1,this.payNowButton.disabled=!1,this.payNowButton.querySelector("svg").classList.add("hidden"),this.payNowButton.querySelector("span").classList.remove("hidden")}async completePaymentUsingToken(t){t.target.parentElement.disabled=!0;let n=document.getElementById("pay-now");return this.payNowButton=n,this.payNowButton.disabled=!0,this.payNowButton.querySelector("svg").classList.remove("hidden"),this.payNowButton.querySelector("span").classList.add("hidden"),document.getElementById("server_response").submit()}async verifyBuyer(t){const n={amount:document.querySelector("meta[name=amount]").content,billingContact:document.querySelector("meta[name=square_contact]").content,currencyCode:document.querySelector("meta[name=currencyCode]").content,intent:"CHARGE"};return(await this.payments.verifyBuyer(t,n)).token}async handle(){document.getElementById("payment-list").classList.add("hidden"),await this.init().then(()=>{var t,n,a,o;(t=document.getElementById("authorize-card"))==null||t.addEventListener("click",e=>this.completePaymentWithoutToken(e)),(n=document.getElementById("pay-now"))==null||n.addEventListener("click",e=>document.querySelector("input[name=token]").value?this.completePaymentUsingToken(e):this.completePaymentWithoutToken(e)),Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(e=>e.addEventListener("click",async r=>{document.getElementById("card-container").classList.add("hidden"),document.getElementById("save-card--container").style.display="none",document.querySelector("input[name=token]").value=r.target.dataset.token})),(a=document.getElementById("toggle-payment-with-credit-card"))==null||a.addEventListener("click",async e=>{document.getElementById("card-container").classList.remove("hidden"),document.getElementById("save-card--container").style.display="grid",document.querySelector("input[name=token]").value=""}),Array.from(document.getElementsByClassName("loader")).forEach(e=>{e.classList.add("hidden")}),document.getElementById("payment-list").classList.remove("hidden"),(o=document.getElementById("toggle-payment-with-credit-card"))==null||o.click()})}}function i(){new s().handle()}c()?i():d("#square-credit-card-payment").then(()=>i());