import{i as l,w as s}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 c{initBraintreeDataCollector(){window.braintree.client.create({authorization:document.querySelector("meta[name=client-token]").content},function(t,r){window.braintree.dataCollector.create({client:r,paypal:!0},function(n,e){n||(document.querySelector("input[name=client-data]").value=e.deviceData)})})}mountBraintreePaymentWidget(){window.braintree.dropin.create({authorization:document.querySelector("meta[name=client-token]").content,container:"#dropin-container",threeDSecure:document.querySelector("input[name=threeds_enable]").value.toLowerCase()==="true"},this.handleCallback)}handleCallback(t,r){if(t){console.error(t);return}let n=document.getElementById("pay-now"),e=JSON.parse(document.querySelector("input[name=threeds]").value);n.addEventListener("click",()=>{r.requestPaymentMethod({threeDSecure:{challengeRequested:!0,amount:e.amount,email:e.email,billingAddress:{givenName:e.billingAddress.givenName,surname:e.billingAddress.surname,phoneNumber:e.billingAddress.phoneNumber,streetAddress:e.billingAddress.streetAddress,extendedAddress:e.billingAddress.extendedAddress,locality:e.billingAddress.locality,region:e.billingAddress.region,postalCode:e.billingAddress.postalCode,countryCodeAlpha2:e.billingAddress.countryCodeAlpha2}}},function(i,a){if(i){console.log(i),dropin.clearSelectedPaymentMethod(),alert("There was a problem verifying this card, please contact your merchant");return}if(document.querySelector("input[name=threeds_enable]").value==="true"&&!a.liabilityShifted){console.log("Liability did not shift",a),alert("There was a problem verifying this card, please contact your merchant");return}n.disabled=!0,n.querySelector("svg").classList.remove("hidden"),n.querySelector("span").classList.add("hidden"),document.querySelector("input[name=gateway_response]").value=JSON.stringify(a);let d=document.querySelector('input[name="token-billing-checkbox"]:checked');d&&(document.querySelector('input[name="store_card"]').value=d.value),document.getElementById("server-response").submit()})})}handle(){this.initBraintreeDataCollector(),this.mountBraintreePaymentWidget(),Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(r=>r.addEventListener("click",n=>{document.getElementById("dropin-container").classList.add("hidden"),document.getElementById("save-card--container").style.display="none",document.querySelector("input[name=token]").value=n.target.dataset.token,document.getElementById("pay-now-with-token").classList.remove("hidden"),document.getElementById("pay-now").classList.add("hidden")})),document.getElementById("toggle-payment-with-credit-card").addEventListener("click",r=>{document.getElementById("dropin-container").classList.remove("hidden"),document.getElementById("save-card--container").style.display="grid",document.querySelector("input[name=token]").value="",document.getElementById("pay-now-with-token").classList.add("hidden"),document.getElementById("pay-now").classList.remove("hidden")});let t=document.getElementById("pay-now-with-token");t.addEventListener("click",r=>{t.disabled=!0,t.querySelector("svg").classList.remove("hidden"),t.querySelector("span").classList.add("hidden"),document.getElementById("server-response").submit()})}}function o(){new c().handle()}l()?o():s("#braintree-credit-card-payment","meta[name=client-token]").then(()=>o());