1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 15:42:51 +01:00
invoiceninja/public/build/assets/authorize-credit-card-payment-bd9c9d4d.js

21 lines
23 KiB
JavaScript
Raw Normal View History

var G=Object.defineProperty;var J=(t,e,n)=>e in t?G(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var T=(t,e,n)=>(J(t,typeof e!="symbol"?e+"":e,n),n);var q=t=>{throw TypeError(t)},Q=(t,e,n)=>e.has(t)||q("Cannot "+n),ee=(t,e,n)=>e.has(t)?q("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,n),te=(t,e,n)=>(Q(t,e,"access private method"),n);const B={mask:/^.*$/,preprocessors:[],postprocessors:[],plugins:[],overwriteMode:"shift"};class ne{constructor(){this.now=null,this.past=[],this.future=[]}undo(){const e=this.past.pop();e&&this.now&&(this.future.push(this.now),this.updateElement(e,"historyUndo"))}redo(){const e=this.future.pop();e&&this.now&&(this.past.push(this.now),this.updateElement(e,"historyRedo"))}updateHistory(e){if(!this.now){this.now=e;return}const n=this.now.value!==e.value,a=this.now.selection.some((s,r)=>s!==e.selection[r]);!n&&!a||(n&&(this.past.push(this.now),this.future=[]),this.now=e)}updateElement(e,n){this.now=e,this.updateElementState(e,{inputType:n,data:null})}}function ae(t,...e){return e.every(({value:n})=>n===t.value)}function se(t,...e){return e.every(({value:n,selection:a})=>n===t.value&&a[0]===t.selection[0]&&a[1]===t.selection[1])}function re({value:t,selection:e},n,a){const[s,r]=e,i=typeof a=="function"?a({value:t,selection:e}):a;return{value:t,selection:i==="replace"?[s,s+n.length]:[s,r]}}function I(t){return typeof t=="string"}function O(t,e,n,a){let s="";for(let r=e.length;r<t.length;r++){const i=t[r],l=(a==null?void 0:a.value[r])===i;if(!I(i)||i===n&&!l)return s;s+=i}return s}function H(t,e){return Array.isArray(e)?t.length===e.length&&Array.from(t).every((n,a)=>{const s=e[a];return I(s)?n===s:n.match(s)}):e.test(t)}function ie(t,e,n){let a=null,s=null;const r=Array.from(t.value).reduce((l,o,c)=>{const u=O(e,l,o,n),d=l+u,h=e[d.length];return I(h)?d+h:o.match(h)?(a===null&&c>=t.selection[0]&&(a=d.length),s===null&&c>=t.selection[1]&&(s=d.length),d+o):d},""),i=O(e,r,"",n);return{value:H(r+i,e)?r+i:r,selection:[a??r.length,s??r.length]}}function le({value:t,selection:e},n){const[a,s]=e;let r=a,i=s;return{value:Array.from(t).reduce((l,o,c)=>{const u=l+o;return a===c&&(r=l.length),s===c&&(i=l.length),u.match(n)?u:l},""),selection:[r,i]}}function A(t,e,n=null){if(H(t.value,e))return t;const{value:a,selection:s}=Array.isArray(e)?ie(t,e,n):le(t,e);return{selection:s,value:Array.isArray(e)?a.slice(0,e.length):a}}function R(t,e){if(!Array.isArray(e))return t;const[n,a]=t.selection,s=[],r=Array.from(t.value).reduce((i,l,o)=>{const c=e[o];return o===n&&s.push(i.length),o===a&&s.push(i.length),I(c)&&c===l?i:i+l},"");return s.length<2&&s.push(...new Array(2-s.length).fill(r.length)),{value:r,selection:[s[0],s[1]]}}class D{constructor(e,n){this.initialElementState=e,this.maskOptions=n,this.value="",this.selection=[0,0];const{value:a,selection:s}=A(this.initialElementState,this.getMaskExpression(this.initialElementState));this.value=a,this.selection=s}addCharacters([e,n],a){const{value:s}=this,r=this.getMaskExpression({value:s.slice(0,e)+a+s.slice(n),selection:[e+a.length,e+a.length]}),i={value:s,selection:[e,n]},l=R(i,r),[o,c]=re(l,a,this.maskOptions.overwriteMode).selection,u=l.value.slice(0,o)+a,d=u.length,h=A({value:u+l.value.slice(c),selection:[d,d]},r,i);if(s.slice(0,o)===A({value:u,selection:[d,d]},r,i).value||se(this,h))throw new Error("Invalid mask value");this.value=h.value,this.selection=h.selection}deleteCharacters([e,n]){if(e===n||!n)return;const{value:a}=this,s=this.getMaskExpression({value:a.slice(0,e)+a.slice(n),selection:[e,e]}),r={value:a,selection:[e,n]},i=R(r,s),[l,o]=i.selection,c=i.value.slice(0,l)+i.value.slice(o),u=A({value:c,selection:[l,l]},s,r);this.value=u.value,this.selection=u.selection}getMaskExpression(e){const{mask:n}=this.maskOptions;return typeof n=="function"?n(e):n}}class oe{constructor(e){this.element=e,this.listeners=[]}listen(e,n,a){const s=n;this.element.addEventListener(e,s,a),this.listeners.push(()=>this.element.removeEventListener(e,s))}destroy(){this.listeners.forEach(e=>e())}}const g={CTRL:1,ALT:2,SHIF
`)+1||t.length:t.slice(0,s).lastIndexOf(`
`)+1;return[n?a:r,n?r:s]}function he({value:t,selection:e},n){const[a,s]=e;return a!==s?[a,s]:(n?[a,s+1]:[a-1,s]).map(r=>Math.min(Math.max(r,0),t.length))}const me=/\s+$/g,pe=/^\s+/g,j=/\s/;function ve({value:t,selection:e},n){const[a,s]=e;if(a!==s)return[a,s];if(n){const o=t.slice(a),[c]=o.match(pe)||[""],u=o.trimStart().search(j);return[a,u!==-1?a+c.length+u:t.length]}const r=t.slice(0,s),[i]=r.match(me)||[""],l=r.trimEnd().split("").reverse().findIndex(o=>o.match(j));return[l!==-1?s-i.length-l:0,s]}function k(t=[]){return(e,...n)=>t.reduce((a,s)=>Object.assign(Object.assign({},a),s(a,...n)),e)}function ge(t,e){const n=Object.assign(Object.assign({},B),e),a=k(n.preprocessors),s=k(n.postprocessors),r=typeof t=="string"?{value:t,selection:[0,0]}:t,{elementState:i}=a({elementState:r,data:""},"validation"),l=new D(i,n),{value:o,selection:c}=s(l,r);return typeof t=="string"?o:{value:o,selection:c}}class M extends ne{constructor(e,n){super(),this.element=e,this.maskitoOptions=n,this.isTextArea=this.element.nodeName==="TEXTAREA",this.eventListener=new oe(this.element),this.options=Object.assign(Object.assign({},B),this.maskitoOptions),this.preprocessor=k(this.options.preprocessors),this.postprocessor=k(this.options.postprocessors),this.teardowns=this.options.plugins.map(a=>a(this.element,this.options)),this.updateHistory(this.elementState),this.eventListener.listen("keydown",a=>{if(ce(a))return a.preventDefault(),this.redo();if(ue(a))return a.preventDefault(),this.undo()}),this.eventListener.listen("beforeinput",a=>{var s;const r=a.inputType.includes("Forward");switch(this.updateHistory(this.elementState),a.inputType){case"historyUndo":return a.preventDefault(),this.undo();case"historyRedo":return a.preventDefault(),this.redo();case"deleteByCut":case"deleteContentBackward":case"deleteContentForward":return this.handleDelete({event:a,isForward:r,selection:he(this.elementState,r)});case"deleteWordForward":case"deleteWordBackward":return this.handleDelete({event:a,isForward:r,selection:ve(this.elementState,r),force:!0});case"deleteSoftLineBackward":case"deleteSoftLineForward":case"deleteHardLineBackward":case"deleteHardLineForward":return this.handleDelete({event:a,isForward:r,selection:de(this.elementState,r),force:!0});case"insertCompositionText":return;case"insertReplacementText":return;case"insertLineBreak":case"insertParagraph":return this.handleEnter(a);case"insertFromPaste":case"insertText":case"insertFromDrop":default:return this.handleInsert(a,a.data||((s=a.dataTransfer)===null||s===void 0?void 0:s.getData("text/plain"))||"")}}),this.eventListener.listen("input",({inputType:a})=>{a!=="insertCompositionText"&&(this.ensureValueFitsMask(),this.updateHistory(this.elementState))}),this.eventListener.listen("compositionend",()=>{this.ensureValueFitsMask(),this.updateHistory(this.elementState)})}get elementState(){const{value:e,selectionStart:n,selectionEnd:a}=this.element;return{value:e,selection:[n||0,a||0]}}get maxLength(){const{maxLength:e}=this.element;return e===-1?1/0:e}destroy(){this.eventListener.destroy(),this.teardowns.forEach(e=>e==null?void 0:e())}updateElementState({value:e,selection:n},a={inputType:"insertText",data:null}){const s=this.elementState.value;this.updateValue(e),this.updateSelectionRange(n),s!==e&&this.dispatchInputEvent(a)}updateSelectionRange([e,n]){var a;const{element:s}=this;s.matches(":focus")&&(s.selectionStart!==e||s.selectionEnd!==n)&&((a=s.setSelectionRange)===null||a===void 0||a.call(s,e,n))}updateValue(e){this.element.value=e}ensureValueFitsMask(){this.updateElementState(ge(this.elementState,this.options))}dispatchInputEvent(e={inputType:"insertText",data:null}){globalThis.InputEvent&&this.element.dispatchEvent(new InputEvent("input",Object.assign(Object.assign({},e),{bubbles:!0,cancelable:!1})))}handleDelete({event:e,selection:n,isForward:a,force:s=!1}){const r={value:this.elementState.value,selection:n},[i,l]=r.selection,{elementState:o}=this.preprocessor({elementState:r,data:""},a?"deleteForward":"deleteBackward"),c=new D(o,this.options),[u,d]=o.selection;c.deleteCharacters([u,d]);cons
`)}}function fe(t,e,n){const a=Math.min(Number(n),Math.max(Number(e),Number(t)));return t instanceof Date?new Date(a):a}function ye(t){return t.replaceAll(/\W/g,"").length}const V=t=>{var e,n,a;return{day:((e=t.match(/d/g))===null||e===void 0?void 0:e.length)||0,month:((n=t.match(/m/g))===null||n===void 0?void 0:n.length)||0,year:((a=t.match(/y/g))===null||a===void 0?void 0:a.length)||0}};function Se(t){return{day:String(t.getDate()).padStart(2,"0"),month:String(t.getMonth()+1).padStart(2,"0"),year:String(t.getFullYear()).padStart(4,"0"),hours:String(t.getHours()).padStart(2,"0"),minutes:String(t.getMinutes()).padStart(2,"0"),seconds:String(t.getSeconds()).padStart(2,"0"),milliseconds:String(t.getMilliseconds()).padStart(3,"0")}}function we(t,e){return t.length<e.length?!1:t.split(/\D/).every(n=>!n.match(/^0+$/))}function W(t,e,n){const a=ye(e);return t.replace(n,"").match(new RegExp(`(\\D*\\d[^\\d\\s]*){1,${a}}`,"g"))||[]}function C(t,e){const n=e.replaceAll(/[^dmy]/g,""),a=t.replaceAll(/\D+/g,""),s={day:a.slice(n.indexOf("d"),n.lastIndexOf("d")+1),month:a.slice(n.indexOf("m"),n.lastIndexOf("m")+1),year:a.slice(n.indexOf("y"),n.lastIndexOf("y")+1)};return Object.fromEntries(Object.entries(s).filter(([r,i])=>!!i).sort(([r],[i])=>e.toLowerCase().indexOf(r[0])>e.toLowerCase().indexOf(i[0])?1:-1))}function be(t,e){var n,a,s,r,i,l,o;const c=((n=t.year)===null||n===void 0?void 0:n.length)===2?`20${t.year}`:t.year,u=new Date(Number(c??"0"),Number((a=t.month)!==null&&a!==void 0?a:"1")-1,Number((s=t.day)!==null&&s!==void 0?s:"1"),Number((r=void 0)!==null&&r!==void 0?r:"0"),Number((i=void 0)!==null&&i!==void 0?i:"0"),Number((l=void 0)!==null&&l!==void 0?l:"0"),Number((o=void 0)!==null&&o!==void 0?o:"0"));return u.setFullYear(Number(c??"0")),u}const z=", ";function E({day:t,month:e,year:n,hours:a,minutes:s,seconds:r,milliseconds:i},{dateMode:l,dateTimeSeparator:o=z,timeMode:c}){var u;const d=((u=l.match(/y/g))===null||u===void 0?void 0:u.length)===2?n==null?void 0:n.slice(-2):n;return(l+(c?o+c:"")).replaceAll(/d+/g,t??"").replaceAll(/m+/g,e??"").replaceAll(/y+/g,d??"").replaceAll(/H+/g,a??"").replaceAll("MSS",i??"").replaceAll(/M+/g,s??"").replaceAll(/S+/g,r??"").replaceAll(/^\D+/g,"").replaceAll(/\D+$/g,"")}const K={day:31,month:12,year:9999},Ee=new Date("0001-01-01"),xe=new Date("9999-12-31"),Te=[":","."];function Ae({dateString:t,dateModeTemplate:e,dateSegmentsSeparator:n,offset:a,selection:[s,r]}){const i=C(t,e),l=Object.entries(i),o={};for(const[d,h]of l){const p=E(o,{dateMode:e}),S=K[d],f=p.length&&n.length,v=a+p.length+f+V(e)[d],y=v>=s&&v===r;if(y&&Number(h)>Number(S))return{validatedDateString:"",updatedSelection:[s,r]};if(y&&Number(h)<1)return{validatedDateString:"",updatedSelection:[s,r]};o[d]=h}const c=E(o,{dateMode:e}),u=c.length-t.length;return{validatedDateString:c,updatedSelection:[s+u,r+u]}}const Z=/[\\^$.*+?()[\]{}|]/g,ke=new RegExp(Z.source);function P(t){return t&&ke.test(t)?t.replaceAll(Z,"\\$&"):t}function L(t,e,n=0){return Number(t.padEnd(e.length,"0"))<=Number(e)?{validatedSegmentValue:t,prefixedZeroesCount:n}:t.endsWith("0")?L(`0${t.slice(0,e.length-1)}`,e,n+1):L(`${t.slice(0,e.length-1)}0`,e,n)}function F(t){return t.replaceAll(/[-]/g,e=>String.fromCharCode(e.charCodeAt(0)-65248))}function Ie({dateModeTemplate:t,dateSegmentSeparator:e,splitFn:n,uniteFn:a}){return({value:s,selection:r})=>{var i;const[l,o]=r,{dateStrings:c,restPart:u=""}=n(s),d=[];let h=0;c.forEach(S=>{const f=C(S,t),v=Object.entries(f).reduce((y,[x,_])=>{const{validatedSegmentValue:U,prefixedZeroesCount:X}=L(_,`${K[x]}`);return h+=X,Object.assign(Object.assign({},y),{[x]:U})},{});d.push(E(v,{dateMode:t}))});const p=a(d,s)+(!((i=c[c.length-1])===null||i===void 0)&&i.endsWith(e)?e:"")+u;return h&&p.slice(o+h,o+h+e.length)===e&&(h+=e.length),{selection:[l+h,o+h],value:p}}}function Me(){return({elementState:t,data:e})=>{const{value:n,selection:a}=t;return{elementState:{selection:a,value:F(n)},data:F(e)}}}function De(t,e){const n=V(e);return Object.fromEntries(Object.entries(t).map(([a,s])=>{const r=n[a];return[a,s.length===r&&s.match(/^0
* 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
*/function qe(...t){return new Promise(e=>{if(!t.length){e([]);return}const n=t.map(s=>document.querySelector(s)).filter(Boolean);if(n.length===t.length){e(n);return}const a=new MutationObserver(()=>{const s=t.map(r=>document.querySelector(r)).filter(Boolean);s.length===t.length&&(a.disconnect(),e(s))});a.observe(document.body,{childList:!0,subtree:!0})})}function He(){const t=document.querySelector('meta[name="instant-payment"]');return!!(t&&t instanceof HTMLMetaElement&&t.content==="yes")}/**
* 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 Ve{constructor(e,n){T(this,"handleAuthorization",()=>{var r,i,l,o;if(this.cvvRequired=="1"&&document.getElementById("cvv").value.length<3){const c=document.getElementById("errors");c&&(c.innerText="CVV is required",c.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 n={};n.cardNumber=(r=this.sc.value("number"))==null?void 0:r.replace(/[^\d]/g,""),n.month=(i=this.sc.value("month"))==null?void 0:i.replace(/[^\d]/g,""),n.year=`20${(l=this.sc.value("year"))==null?void 0:l.replace(/[^\d]/g,"")}`,n.cardCode=(o=this.sc.value("cvv"))==null?void 0:o.replace(/[^\d]/g,"");var a={};return a.authData=e,a.cardData=n,document.getElementById("pay-now")&&(document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden")),Accept.dispatchData(a,this.responseHandler),!1});T(this,"responseHandler",e=>{if(e.messages.resultCode==="Error"){var n=0;const a=document.getElementById("errors");a&&(a.innerText=`${e.messages.message[n].code}: ${e.messages.message[n].text}`,a.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")}else if(e.messages.resultCode==="Ok"){document.getElementById("dataDescriptor").value=e.opaqueData.dataDescriptor,document.getElementById("dataValue").value=e.opaqueData.dataValue;let a=document.querySelector("input[name=token-billing-checkbox]:checked");a&&(document.getElementById("store_card").value=a.value),document.getElementById("server_response").submit()}return!1});T(this,"handle",()=>{Array.from(document.getElementsByClassName("toggle-payment-with-token")).forEach(a=>a.addEventListener("click",s=>{document.getElementById("save-card--container").style.display="none",document.getElementById("authorize--credit-card-container").style.display="none",document.getElementById("token").value=s.target.dataset.token}));let e=document.getElementById("toggle-payment-with-credit-card");e&&e.addEventListener("click",()=>{document.getElementById("save-card--container").style.display="grid",document.getElementById("authorize--credit-card-container").style.display="flex",document.getElementById("token").value=null});let n=document.getElementById("pay-now");return n&&n.addEventListener("click",a=>{let s=document.getElementById("token");s.value?this.handlePayNowAction(s.value):this.handleAuthorization()}),this});this.publicKey=e,this.loginId=n,this.cardHolderName=document.getElementById("cardholder_name"),this.sc=new Ne({fields:{card:{number:"#number",date:"#date",cvv:"#cvv"}}}),this.sc.mount(),this.cvvRequired=document.querySelector('meta[name="authnet-require-cvv"]').content}handlePayNowAction(e){document.getElementById("pay-now").disabled=!0,document.querySelector("#pay-now > svg").classList.remove("hidden"),document.querySelector("#pay-now > span").classList.add("hidden"),document.getElementById("token").value=e,document.getElementById("server_response").submit()}}function N(){const t=document.querySelector('meta[name="authorize-public-key"]').content,e=document.querySelector('meta[name="authorize-login-id"]').content;new Ve(t,e).handle()}He()?N():qe("#authorize-net-credit-card-payment").then(()=>N());export{Ne as $,He as i,qe as w};