1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00

Fixes for CBA Powerboard

This commit is contained in:
David Bomba 2024-09-24 17:41:32 +10:00
parent fb82c204f2
commit 47f9673caf

View File

@ -0,0 +1,13 @@
import{i,w as u}from"./wait-8f4ae121.js";/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/let a=!1;function l(){const e=document.querySelector("meta[name=public_key]"),t=document.querySelector("meta[name=gateway_id]"),r=document.querySelector("meta[name=environment]"),n=new cba.HtmlWidget("#widget",e==null?void 0:e.content,t==null?void 0:t.content);n.setEnv(r==null?void 0:r.content),n.useAutoResize(),n.interceptSubmitForm("#stepone"),n.onFinishInsert('#server-response input[name="gateway_response"]',"payment_source"),n.setFormFields(["card_name*"]),n.reload();let o=document.getElementById("pay-now");return o.disabled=!1,o.querySelector("svg").classList.add("hidden"),o.querySelector("span").classList.remove("hidden"),document.querySelector('#server-response input[name="gateway_response"]').value="",n}function m(){var e,t,r;(e=document.querySelector("#widget"))==null||e.replaceChildren(),(t=document.querySelector("#widget"))==null||t.classList.remove("hidden"),(r=document.querySelector("#widget-3dsecure"))==null||r.replaceChildren()}function s(){var n;m();const e=l();e.on("finish",()=>{document.getElementById("errors").hidden=!0,g()}),e.on("submit",function(o){document.getElementById("errors").hidden=!0});let t=document.getElementById("pay-now");t.addEventListener("click",()=>{const o=document.getElementById("widget");if(e.getValidationState(),!e.isValidForm()&&o.offsetParent!==null){t.disabled=!1,t.querySelector("svg").classList.add("hidden"),t.querySelector("span").classList.remove("hidden");return}t.disabled=!0,t.querySelector("svg").classList.remove("hidden"),t.querySelector("span").classList.add("hidden");let d=document.querySelector("input[name=token-billing-checkbox]:checked");d&&(document.getElementById("store_card").value=d.value),o.offsetParent!==null?document.getElementById("stepone_submit").click():document.getElementById("server-response").submit()}),document.getElementById("toggle-payment-with-credit-card").addEventListener("click",o=>{var c;document.getElementById("widget").classList.remove("hidden"),document.getElementById("save-card--container").style.display="grid",document.querySelector("input[name=token]").value="",(c=document.querySelector("#powerboard-payment-container"))==null||c.classList.remove("hidden")}),Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(o=>o.addEventListener("click",d=>{var c;document.getElementById("widget").classList.add("hidden"),document.getElementById("save-card--container").style.display="none",document.querySelector("input[name=token]").value=d.target.dataset.token,(c=document.querySelector("#powerboard-payment-container"))==null||c.classList.add("hidden")}));const r=document.querySelector('input[name="payment-type"]');r&&r.click(),console.log({focusCreditCard:a}),a&&((n=document.getElementById("toggle-payment-with-credit-card"))==null||n.click())}async function g(){try{const e=await y();if(console.log(e),!e.status||e.status==="not_authenticated"||e==="not_authenticated")throw a=!0,s(),new Error("There was an issue authenticating this payment method.");if(e.status==="authentication_not_supported"){document.querySelector('input[name="browser_details"]').value=null,document.querySelector('input[name="charge"]').value=JSON.stringify(e);let n=document.querySelector("input[name=token-billing-checkbox]:checked");return n&&(document.getElementById("store_card").value=n.value),document.getElementById("server-response").submit()}const t=new cba.Canvas3ds("#widget-3dsecure",e._3ds.token);t.load(),document.getElementById("widget").classList.add("hidden"),t.on("chargeAuthSuccess",function(n){document.querySelector('input[name="browser_details"]').value=null,document.querySelector('input[name="charge"]').value=JSON.stringify(n);let o=document.querySelector("input[name=token-billing-checkbox]:checked");o&&(document.getElementById("store_card").value=o.value),document.getElementById("server-response").submit()}),t.on("chargeAuthReject",function(n){document.getElementById("errors").textContent="Sorry, your transaction could not be processed...",document.getElementById("errors").hidden=!1,a=!0,s()}),t.load()}catch(e){const t=e.message??"Unknown error.";document.getElementById("errors").textContent=`Sorry, your transaction could not be processed...
${t}`,document.getElementById("errors").hidden=!1,a=!0,s()}}async function y(){const e={name:navigator.userAgent.substring(0,100),java_enabled:navigator.javaEnabled()?"true":"false",language:navigator.language||navigator.userLanguage,screen_height:window.screen.height.toString(),screen_width:window.screen.width.toString(),time_zone:(new Date().getTimezoneOffset()*-1).toString(),color_depth:window.screen.colorDepth.toString()};document.querySelector('input[name="browser_details"]').value=JSON.stringify(e);const t=JSON.stringify(Object.fromEntries(new FormData(document.getElementById("server-response")))),r=document.querySelector("meta[name=payments_route]");try{const n=await fetch(r.content,{method:"POST",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest",Accept:"application/json","X-CSRF-Token":document.querySelector('meta[name="csrf-token"]').content},body:t});return n.ok?await n.json():await n.json().then(o=>{throw new Error(o.message??"Unknown error.")})}catch(n){document.getElementById("errors").textContent=`Sorry, your transaction could not be processed...
${n.message}`,document.getElementById("errors").hidden=!1,a=!0,s()}}i()?s():u("#powerboard-credit-card-payment").then(()=>s());