@test-glide/glide-payment 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,72 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(n,e={}){const t=document.createElement(n),{className:l,id:r,innerHTML:h,textContent:o,attributes:c,styles:d,dataset:a,children:i,events:m}=e;if(l){const u=Array.isArray(l)?l:l.split(" ");t.classList.add(...u.filter(Boolean))}if(r&&(t.id=r),h&&(t.innerHTML=h),o&&(t.textContent=o),c)for(const[u,s]of Object.entries(c))s&&t.setAttribute(u,s);if(d)for(const[u,s]of Object.entries(d))t.style[u]=s;if(a)for(const[u,s]of Object.entries(a))t.dataset[u]=s;if(i&&t.append(...i.filter(Boolean)),m)for(const[u,s]of Object.entries(m))t.addEventListener(u,s);return t}function x(n,e){const t="id"in n?[document.getElementById(n.id)].filter(Boolean):"className"in n?Array.from(document.getElementsByClassName(n.className)):[n.element];if(!t.length){console.warn("updateElements: no elements found for",n);return}for(const l of t){const{styles:r,attributes:h,dataset:o,innerHTML:c,textContent:d,className:a}=e;if(r)for(const[i,m]of Object.entries(r))l.style[i]=m;if(h)for(const[i,m]of Object.entries(h))l.setAttribute(i,m);if(o)for(const[i,m]of Object.entries(o))l.dataset[i]=m;if(c!==void 0&&(l.innerHTML=c),d!==void 0&&(l.textContent=d),a?.add){const i=Array.isArray(a.add)?a.add:[a.add];l.classList.add(...i)}if(a?.remove){const i=Array.isArray(a.remove)?a.remove:[a.remove];l.classList.remove(...i)}a?.toggle&&(Array.isArray(a.toggle)?a.toggle:[a.toggle]).forEach(m=>l.classList.toggle(m))}}const Q=`
2
+ <svg
3
+ xmlns="http://www.w3.org/2000/svg"
4
+ width="16"
5
+ height="16"
6
+ fill="none"
7
+ viewBox="0 0 16 16"
8
+ >
9
+ <path
10
+ fill="#000"
11
+ fill-rule="evenodd"
12
+ d="M8 2.667a2 2 0 0 0-2 2v2h4v-2a2 2 0 0 0-2-2m3.333 4v-2a3.333 3.333 0 0 0-6.666 0v2a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h6.666a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2M4.667 8.001A.667.667 0 0 0 4 8.667v4c0 .369.298.667.667.667h6.666a.667.667 0 0 0 .667-.667v-4a.667.667 0 0 0-.667-.666zm2 2.666a1.333 1.333 0 1 1 2.666 0 1.333 1.333 0 0 1-2.666 0"
13
+ clip-rule="evenodd"
14
+ ></path>
15
+ </svg>
16
+ `,X=`
17
+ <svg
18
+ xmlns="http://www.w3.org/2000/svg"
19
+ width="16"
20
+ height="16"
21
+ fill="none"
22
+ stroke="currentColor"
23
+ stroke-linecap="round"
24
+ stroke-linejoin="round"
25
+ stroke-width="2"
26
+ class="lucide lucide-loader-icon lucide-loader"
27
+ viewBox="0 0 24 24"
28
+ >
29
+ <path d="M12 2v4M16.2 7.8l2.9-2.9M18 12h4M16.2 16.2l2.9 2.9M12 18v4M4.9 19.1l2.9-2.9M2 12h4M4.9 4.9l2.9 2.9"></path>
30
+ </svg>
31
+ `,ee=`<svg
32
+ xmlns="http://www.w3.org/2000/svg"
33
+ width="20"
34
+ height="20"
35
+ fill="none"
36
+ viewBox="0 0 24 24"
37
+ >
38
+ <path
39
+ fill="#071B32"
40
+ d="M9.709 21.493a.44.44 0 0 1-.325-.146l-8.25-9a.533.533 0 0 1 0-.707l8.25-9a.432.432 0 0 1 .648.013.53.53 0 0 1 0 .694l-7.925 8.646 7.925 8.646c.18.195.18.512 0 .707a.44.44 0 0 1-.323.147"
41
+ ></path>
42
+ <path
43
+ fill="#071B32"
44
+ d="M22.542 12.494H1.459c-.253 0-.459-.224-.459-.5s.206-.5.459-.5h21.083c.253 0 .458.224.458.5s-.205.5-.458.5"
45
+ ></path>
46
+ </svg>`,k=`
47
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 256 256"><path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm16-40a8,8,0,0,1-8,8,16,16,0,0,1-16-16V128a8,8,0,0,1,0-16,16,16,0,0,1,16,16v40A8,8,0,0,1,144,176ZM112,84a12,12,0,1,1,12,12A12,12,0,0,1,112,84Z"></path></svg>
48
+ `,te=({children:n,onClick:e,disabled:t=!1,size:l="medium",type:r="button",className:h="",variant:o="primary"})=>{const c=p("span",{className:"button-spinner",innerHTML:X,dataset:{show:"false"}}),d=p("span",{className:"button-label",children:[null],textContent:n}),a=p("button",{className:`custom-button ${o} ${l} ${h}`,attributes:{type:r,...t?{disabled:"true"}:{}},events:{click:e},children:[c,d]}),i=(u=!1)=>{x({element:c},{dataset:{show:String(u)}}),m(u)},m=(u=!1)=>{u?a.setAttribute("disabled","true"):a.removeAttribute("disabled")};return{element:a,setLoading:i,setDisabled:m}},ne=({content:n,position:e="top",delay:t=200,maxWidth:l=250,className:r="",id:h=""})=>{var o=p("div",{className:`tooltip ${e} ${r}`,styles:{maxWidth:`${l}px`},attributes:{role:"tooltip"},dataset:{show:"false"},innerHTML:`
49
+ <div class="tooltip-content">${n}</div>
50
+ <div class="tooltip-arrow"></div>
51
+ `});let c=null;var i=p("span",{className:"tooltip-trigger",innerHTML:k,events:{mouseenter:()=>{t>0?c=window.setTimeout(()=>{o.dataset.show="true",m()},t):(o.dataset.show="true",m())},mouseleave:()=>{c&&clearTimeout(c),o.dataset.show="false"}}});function m(){if(!i||!o)return;const s=i.getBoundingClientRect(),v=o.getBoundingClientRect(),y=8;let w,g;switch(e){case"top":w=s.top-v.height-y,g=s.left+s.width/2-v.width/2;break;case"bottom":w=s.bottom+y,g=s.left+s.width/2-v.width/2;break;case"left":w=s.top+s.height/2-v.height/2,g=s.left-v.width-y;break;case"right":w=s.top+s.height/2-v.height/2,g=s.right+y;break;default:w=s.top-v.height-y,g=s.left+s.width/2-v.width/2}const N=window.innerWidth,C=window.innerHeight;g<0&&(g=y),g+v.width>N&&(g=N-v.width-y),w<0&&(w=y),w+v.height>C&&(w=C-v.height-y),o.style.top=`${w}px`,o.style.left=`${g}px`}return p("div",{className:"tooltip-wrapper",id:`tooltip-${h}`,children:[i,o]})},se=n=>{const e={},t=Object.values(n).every(r=>!r||r.trim()===""),l=n.cardNumber?.replace(/\s/g,"");if(l?/^\d{13,19}$/.test(l)||(e.cardNumber="Card number must be 13-19 digits"):e.cardNumber="Card number is required",!n.expiryDate)e.expiryDate="Expiry date is required";else{const r=n.expiryDate.replace(/\D/g,"");if(r.length<4)e.expiryDate="Enter complete expiry date (MM/YY)";else{const h=parseInt(r.substring(0,2),10),o=parseInt(r.substring(2,4),10);if(isNaN(h)||h<1||h>12)e.expiryDate="Invalid month (must be 01-12)";else if(isNaN(o)||o<0||o>99)e.expiryDate="Invalid year";else{const c=new Date,d=c.getFullYear(),a=c.getMonth()+1,i=Math.floor(d/100)*100,m=i+o,u=i+100+o;let s;m>=d&&m<=d+20?s=m:(u>=d&&u<=d+20,s=u),s<d||s===d&&h<a?e.expiryDate="Card has expired":s>d+20&&(e.expiryDate="Expiry year is too far in the future")}}}return n.cvv?.trim()?/^\d{3,4}$/.test(n.cvv.trim())||(e.cvv="CVV must be 3 or 4 digits"):e.cvv="CVV is required",n.zipCode?.trim()?/^[A-Z0-9\s-]{3,10}$/i.test(n.zipCode.trim())||(e.zipCode="Invalid ZIP code format"):e.zipCode="Postal code is required",{isValid:Object.keys(e).length===0,errors:e,isEmpty:t}};function re(n){const e=parseInt(n,10);if(isNaN(e)||e<0||e>99)return null;const t=new Date().getFullYear(),l=Math.floor(t/100)*100;let r=l+e;return r>=t&&r<=t+20||(r=l+100+e,r>=t&&r<=t+20)?r:l+100+e}function V(n=""){return n.trim().replaceAll(/\s/g,"").replaceAll("-","")}const oe={card:n=>n.replace(/\s+/g,"").replace(/[^0-9]/gi,"").substring(0,16).match(/.{1,4}/g)?.join(" ")??"",phone:n=>{const e=n.replace(/\D/g,"").substring(0,10),t=e.match(/^(\d{3})(\d{3})(\d{4})$/);return t?`(${t[1]}) ${t[2]}-${t[3]}`:e},expiry:n=>{const e=n.replace(/\//g,"");return e.substring(0,2)+(n.length>2?"/":"")+e.substring(2,4)},cvv:n=>n.replace(/\D/g,"").substring(0,4),zip:n=>{const e=n.replace(/\D/g,"").substring(0,9);return e.length>5?`${e.substring(0,5)}-${e.substring(5)}`:e}};function ae(n,e){return e==="none"?n:oe[e](n)}const $=({label:n,maskType:e,id:t,name:l,type:r="text",placeholder:h="Enter value",tooltip:o="",onChange:c})=>{const d=["card","expiry","phone","cvv","zip"].includes(e)?"numeric":"",a=p("label",{className:"input-label",innerHTML:n,attributes:{for:t}});let i=!1;const u=p("input",{id:t||"input-id",className:"styled-input",attributes:{placeholder:h,type:r,inputMode:d,name:l},events:{input:s,blur:v,keydown:b=>{b.key==="Enter"&&(i=!0)}}});function s(b){const D=e!=="none"?ae(b?.target?.value,e):b?.target?.value;u.value=D,c?.(D)}function v(){i=!0,c?.(u?.value||"")}const y=p("div",{className:"input-loader",innerHTML:'<div class="loader"></div>',dataset:{show:"false"}}),w=o?p("div",{className:"input-right-element",children:[ne({content:o,id:t})]}):null,g=p("div",{className:"input-wrapper",children:[u,y,w]}),N=p("div",{className:"error-message",dataset:{show:"false"},innerHTML:`
52
+ ${k}
53
+ <span></span>
54
+ `});return{element:p("div",{className:"custom-input-group",children:[a,g,N]}),setLoading:b=>{x({element:g},{dataset:{loading:b?"true":"false"}}),x({element:u},{attributes:{disabled:b?"true":"false"}}),x({element:y},{dataset:{show:b?"true":"false"}})},setError:(b="")=>{x({element:g},{className:b&&i?{add:"input-error"}:{remove:"input-error"}}),x({element:N},{dataset:{show:b&&i?"true":"false"},innerHTML:`
55
+ ${k}
56
+ <span>${b||""}</span>
57
+ `})}}},ie=async(n,e={})=>{const{method:t="GET",headers:l={},body:r=null,...h}=e;try{const o={method:t,headers:{Accept:"*/*","Content-Type":"application/json",...l},...h};r&&["POST","PUT","PATCH","DELETE"].includes(t.toUpperCase())&&(o.body=typeof r=="string"?r:JSON.stringify(r));const c=await fetch(n,o),d=c.headers.get("content-type");let a;if(d?.includes("application/json")?a=await c.json():a=await c.text(),!c.ok){const i=a;throw new Error(i?.message||`HTTP error! status: ${c.status}`)}return{data:a,error:null}}catch(o){return{data:null,error:o instanceof Error?o.message:"An error occurred"}}},le=({title:n="",children:e,onClose:t,showBackBtn:l=!1,showCloseBtn:r=!0})=>{const h=p("button",{className:"back-btn",innerHTML:ee,dataset:{show:String(l)},events:{click:()=>m()}}),o=p("h3",{textContent:n}),c=p("button",{className:"close-btn",innerHTML:"&times;",dataset:{show:String(r)},attributes:{"aria-label":"Close modal"},events:{click:()=>m()}}),d=p("div",{className:"modal-header",children:[h,o,c]}),a=p("div",{className:"modal-content",children:[e]}),i=p("dialog",{className:"custom-modal",children:[d,a],events:{cancel:s=>{s.preventDefault(),m()}}}),m=()=>{i.close(),t?.()};return{element:i,setModalVisibility:s=>{s?i.showModal():i.close()}}},ce=({token:n,endpoint:e,beneficiaryCard:t=!1,isModal:l=!1,onCallback:r=()=>null})=>{const h=t?"Enter Recipient Debit Card Details":"Enter Your Debit Card Details",o=t?"Enter the debit card details of the recipient you're sending funds to.":"Linking an external account allows you to send and receive money to your account.",c=t?"Debit Card Number":"Your Debit Card Number",d=t?"Enter recipient's card number":"Enter your card number",a=`add-card-form-wrapper${t?" recipient-form":""}`,i={cardNumber:"",expiryDate:"",cvv:"",zipCode:""},{element:m,setError:u}=$({label:c,placeholder:d,id:"card-number-input",name:"cardNumber",maskType:"card",onChange(f){L("cardNumber",f,u)}}),{element:s,setError:v}=$({label:"Expiration Date",placeholder:"MM/YY",id:"expiry-input",name:"expiryDate",maskType:"expiry",onChange(f){L("expiryDate",f,v)}}),{element:y,setError:w}=$({label:"CVV",placeholder:"3-Digit",type:"number",maskType:"cvv",id:"cvv-input",name:"cvv",tooltip:"A CVV is a 3-digit number on your debit card. You can find it on the back side of the card.",onChange(f){L("cvv",f,w)}}),{element:g,setError:N}=$({label:"ZIP Code",placeholder:t?"ZIP Code":"Enter your ZIP Code",id:"zip-input",name:"zipCode",maskType:"zip",onChange(f){L("zipCode",f,N)}}),C=p("div",{className:t?"input-sections":"inputs",children:[m,s,y,g]}),A=p("p",{className:"submit-error",dataset:{show:"false"}}),{element:j,setDisabled:b,setLoading:D}=te({children:"Link Card",type:"submit",disabled:!0}),S=(f="")=>{x({element:A},{dataset:{show:String(!!f)},innerHTML:`
58
+ ${k}
59
+ ${f||""}
60
+ `})},B=(f=!0)=>{b(f),D(f)};function L(f,H,E){i[f]=H;const{isValid:I,errors:T}=se(i);T[f]?E(T[f]):E(""),b(!I)}const O=p("div",{className:"submit-button-wrapper",children:[A,j]});async function P(f){f.preventDefault();const H=new FormData(f.target),E=Object.fromEntries(H.entries());console.log(E);const I=E?.cardNumber,T=E?.expiryDate,_=E?.cvv,G=E?.zipCode,K=Number(T?.split("/")[0]),U=re(T?.split("/")[1]),J=V(I);B(!0),S("");const M=await ie(e,{method:"POST",body:{token:n,pan:J,expiry_month:K,expiry_year:U,cvv:V(_),address:{postal_code:V(G)}}});M.error?(console.error("Request failed:",M.error),B(!1),S(M.error),r?.({success:!1,error:M.error})):(console.log("Request success:",M.data),B(!1),r?.({success:!0,data:M.data}))}const Z=()=>p("form",{events:{submit:P},children:[C,O]}),W=()=>p("div",{className:"form-title",innerHTML:`
61
+ <p>${o}</p>
62
+
63
+ <div>
64
+ ${Q}
65
+
66
+ <span>Secured with 256-bit encryption</span>
67
+ </div>
68
+ `}),z=()=>p("div",{className:l?"":"non-modal-content",children:[W(),Z()]}),q=l?null:p("div",{className:`${a} non-modal`,children:[p("div",{className:"non-modal-header",innerHTML:`
69
+ <span></span>
70
+ <h3>${h}</h3>
71
+ <span></span>
72
+ `}),z()]}),{element:Y,setModalVisibility:F}=l?le({title:h,children:z()}):{element:null,setModalVisibility:()=>{}};function R(){Y&&(document.body.appendChild(p("div",{className:a,children:[Y]})),F(!0))}return{renderFormWithModal:R,nonModalForm:q,closeModal:()=>F(!1)}};function de({token:n,endpoint:e,beneficiaryCard:t,isModal:l,onCallback:r}){const{renderFormWithModal:h,nonModalForm:o,closeModal:c}=ce({token:n,endpoint:e,beneficiaryCard:t,isModal:l,onCallback:r});return{mount(d){const a="className"in d?document.querySelector(d.className):"id"in d?document.getElementById(d.id):d.element;a&&o&&a.appendChild(o)},open(){h()},destroy(){c()}}}exports.init=de;
@@ -0,0 +1,578 @@
1
+ function p(n, e = {}) {
2
+ const t = document.createElement(n), { className: l, id: r, innerHTML: h, textContent: o, attributes: c, styles: d, dataset: a, children: i, events: m } = e;
3
+ if (l) {
4
+ const u = Array.isArray(l) ? l : l.split(" ");
5
+ t.classList.add(...u.filter(Boolean));
6
+ }
7
+ if (r && (t.id = r), h && (t.innerHTML = h), o && (t.textContent = o), c)
8
+ for (const [u, s] of Object.entries(c))
9
+ s && t.setAttribute(u, s);
10
+ if (d)
11
+ for (const [u, s] of Object.entries(d))
12
+ t.style[u] = s;
13
+ if (a)
14
+ for (const [u, s] of Object.entries(a))
15
+ t.dataset[u] = s;
16
+ if (i && t.append(...i.filter(Boolean)), m)
17
+ for (const [u, s] of Object.entries(m))
18
+ t.addEventListener(u, s);
19
+ return t;
20
+ }
21
+ function x(n, e) {
22
+ const t = "id" in n ? [document.getElementById(n.id)].filter(Boolean) : "className" in n ? Array.from(document.getElementsByClassName(n.className)) : [n.element];
23
+ if (!t.length) {
24
+ console.warn("updateElements: no elements found for", n);
25
+ return;
26
+ }
27
+ for (const l of t) {
28
+ const { styles: r, attributes: h, dataset: o, innerHTML: c, textContent: d, className: a } = e;
29
+ if (r)
30
+ for (const [i, m] of Object.entries(r))
31
+ l.style[i] = m;
32
+ if (h)
33
+ for (const [i, m] of Object.entries(h))
34
+ l.setAttribute(i, m);
35
+ if (o)
36
+ for (const [i, m] of Object.entries(o))
37
+ l.dataset[i] = m;
38
+ if (c !== void 0 && (l.innerHTML = c), d !== void 0 && (l.textContent = d), a?.add) {
39
+ const i = Array.isArray(a.add) ? a.add : [a.add];
40
+ l.classList.add(...i);
41
+ }
42
+ if (a?.remove) {
43
+ const i = Array.isArray(a.remove) ? a.remove : [a.remove];
44
+ l.classList.remove(...i);
45
+ }
46
+ a?.toggle && (Array.isArray(a.toggle) ? a.toggle : [a.toggle]).forEach((m) => l.classList.toggle(m));
47
+ }
48
+ }
49
+ const Q = `
50
+ <svg
51
+ xmlns="http://www.w3.org/2000/svg"
52
+ width="16"
53
+ height="16"
54
+ fill="none"
55
+ viewBox="0 0 16 16"
56
+ >
57
+ <path
58
+ fill="#000"
59
+ fill-rule="evenodd"
60
+ d="M8 2.667a2 2 0 0 0-2 2v2h4v-2a2 2 0 0 0-2-2m3.333 4v-2a3.333 3.333 0 0 0-6.666 0v2a2 2 0 0 0-2 2v4a2 2 0 0 0 2 2h6.666a2 2 0 0 0 2-2v-4a2 2 0 0 0-2-2M4.667 8.001A.667.667 0 0 0 4 8.667v4c0 .369.298.667.667.667h6.666a.667.667 0 0 0 .667-.667v-4a.667.667 0 0 0-.667-.666zm2 2.666a1.333 1.333 0 1 1 2.666 0 1.333 1.333 0 0 1-2.666 0"
61
+ clip-rule="evenodd"
62
+ ></path>
63
+ </svg>
64
+ `, X = `
65
+ <svg
66
+ xmlns="http://www.w3.org/2000/svg"
67
+ width="16"
68
+ height="16"
69
+ fill="none"
70
+ stroke="currentColor"
71
+ stroke-linecap="round"
72
+ stroke-linejoin="round"
73
+ stroke-width="2"
74
+ class="lucide lucide-loader-icon lucide-loader"
75
+ viewBox="0 0 24 24"
76
+ >
77
+ <path d="M12 2v4M16.2 7.8l2.9-2.9M18 12h4M16.2 16.2l2.9 2.9M12 18v4M4.9 19.1l2.9-2.9M2 12h4M4.9 4.9l2.9 2.9"></path>
78
+ </svg>
79
+ `, ee = `<svg
80
+ xmlns="http://www.w3.org/2000/svg"
81
+ width="20"
82
+ height="20"
83
+ fill="none"
84
+ viewBox="0 0 24 24"
85
+ >
86
+ <path
87
+ fill="#071B32"
88
+ d="M9.709 21.493a.44.44 0 0 1-.325-.146l-8.25-9a.533.533 0 0 1 0-.707l8.25-9a.432.432 0 0 1 .648.013.53.53 0 0 1 0 .694l-7.925 8.646 7.925 8.646c.18.195.18.512 0 .707a.44.44 0 0 1-.323.147"
89
+ ></path>
90
+ <path
91
+ fill="#071B32"
92
+ d="M22.542 12.494H1.459c-.253 0-.459-.224-.459-.5s.206-.5.459-.5h21.083c.253 0 .458.224.458.5s-.205.5-.458.5"
93
+ ></path>
94
+ </svg>`, k = `
95
+ <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 256 256"><path d="M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Zm16-40a8,8,0,0,1-8,8,16,16,0,0,1-16-16V128a8,8,0,0,1,0-16,16,16,0,0,1,16,16v40A8,8,0,0,1,144,176ZM112,84a12,12,0,1,1,12,12A12,12,0,0,1,112,84Z"></path></svg>
96
+ `, te = ({ children: n, onClick: e, disabled: t = !1, size: l = "medium", type: r = "button", className: h = "", variant: o = "primary" }) => {
97
+ const c = p("span", {
98
+ className: "button-spinner",
99
+ innerHTML: X,
100
+ dataset: { show: "false" }
101
+ }), d = p("span", {
102
+ className: "button-label",
103
+ children: [
104
+ null
105
+ ],
106
+ textContent: n
107
+ }), a = p("button", {
108
+ className: `custom-button ${o} ${l} ${h}`,
109
+ attributes: {
110
+ type: r,
111
+ ...t ? { disabled: "true" } : {}
112
+ },
113
+ events: {
114
+ click: e
115
+ },
116
+ children: [
117
+ c,
118
+ d
119
+ ]
120
+ }), i = (u = !1) => {
121
+ x({ element: c }, {
122
+ dataset: { show: String(u) }
123
+ }), m(u);
124
+ }, m = (u = !1) => {
125
+ u ? a.setAttribute("disabled", "true") : a.removeAttribute("disabled");
126
+ };
127
+ return {
128
+ element: a,
129
+ setLoading: i,
130
+ setDisabled: m
131
+ };
132
+ }, ne = ({ content: n, position: e = "top", delay: t = 200, maxWidth: l = 250, className: r = "", id: h = "" }) => {
133
+ var o = p("div", {
134
+ className: `tooltip ${e} ${r}`,
135
+ styles: {
136
+ // top: `${tooltipPosition.top}px`,
137
+ // left: `${tooltipPosition.left}px`,
138
+ maxWidth: `${l}px`
139
+ },
140
+ attributes: {
141
+ role: "tooltip"
142
+ },
143
+ dataset: { show: "false" },
144
+ innerHTML: `
145
+ <div class="tooltip-content">${n}</div>
146
+ <div class="tooltip-arrow"></div>
147
+ `
148
+ });
149
+ let c = null;
150
+ var i = p("span", {
151
+ className: "tooltip-trigger",
152
+ innerHTML: k,
153
+ events: {
154
+ mouseenter: () => {
155
+ t > 0 ? c = window.setTimeout(() => {
156
+ o.dataset.show = "true", m();
157
+ }, t) : (o.dataset.show = "true", m());
158
+ },
159
+ mouseleave: () => {
160
+ c && clearTimeout(c), o.dataset.show = "false";
161
+ }
162
+ }
163
+ });
164
+ function m() {
165
+ if (!i || !o) return;
166
+ const s = i.getBoundingClientRect(), v = o.getBoundingClientRect(), y = 8;
167
+ let w, g;
168
+ switch (e) {
169
+ case "top":
170
+ w = s.top - v.height - y, g = s.left + s.width / 2 - v.width / 2;
171
+ break;
172
+ case "bottom":
173
+ w = s.bottom + y, g = s.left + s.width / 2 - v.width / 2;
174
+ break;
175
+ case "left":
176
+ w = s.top + s.height / 2 - v.height / 2, g = s.left - v.width - y;
177
+ break;
178
+ case "right":
179
+ w = s.top + s.height / 2 - v.height / 2, g = s.right + y;
180
+ break;
181
+ default:
182
+ w = s.top - v.height - y, g = s.left + s.width / 2 - v.width / 2;
183
+ }
184
+ const N = window.innerWidth, M = window.innerHeight;
185
+ g < 0 && (g = y), g + v.width > N && (g = N - v.width - y), w < 0 && (w = y), w + v.height > M && (w = M - v.height - y), o.style.top = `${w}px`, o.style.left = `${g}px`;
186
+ }
187
+ return p("div", {
188
+ className: "tooltip-wrapper",
189
+ id: `tooltip-${h}`,
190
+ children: [
191
+ i,
192
+ o
193
+ ]
194
+ });
195
+ }, se = (n) => {
196
+ const e = {}, t = Object.values(n).every(
197
+ (r) => !r || r.trim() === ""
198
+ ), l = n.cardNumber?.replace(/\s/g, "");
199
+ if (l ? /^\d{13,19}$/.test(l) || (e.cardNumber = "Card number must be 13-19 digits") : e.cardNumber = "Card number is required", !n.expiryDate)
200
+ e.expiryDate = "Expiry date is required";
201
+ else {
202
+ const r = n.expiryDate.replace(/\D/g, "");
203
+ if (r.length < 4)
204
+ e.expiryDate = "Enter complete expiry date (MM/YY)";
205
+ else {
206
+ const h = parseInt(r.substring(0, 2), 10), o = parseInt(r.substring(2, 4), 10);
207
+ if (isNaN(h) || h < 1 || h > 12)
208
+ e.expiryDate = "Invalid month (must be 01-12)";
209
+ else if (isNaN(o) || o < 0 || o > 99)
210
+ e.expiryDate = "Invalid year";
211
+ else {
212
+ const c = /* @__PURE__ */ new Date(), d = c.getFullYear(), a = c.getMonth() + 1, i = Math.floor(d / 100) * 100, m = i + o, u = i + 100 + o;
213
+ let s;
214
+ m >= d && m <= d + 20 ? s = m : (u >= d && u <= d + 20, s = u), s < d || s === d && h < a ? e.expiryDate = "Card has expired" : s > d + 20 && (e.expiryDate = "Expiry year is too far in the future");
215
+ }
216
+ }
217
+ }
218
+ return n.cvv?.trim() ? /^\d{3,4}$/.test(n.cvv.trim()) || (e.cvv = "CVV must be 3 or 4 digits") : e.cvv = "CVV is required", n.zipCode?.trim() ? /^[A-Z0-9\s-]{3,10}$/i.test(n.zipCode.trim()) || (e.zipCode = "Invalid ZIP code format") : e.zipCode = "Postal code is required", {
219
+ isValid: Object.keys(e).length === 0,
220
+ errors: e,
221
+ isEmpty: t
222
+ };
223
+ };
224
+ function re(n) {
225
+ const e = parseInt(n, 10);
226
+ if (isNaN(e) || e < 0 || e > 99) return null;
227
+ const t = (/* @__PURE__ */ new Date()).getFullYear(), l = Math.floor(t / 100) * 100;
228
+ let r = l + e;
229
+ return r >= t && r <= t + 20 || (r = l + 100 + e, r >= t && r <= t + 20) ? r : l + 100 + e;
230
+ }
231
+ function V(n = "") {
232
+ return n.trim().replaceAll(/\s/g, "").replaceAll("-", "");
233
+ }
234
+ const oe = {
235
+ card: (n) => n.replace(/\s+/g, "").replace(/[^0-9]/gi, "").substring(0, 16).match(/.{1,4}/g)?.join(" ") ?? "",
236
+ phone: (n) => {
237
+ const e = n.replace(/\D/g, "").substring(0, 10), t = e.match(/^(\d{3})(\d{3})(\d{4})$/);
238
+ return t ? `(${t[1]}) ${t[2]}-${t[3]}` : e;
239
+ },
240
+ expiry: (n) => {
241
+ const e = n.replace(/\//g, "");
242
+ return e.substring(0, 2) + (n.length > 2 ? "/" : "") + e.substring(2, 4);
243
+ },
244
+ cvv: (n) => n.replace(/\D/g, "").substring(0, 4),
245
+ zip: (n) => {
246
+ const e = n.replace(/\D/g, "").substring(0, 9);
247
+ return e.length > 5 ? `${e.substring(0, 5)}-${e.substring(5)}` : e;
248
+ }
249
+ };
250
+ function ae(n, e) {
251
+ return e === "none" ? n : oe[e](n);
252
+ }
253
+ const $ = ({ label: n, maskType: e, id: t, name: l, type: r = "text", placeholder: h = "Enter value", tooltip: o = "", onChange: c }) => {
254
+ const d = ["card", "expiry", "phone", "cvv", "zip"].includes(e) ? "numeric" : "", a = p("label", {
255
+ className: "input-label",
256
+ innerHTML: n,
257
+ attributes: {
258
+ for: t
259
+ }
260
+ });
261
+ let i = !1;
262
+ const u = p("input", {
263
+ id: t || "input-id",
264
+ className: "styled-input",
265
+ attributes: {
266
+ placeholder: h,
267
+ type: r,
268
+ inputMode: d,
269
+ name: l
270
+ },
271
+ events: {
272
+ input: s,
273
+ blur: v,
274
+ keydown: (b) => {
275
+ b.key === "Enter" && (i = !0);
276
+ }
277
+ }
278
+ });
279
+ function s(b) {
280
+ const D = e !== "none" ? ae(b?.target?.value, e) : b?.target?.value;
281
+ u.value = D, c?.(D);
282
+ }
283
+ function v() {
284
+ i = !0, c?.(u?.value || "");
285
+ }
286
+ const y = p("div", {
287
+ className: "input-loader",
288
+ innerHTML: '<div class="loader"></div>',
289
+ dataset: { show: "false" }
290
+ }), w = o ? p("div", {
291
+ className: "input-right-element",
292
+ children: [
293
+ ne({ content: o, id: t })
294
+ ]
295
+ }) : null, g = p("div", {
296
+ className: "input-wrapper",
297
+ children: [
298
+ u,
299
+ y,
300
+ w
301
+ ]
302
+ }), N = p("div", {
303
+ className: "error-message",
304
+ dataset: { show: "false" },
305
+ innerHTML: `
306
+ ${k}
307
+ <span></span>
308
+ `
309
+ });
310
+ return {
311
+ element: p("div", {
312
+ className: "custom-input-group",
313
+ children: [
314
+ a,
315
+ g,
316
+ N
317
+ ]
318
+ }),
319
+ setLoading: (b) => {
320
+ x({ element: g }, {
321
+ dataset: { loading: b ? "true" : "false" }
322
+ }), x({ element: u }, {
323
+ attributes: { disabled: b ? "true" : "false" }
324
+ }), x({ element: y }, {
325
+ dataset: { show: b ? "true" : "false" }
326
+ });
327
+ },
328
+ setError: (b = "") => {
329
+ x({ element: g }, {
330
+ className: b && i ? { add: "input-error" } : { remove: "input-error" }
331
+ }), x({ element: N }, {
332
+ dataset: { show: b && i ? "true" : "false" },
333
+ innerHTML: `
334
+ ${k}
335
+ <span>${b || ""}</span>
336
+ `
337
+ });
338
+ }
339
+ };
340
+ }, ie = async (n, e = {}) => {
341
+ const { method: t = "GET", headers: l = {}, body: r = null, ...h } = e;
342
+ try {
343
+ const o = {
344
+ method: t,
345
+ headers: {
346
+ Accept: "*/*",
347
+ "Content-Type": "application/json",
348
+ ...l
349
+ },
350
+ ...h
351
+ };
352
+ r && ["POST", "PUT", "PATCH", "DELETE"].includes(t.toUpperCase()) && (o.body = typeof r == "string" ? r : JSON.stringify(r));
353
+ const c = await fetch(n, o), d = c.headers.get("content-type");
354
+ let a;
355
+ if (d?.includes("application/json") ? a = await c.json() : a = await c.text(), !c.ok) {
356
+ const i = a;
357
+ throw new Error(
358
+ i?.message || `HTTP error! status: ${c.status}`
359
+ );
360
+ }
361
+ return { data: a, error: null };
362
+ } catch (o) {
363
+ return { data: null, error: o instanceof Error ? o.message : "An error occurred" };
364
+ }
365
+ }, le = ({
366
+ title: n = "",
367
+ children: e,
368
+ onClose: t,
369
+ showBackBtn: l = !1,
370
+ showCloseBtn: r = !0
371
+ }) => {
372
+ const h = p("button", {
373
+ className: "back-btn",
374
+ innerHTML: ee,
375
+ dataset: { show: String(l) },
376
+ events: { click: () => m() }
377
+ }), o = p("h3", {
378
+ textContent: n
379
+ }), c = p("button", {
380
+ className: "close-btn",
381
+ innerHTML: "&times;",
382
+ dataset: { show: String(r) },
383
+ attributes: { "aria-label": "Close modal" },
384
+ events: { click: () => m() }
385
+ }), d = p("div", {
386
+ className: "modal-header",
387
+ children: [h, o, c]
388
+ }), a = p("div", {
389
+ className: "modal-content",
390
+ children: [e]
391
+ }), i = p("dialog", {
392
+ className: "custom-modal",
393
+ children: [d, a],
394
+ events: {
395
+ cancel: (s) => {
396
+ s.preventDefault(), m();
397
+ }
398
+ }
399
+ }), m = () => {
400
+ i.close(), t?.();
401
+ };
402
+ return {
403
+ element: i,
404
+ setModalVisibility: (s) => {
405
+ s ? i.showModal() : i.close();
406
+ }
407
+ };
408
+ }, ce = ({ token: n, endpoint: e, beneficiaryCard: t = !1, isModal: l = !1, onCallback: r = () => null }) => {
409
+ const h = t ? "Enter Recipient Debit Card Details" : "Enter Your Debit Card Details", o = t ? "Enter the debit card details of the recipient you're sending funds to." : "Linking an external account allows you to send and receive money to your account.", c = t ? "Debit Card Number" : "Your Debit Card Number", d = t ? "Enter recipient's card number" : "Enter your card number", a = `add-card-form-wrapper${t ? " recipient-form" : ""}`, i = {
410
+ cardNumber: "",
411
+ expiryDate: "",
412
+ cvv: "",
413
+ zipCode: ""
414
+ }, { element: m, setError: u } = $({
415
+ label: c,
416
+ placeholder: d,
417
+ id: "card-number-input",
418
+ name: "cardNumber",
419
+ maskType: "card",
420
+ onChange(f) {
421
+ L("cardNumber", f, u);
422
+ }
423
+ }), { element: s, setError: v } = $({
424
+ label: "Expiration Date",
425
+ placeholder: "MM/YY",
426
+ id: "expiry-input",
427
+ name: "expiryDate",
428
+ maskType: "expiry",
429
+ onChange(f) {
430
+ L("expiryDate", f, v);
431
+ }
432
+ }), { element: y, setError: w } = $({
433
+ label: "CVV",
434
+ placeholder: "3-Digit",
435
+ type: "number",
436
+ maskType: "cvv",
437
+ id: "cvv-input",
438
+ name: "cvv",
439
+ tooltip: "A CVV is a 3-digit number on your debit card. You can find it on the back side of the card.",
440
+ onChange(f) {
441
+ L("cvv", f, w);
442
+ }
443
+ }), { element: g, setError: N } = $({
444
+ label: "ZIP Code",
445
+ placeholder: t ? "ZIP Code" : "Enter your ZIP Code",
446
+ id: "zip-input",
447
+ name: "zipCode",
448
+ maskType: "zip",
449
+ onChange(f) {
450
+ L("zipCode", f, N);
451
+ }
452
+ }), M = p("div", {
453
+ className: t ? "input-sections" : "inputs",
454
+ children: [m, s, y, g]
455
+ }), A = p("p", {
456
+ className: "submit-error",
457
+ dataset: { show: "false" }
458
+ // innerHTML: `//icon`
459
+ }), { element: j, setDisabled: b, setLoading: D } = te({
460
+ children: "Link Card",
461
+ type: "submit",
462
+ disabled: !0
463
+ }), z = (f = "") => {
464
+ x({ element: A }, {
465
+ dataset: { show: String(!!f) },
466
+ innerHTML: `
467
+ ${k}
468
+ ${f || ""}
469
+ `
470
+ });
471
+ }, B = (f = !0) => {
472
+ b(f), D(f);
473
+ };
474
+ function L(f, H, E) {
475
+ i[f] = H;
476
+ const { isValid: I, errors: T } = se(i);
477
+ T[f] ? E(T[f]) : E(""), b(!I);
478
+ }
479
+ const O = p("div", {
480
+ className: "submit-button-wrapper",
481
+ children: [A, j]
482
+ });
483
+ async function P(f) {
484
+ f.preventDefault();
485
+ const H = new FormData(f.target), E = Object.fromEntries(H.entries());
486
+ console.log(E);
487
+ const I = E?.cardNumber, T = E?.expiryDate, _ = E?.cvv, G = E?.zipCode, K = Number(T?.split("/")[0]), U = re(T?.split("/")[1]), J = V(I);
488
+ B(!0), z("");
489
+ const C = await ie(e, {
490
+ method: "POST",
491
+ body: {
492
+ token: n,
493
+ pan: J,
494
+ expiry_month: K,
495
+ expiry_year: U,
496
+ cvv: V(_),
497
+ address: {
498
+ postal_code: V(G)
499
+ }
500
+ }
501
+ });
502
+ C.error ? (console.error("Request failed:", C.error), B(!1), z(C.error), r?.({ success: !1, error: C.error })) : (console.log("Request success:", C.data), B(!1), r?.({ success: !0, data: C.data }));
503
+ }
504
+ const Z = () => p("form", {
505
+ events: {
506
+ submit: P
507
+ },
508
+ children: [
509
+ M,
510
+ O
511
+ ]
512
+ }), W = () => p("div", {
513
+ className: "form-title",
514
+ innerHTML: `
515
+ <p>${o}</p>
516
+
517
+ <div>
518
+ ${Q}
519
+
520
+ <span>Secured with 256-bit encryption</span>
521
+ </div>
522
+ `
523
+ }), Y = () => p("div", {
524
+ className: l ? "" : "non-modal-content",
525
+ children: [W(), Z()]
526
+ }), q = l ? null : p("div", {
527
+ className: `${a} non-modal`,
528
+ children: [
529
+ p("div", {
530
+ className: "non-modal-header",
531
+ innerHTML: `
532
+ <span></span>
533
+ <h3>${h}</h3>
534
+ <span></span>
535
+ `
536
+ }),
537
+ Y()
538
+ ]
539
+ }), { element: F, setModalVisibility: S } = l ? le({ title: h, children: Y() }) : { element: null, setModalVisibility: () => {
540
+ } };
541
+ function R() {
542
+ F && (document.body.appendChild(
543
+ p("div", {
544
+ className: a,
545
+ children: [F]
546
+ })
547
+ ), S(!0));
548
+ }
549
+ return {
550
+ renderFormWithModal: R,
551
+ nonModalForm: q,
552
+ closeModal: () => S(!1)
553
+ };
554
+ };
555
+ function de({ token: n, endpoint: e, beneficiaryCard: t, isModal: l, onCallback: r }) {
556
+ const { renderFormWithModal: h, nonModalForm: o, closeModal: c } = ce({
557
+ token: n,
558
+ endpoint: e,
559
+ beneficiaryCard: t,
560
+ isModal: l,
561
+ onCallback: r
562
+ });
563
+ return {
564
+ mount(d) {
565
+ const a = "className" in d ? document.querySelector(d.className) : "id" in d ? document.getElementById(d.id) : d.element;
566
+ a && o && a.appendChild(o);
567
+ },
568
+ open() {
569
+ h();
570
+ },
571
+ destroy() {
572
+ c();
573
+ }
574
+ };
575
+ }
576
+ export {
577
+ de as init
578
+ };