@test-glide/glide-payment 0.0.2 → 0.0.4

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.
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(M,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(M=typeof globalThis<"u"?globalThis:M||self,c(M.BivoPayments={}))})(this,(function(M){"use strict";function c(n,e={}){const t=document.createElement(n),{className:l,id:r,innerHTML:h,textContent:o,attributes:d,styles:u,dataset:i,children:a,events:m}=e;if(l){const p=Array.isArray(l)?l:l.split(" ");t.classList.add(...p.filter(Boolean))}if(r&&(t.id=r),h&&(t.innerHTML=h),o&&(t.textContent=o),d)for(const[p,s]of Object.entries(d))s&&t.setAttribute(p,s);if(u)for(const[p,s]of Object.entries(u))t.style[p]=s;if(i)for(const[p,s]of Object.entries(i))t.dataset[p]=s;if(a&&t.append(...a.filter(Boolean)),m)for(const[p,s]of Object.entries(m))t.addEventListener(p,s);return t}function N(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:d,textContent:u,className:i}=e;if(r)for(const[a,m]of Object.entries(r))l.style[a]=m;if(h)for(const[a,m]of Object.entries(h))l.setAttribute(a,m);if(o)for(const[a,m]of Object.entries(o))l.dataset[a]=m;if(d!==void 0&&(l.innerHTML=d),u!==void 0&&(l.textContent=u),i?.add){const a=Array.isArray(i.add)?i.add:[i.add];l.classList.add(...a)}if(i?.remove){const a=Array.isArray(i.remove)?i.remove:[i.remove];l.classList.remove(...a)}i?.toggle&&(Array.isArray(i.toggle)?i.toggle:[i.toggle]).forEach(m=>l.classList.toggle(m))}}const P=`
1
+ (function(M,d){typeof exports=="object"&&typeof module<"u"?d(exports):typeof define=="function"&&define.amd?define(["exports"],d):(M=typeof globalThis<"u"?globalThis:M||self,d(M.BivoPayments={}))})(this,(function(M){"use strict";function d(t,n={}){const e=document.createElement(t),{className:o,id:l,innerHTML:m,textContent:c,attributes:a,styles:h,dataset:s,children:r,events:u}=n;if(o){const p=Array.isArray(o)?o:o.split(" ");e.classList.add(...p.filter(Boolean))}if(l&&(e.id=l),m&&(e.innerHTML=m),c&&(e.textContent=c),a)for(const[p,i]of Object.entries(a))i&&e.setAttribute(p,i);if(h)for(const[p,i]of Object.entries(h))e.style[p]=i;if(s)for(const[p,i]of Object.entries(s))e.dataset[p]=i;if(r&&e.append(...r.filter(Boolean)),u)for(const[p,i]of Object.entries(u))e.addEventListener(p,i);return e}function N(t,n){const e="id"in t?[document.getElementById(t.id)].filter(Boolean):"className"in t?Array.from(document.getElementsByClassName(t.className)):[t.element];if(!e.length){console.warn("updateElements: no elements found for",t);return}for(const o of e){const{styles:l,attributes:m,dataset:c,innerHTML:a,textContent:h,className:s}=n;if(l)for(const[r,u]of Object.entries(l))o.style[r]=u;if(m)for(const[r,u]of Object.entries(m))o.setAttribute(r,u);if(c)for(const[r,u]of Object.entries(c))o.dataset[r]=u;if(a!==void 0&&(o.innerHTML=a),h!==void 0&&(o.textContent=h),s?.add){const r=Array.isArray(s.add)?s.add:[s.add];o.classList.add(...r)}if(s?.remove){const r=Array.isArray(s.remove)?s.remove:[s.remove];o.classList.remove(...r)}s?.toggle&&(Array.isArray(s.toggle)?s.toggle:[s.toggle]).forEach(u=>o.classList.toggle(u))}}const P=`
2
2
  <svg
3
3
  xmlns="http://www.w3.org/2000/svg"
4
4
  width="16"
@@ -45,28 +45,28 @@
45
45
  ></path>
46
46
  </svg>`,L=`
47
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
- `,q=({children:n,onClick:e,disabled:t=!1,size:l="medium",type:r="button",className:h="",variant:o="primary"})=>{const d=c("span",{className:"button-spinner",innerHTML:Z,dataset:{show:"false"}}),u=c("span",{className:"button-label",children:[null],textContent:n}),i=c("button",{className:`custom-button ${o} ${l} ${h}`,attributes:{type:r,...t?{disabled:"true"}:{}},events:{click:e},children:[d,u]}),a=(p=!1)=>{N({element:d},{dataset:{show:String(p)}}),m(p)},m=(p=!1)=>{p?i.setAttribute("disabled","true"):i.removeAttribute("disabled")};return{element:i,setLoading:a,setDisabled:m}},R=({content:n,position:e="top",delay:t=200,maxWidth:l=250,className:r="",id:h=""})=>{var o=c("div",{className:`tooltip ${e} ${r}`,styles:{maxWidth:`${l}px`},attributes:{role:"tooltip"},dataset:{show:"false"},innerHTML:`
49
- <div class="tooltip-content">${n}</div>
48
+ `,R=({children:t,onClick:n,disabled:e=!1,size:o="medium",type:l="button",className:m="",variant:c="primary"})=>{const a=d("span",{className:"button-spinner",innerHTML:Z,dataset:{show:"false"}}),h=d("span",{className:"button-label",children:[null],textContent:t}),s=d("button",{className:`custom-button ${c} ${o} ${m}`,attributes:{type:l,...e?{disabled:"true"}:{}},events:{click:n},children:[a,h]}),r=(p=!1)=>{N({element:a},{dataset:{show:String(p)}}),u(p)},u=(p=!1)=>{p?s.setAttribute("disabled","true"):s.removeAttribute("disabled")};return{element:s,setLoading:r,setDisabled:u}},q=({content:t,position:n="top",delay:e=200,maxWidth:o=250,className:l="",id:m=""})=>{var c=d("div",{className:`tooltip ${n} ${l}`,styles:{maxWidth:`${o}px`},attributes:{role:"tooltip"},dataset:{show:"false"},innerHTML:`
49
+ <div class="tooltip-content">${t}</div>
50
50
  <div class="tooltip-arrow"></div>
51
- `});let d=null;var a=c("span",{className:"tooltip-trigger",innerHTML:L,events:{mouseenter:()=>{t>0?d=window.setTimeout(()=>{o.dataset.show="true",m()},t):(o.dataset.show="true",m())},mouseleave:()=>{d&&clearTimeout(d),o.dataset.show="false"}}});function m(){if(!a||!o)return;const s=a.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 x=window.innerWidth,T=window.innerHeight;g<0&&(g=y),g+v.width>x&&(g=x-v.width-y),w<0&&(w=y),w+v.height>T&&(w=T-v.height-y),o.style.top=`${w}px`,o.style.left=`${g}px`}return c("div",{className:"tooltip-wrapper",id:`tooltip-${h}`,children:[a,o]})},_=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 d=new Date,u=d.getFullYear(),i=d.getMonth()+1,a=Math.floor(u/100)*100,m=a+o,p=a+100+o;let s;m>=u&&m<=u+20?s=m:(p>=u&&p<=u+20,s=p),s<u||s===u&&h<i?e.expiryDate="Card has expired":s>u+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 G(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 B(n=""){return n.trim().replaceAll(/\s/g,"").replaceAll("-","")}const K={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 U(n,e){return e==="none"?n:K[e](n)}const $=({label:n,maskType:e,id:t,name:l,type:r="text",placeholder:h="Enter value",tooltip:o="",onChange:d})=>{const u=["card","expiry","phone","cvv","zip"].includes(e)?"numeric":"",i=c("label",{className:"input-label",innerHTML:n,attributes:{for:t}});let a=!1;const p=c("input",{id:t||"input-id",className:"styled-input",attributes:{placeholder:h,type:r,inputMode:u,name:l},events:{input:s,blur:v,keydown:b=>{b.key==="Enter"&&(a=!0)}}});function s(b){const k=e!=="none"?U(b?.target?.value,e):b?.target?.value;p.value=k,d?.(k)}function v(){a=!0,d?.(p?.value||"")}const y=c("div",{className:"input-loader",innerHTML:'<div class="loader"></div>',dataset:{show:"false"}}),w=o?c("div",{className:"input-right-element",children:[R({content:o,id:t})]}):null,g=c("div",{className:"input-wrapper",children:[p,y,w]}),x=c("div",{className:"error-message",dataset:{show:"false"},innerHTML:`
51
+ `});let a=null;var r=d("span",{className:"tooltip-trigger",innerHTML:L,events:{mouseenter:()=>{e>0?a=window.setTimeout(()=>{c.dataset.show="true",u()},e):(c.dataset.show="true",u())},mouseleave:()=>{a&&clearTimeout(a),c.dataset.show="false"}}});function u(){if(!r||!c)return;const i=r.getBoundingClientRect(),g=c.getBoundingClientRect(),b=8;let f,y;switch(n){case"top":f=i.top-g.height-b,y=i.left+i.width/2-g.width/2;break;case"bottom":f=i.bottom+b,y=i.left+i.width/2-g.width/2;break;case"left":f=i.top+i.height/2-g.height/2,y=i.left-g.width-b;break;case"right":f=i.top+i.height/2-g.height/2,y=i.right+b;break;default:f=i.top-g.height-b,y=i.left+i.width/2-g.width/2}const x=window.innerWidth,T=window.innerHeight;y<0&&(y=b),y+g.width>x&&(y=x-g.width-b),f<0&&(f=b),f+g.height>T&&(f=T-g.height-b),c.style.top=`${f}px`,c.style.left=`${y}px`}return d("div",{className:"tooltip-wrapper",id:`tooltip-${m}`,children:[r,c]})},_=(t,n=!1)=>{const e={},o=Object.values(t).every(a=>!a||a.trim()===""),l=t.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",!t.expiryDate&&!n)e.expiryDate="Expiry date is required";else if(t.expiryDate){const a=t.expiryDate.replace(/\D/g,"");if(a.length<4)e.expiryDate="Enter complete expiry date (MM/YY)";else{const h=parseInt(a.substring(0,2),10),s=parseInt(a.substring(2,4),10);if(isNaN(h)||h<1||h>12)e.expiryDate="Invalid month (must be 01-12)";else if(isNaN(s)||s<0||s>99)e.expiryDate="Invalid year";else{const r=new Date,u=r.getFullYear(),p=r.getMonth()+1,i=Math.floor(u/100)*100,g=i+s,b=i+100+s;let f;g>=u&&g<=u+20?f=g:(b>=u&&b<=u+20,f=b),f<u||f===u&&h<p?e.expiryDate="Card has expired":f>u+20&&(e.expiryDate="Expiry year is too far in the future")}}}const m=t.cvv.trim();m&&!/^\d{3,4}$/.test(m)&&(e.cvv="CVV must be 3 or 4 digits");const c=t.zipCode.trim();return c&&!/^[A-Z0-9\s-]{3,10}$/i.test(c)&&(e.zipCode="Invalid ZIP code format"),{isValid:Object.keys(e).length===0,errors:e,isEmpty:o}};function G(t){const n=parseInt(t,10);if(isNaN(n)||n<0||n>99)return null;const e=new Date().getFullYear(),o=Math.floor(e/100)*100;let l=o+n;return l>=e&&l<=e+20||(l=o+100+n,l>=e&&l<=e+20)?l:o+100+n}function B(t=""){return t.trim().replaceAll(/\s/g,"").replaceAll("-","")}const K={card:t=>t.replace(/\s+/g,"").replace(/[^0-9]/gi,"").substring(0,16).match(/.{1,4}/g)?.join(" ")??"",phone:t=>{const n=t.replace(/\D/g,"").substring(0,10),e=n.match(/^(\d{3})(\d{3})(\d{4})$/);return e?`(${e[1]}) ${e[2]}-${e[3]}`:n},expiry:t=>{const n=t.replace(/[^0-9/]/g,"");return n.length<=2?n:n.includes("/")?n.substring(0,5):n.substring(0,2)+"/"+n.substring(2,4)},cvv:t=>t.replace(/\D/g,"").substring(0,4),zip:t=>{const n=t.replace(/\D/g,"").substring(0,9);return n.length>5?`${n.substring(0,5)}-${n.substring(5)}`:n}};function U(t,n){return n==="none"?t:K[n](t)}const $=({label:t,maskType:n,id:e,name:o,type:l="text",placeholder:m="Enter value",tooltip:c="",onChange:a})=>{const h=["card","expiry","phone","cvv","zip"].includes(n)?"numeric":"",s=d("label",{className:"input-label",innerHTML:t,attributes:{for:e}});let r=!1;const p=d("input",{id:e||"input-id",className:"styled-input",attributes:{placeholder:m,type:l,inputMode:h,name:o},events:{input:i,blur:g,keydown:w=>{w.key==="Enter"&&(r=!0)}}});function i(w){const k=n!=="none"?U(w?.target?.value,n):w?.target?.value;p.value=k,a?.(k)}function g(){r=!0,a?.(p?.value||"")}const b=d("div",{className:"input-loader",innerHTML:'<div class="loader"></div>',dataset:{show:"false"}}),f=c?d("div",{className:"input-right-element",children:[q({content:c,id:e})]}):null,y=d("div",{className:"input-wrapper",children:[p,b,f]}),x=d("div",{className:"error-message",dataset:{show:"false"},innerHTML:`
52
52
  ${L}
53
53
  <span></span>
54
- `});return{element:c("div",{className:"custom-input-group",children:[i,g,x]}),setLoading:b=>{N({element:g},{dataset:{loading:b?"true":"false"}}),N({element:p},{attributes:{disabled:b?"true":"false"}}),N({element:y},{dataset:{show:b?"true":"false"}})},setError:(b="")=>{N({element:g},{className:b&&a?{add:"input-error"}:{remove:"input-error"}}),N({element:x},{dataset:{show:b&&a?"true":"false"},innerHTML:`
54
+ `});return{element:d("div",{className:"custom-input-group",children:[s,y,x]}),setLoading:w=>{N({element:y},{dataset:{loading:w?"true":"false"}}),N({element:p},{attributes:{disabled:w?"true":"false"}}),N({element:b},{dataset:{show:w?"true":"false"}})},setError:(w="")=>{N({element:y},{className:w&&r?{add:"input-error"}:{remove:"input-error"}}),N({element:x},{dataset:{show:w&&r?"true":"false"},innerHTML:`
55
55
  ${L}
56
- <span>${b||""}</span>
57
- `})}}},J=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 d=await fetch(n,o),u=d.headers.get("content-type");let i;if(u?.includes("application/json")?i=await d.json():i=await d.text(),!d.ok){const a=i;throw new Error(a?.message||`HTTP error! status: ${d.status}`)}return{data:i,error:null}}catch(o){return{data:null,error:o instanceof Error?o.message:"An error occurred"}}},Q=({title:n="",children:e,onClose:t,showBackBtn:l=!1,showCloseBtn:r=!0})=>{const h=c("button",{className:"back-btn",innerHTML:W,dataset:{show:String(l)},events:{click:()=>m()}}),o=c("h3",{textContent:n}),d=c("button",{className:"close-btn",innerHTML:"&times;",dataset:{show:String(r)},attributes:{"aria-label":"Close modal"},events:{click:()=>m()}}),u=c("div",{className:"modal-header",children:[h,o,d]}),i=c("div",{className:"modal-content",children:[e]}),a=c("dialog",{className:"custom-modal",children:[u,i],events:{cancel:s=>{s.preventDefault(),m()}}}),m=()=>{a.close(),t?.()};return{element:a,setModalVisibility:s=>{s?a.showModal():a.close()}}},X=({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.",d=t?"Debit Card Number":"Your Debit Card Number",u=t?"Enter recipient's card number":"Enter your card number",i=`add-card-form-wrapper${t?" recipient-form":""}`,a={cardNumber:"",expiryDate:"",cvv:"",zipCode:""},{element:m,setError:p}=$({label:d,placeholder:u,id:"card-number-input",name:"cardNumber",maskType:"card",onChange(f){A("cardNumber",f,p)}}),{element:s,setError:v}=$({label:"Expiration Date",placeholder:"MM/YY",id:"expiry-input",name:"expiryDate",maskType:"expiry",onChange(f){A("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){A("cvv",f,w)}}),{element:g,setError:x}=$({label:"ZIP Code",placeholder:t?"ZIP Code":"Enter your ZIP Code",id:"zip-input",name:"zipCode",maskType:"zip",onChange(f){A("zipCode",f,x)}}),T=c("div",{className:t?"input-sections":"inputs",children:[m,s,y,g]}),H=c("p",{className:"submit-error",dataset:{show:"false"}}),{element:S,setDisabled:b,setLoading:k}=q({children:"Link Card",type:"submit",disabled:!0}),z=(f="")=>{N({element:H},{dataset:{show:String(!!f)},innerHTML:`
56
+ <span>${w||""}</span>
57
+ `})}}},J=async(t,n={})=>{const{method:e="GET",headers:o={},body:l=null,...m}=n;try{const c={method:e,headers:{Accept:"*/*","Content-Type":"application/json",...o},...m};l&&["POST","PUT","PATCH","DELETE"].includes(e.toUpperCase())&&(c.body=typeof l=="string"?l:JSON.stringify(l));const a=await fetch(t,c),h=a.headers.get("content-type");let s;if(h?.includes("application/json")?s=await a.json():s=await a.text(),!a.ok){const r=s;throw new Error(r?.message||`HTTP error! status: ${a.status}`)}return{data:s,error:null}}catch(c){return{data:null,error:c instanceof Error?c.message:"An error occurred"}}},Q=({title:t="",children:n,onClose:e,showBackBtn:o=!1,showCloseBtn:l=!0})=>{const m=d("button",{className:"back-btn",innerHTML:W,dataset:{show:String(o)},events:{click:()=>u()}}),c=d("h3",{textContent:t}),a=d("button",{className:"close-btn",innerHTML:"&times;",dataset:{show:String(l)},attributes:{"aria-label":"Close modal"},events:{click:()=>u()}}),h=d("div",{className:"modal-header",children:[m,c,a]}),s=d("div",{className:"modal-content",children:[n]}),r=d("dialog",{className:"custom-modal",children:[h,s],events:{cancel:i=>{i.preventDefault(),u()}}}),u=()=>{r.close(),e?.()};return{element:r,setModalVisibility:i=>{i?r.showModal():r.close()}}},X=({token:t,endpoint:n,beneficiaryCard:e=!1,isModal:o=!1,onCallback:l=()=>null})=>{const m=e?"Enter Recipient Debit Card Details":"Enter Your Debit Card Details",c=e?"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.",a=e?"Debit Card Number":"Your Debit Card Number",h=e?"Enter recipient's card number":"Enter your card number",s=`add-card-form-wrapper${e?" recipient-form":""}`,r={cardNumber:"",expiryDate:"",cvv:"",zipCode:""},{element:u,setError:p}=$({label:a,placeholder:h,id:"card-number-input",name:"cardNumber",maskType:"card",onChange(v){A("cardNumber",v,p)}}),{element:i,setError:g}=$({label:"Expiration Date",placeholder:"MM/YY",id:"expiry-input",name:"expiryDate",maskType:"expiry",onChange(v){A("expiryDate",v,g)}}),{element:b,setError:f}=$({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(v){A("cvv",v,f)}}),{element:y,setError:x}=$({label:"ZIP Code",placeholder:e?"ZIP Code":"Enter your ZIP Code",id:"zip-input",name:"zipCode",maskType:"zip",onChange(v){A("zipCode",v,x)}}),T=d("div",{className:e?"input-sections":"inputs",children:[u,i,b,y]}),H=d("p",{className:"submit-error",dataset:{show:"false"}}),{element:V,setDisabled:w,setLoading:k}=R({children:"Link Card",type:"submit",disabled:!0}),Y=(v="")=>{N({element:H},{dataset:{show:String(!!v)},innerHTML:`
58
58
  ${L}
59
- ${f||""}
60
- `})},j=(f=!0)=>{b(f),k(f)};function A(f,I,E){a[f]=I;const{isValid:V,errors:D}=_(a);D[f]?E(D[f]):E(""),b(!V)}const te=c("div",{className:"submit-button-wrapper",children:[H,S]});async function ne(f){f.preventDefault();const I=new FormData(f.target),E=Object.fromEntries(I.entries());console.log(E);const V=E?.cardNumber,D=E?.expiryDate,ae=E?.cvv,le=E?.zipCode,ce=Number(D?.split("/")[0]),de=G(D?.split("/")[1]),ue=B(V);j(!0),z("");const C=await J(e,{method:"POST",body:{token:n,pan:ue,expiry_month:ce,expiry_year:de,cvv:B(ae),address:{postal_code:B(le)}}});C.error?(console.error("Request failed:",C.error),j(!1),z(C.error),r?.({success:!1,error:C.error})):(console.log("Request success:",C.data),j(!1),r?.({success:!0,data:C.data}))}const se=()=>c("form",{events:{submit:ne},children:[T,te]}),re=()=>c("div",{className:"form-title",innerHTML:`
61
- <p>${o}</p>
59
+ ${v||""}
60
+ `})},S=(v=!0)=>{w(v),k(v)};function A(v,j,E){r[v]=j;const{isValid:I,errors:D}=_(r,e);D[v]?E(D[v]):E(""),w(!I)}const te=d("div",{className:"submit-button-wrapper",children:[H,V]});async function ne(v){v.preventDefault();const j=new FormData(v.target),E=Object.fromEntries(j.entries());console.log(E);const I=E?.cardNumber,D=E?.expiryDate,ie=E?.cvv,le=E?.zipCode,ce=Number(D?.split("/")[0]),de=G(D?.split("/")[1]),ue=B(I);S(!0),Y("");const C=await J(n,{method:"POST",body:{token:t,pan:ue,expiry_month:ce,expiry_year:de,cvv:B(ie),address:{postal_code:B(le)}}});C.error?(console.error("Request failed:",C.error),S(!1),Y(C.error),l?.({success:!1,error:C.error})):(console.log("Request success:",C.data),S(!1),l?.({success:!0,data:C.data}))}const se=()=>d("form",{events:{submit:ne},children:[T,te]}),re=()=>d("div",{className:"form-title",innerHTML:`
61
+ <p>${c}</p>
62
62
 
63
63
  <div>
64
64
  ${P}
65
65
 
66
66
  <span>Secured with 256-bit encryption</span>
67
67
  </div>
68
- `}),Y=()=>c("div",{className:l?"":"non-modal-content",children:[re(),se()]}),oe=l?null:c("div",{className:`${i} non-modal`,children:[c("div",{className:"non-modal-header",innerHTML:`
68
+ `}),z=()=>d("div",{className:o?"":"non-modal-content",children:[re(),se()]}),oe=o?null:d("div",{className:`${s} non-modal`,children:[d("div",{className:"non-modal-header",innerHTML:`
69
69
  <span></span>
70
- <h3>${h}</h3>
70
+ <h3>${m}</h3>
71
71
  <span></span>
72
- `}),Y()]}),{element:F,setModalVisibility:O}=l?Q({title:h,children:Y()}):{element:null,setModalVisibility:()=>{}};function ie(){F&&(document.body.appendChild(c("div",{className:i,children:[F]})),O(!0))}return{renderFormWithModal:ie,nonModalForm:oe,closeModal:()=>O(!1)}};function ee({token:n,endpoint:e,beneficiaryCard:t,isModal:l,onCallback:r}){const{renderFormWithModal:h,nonModalForm:o,closeModal:d}=X({token:n,endpoint:e,beneficiaryCard:t,isModal:l,onCallback:r});return{mount(u){const i="className"in u?document.querySelector(u.className):"id"in u?document.getElementById(u.id):u.element;i&&o&&i.appendChild(o)},open(){h()},destroy(){d()}}}M.init=ee,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
72
+ `}),z()]}),{element:F,setModalVisibility:O}=o?Q({title:m,children:z()}):{element:null,setModalVisibility:()=>{}};function ae(){F&&(document.body.appendChild(d("div",{className:s,children:[F]})),O(!0))}return{renderFormWithModal:ae,nonModalForm:oe,closeModal:()=>O(!1)}};function ee({token:t,endpoint:n,beneficiaryCard:e,isModal:o,onCallback:l,onModalClose:m}){const{renderFormWithModal:c,nonModalForm:a,closeModal:h}=X({token:t,endpoint:n,beneficiaryCard:e,isModal:o,onCallback:l});return{mount(s){const r="className"in s?document.querySelector(s.className):"id"in s?document.getElementById(s.id):s.element;r&&a&&r.appendChild(a)},open(){c()},destroy(){h(),m?.()}}}M.init=ee,Object.defineProperty(M,Symbol.toStringTag,{value:"Module"})}));
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),g=require("react"),E=i=>{const r={},o=Object.values(i).every(e=>!e||e.trim()===""),d=i.cardNumber?.replace(/\s/g,"");if(d?/^\d{13,19}$/.test(d)||(r.cardNumber="Card number must be 13-19 digits"):r.cardNumber="Card number is required",!i.expiryDate)r.expiryDate="Expiry date is required";else{const e=i.expiryDate.replace(/\D/g,"");if(e.length<4)r.expiryDate="Enter complete expiry date (MM/YY)";else{const f=parseInt(e.substring(0,2),10),s=parseInt(e.substring(2,4),10);if(isNaN(f)||f<1||f>12)r.expiryDate="Invalid month (must be 01-12)";else if(isNaN(s)||s<0||s>99)r.expiryDate="Invalid year";else{const l=new Date,a=l.getFullYear(),u=l.getMonth()+1,x=Math.floor(a/100)*100,h=x+s,b=x+100+s;let p;h>=a&&h<=a+20?p=h:(b>=a&&b<=a+20,p=b),p<a||p===a&&f<u?r.expiryDate="Card has expired":p>a+20&&(r.expiryDate="Expiry year is too far in the future")}}}return i.cvv?.trim()?/^\d{3,4}$/.test(i.cvv.trim())||(r.cvv="CVV must be 3 or 4 digits"):r.cvv="CVV is required",i.zipCode?.trim()?/^[A-Z0-9\s-]{3,10}$/i.test(i.zipCode.trim())||(r.zipCode="Invalid ZIP code format"):r.zipCode="Postal code is required",{isValid:Object.keys(r).length===0,errors:r,isEmpty:o}};function k(i){const r=parseInt(i,10);if(isNaN(r)||r<0||r>99)return null;const o=new Date().getFullYear(),d=Math.floor(o/100)*100;let e=d+r;return e>=o&&e<=o+20||(e=d+100+r,e>=o&&e<=o+20)?e:d+100+r}function S(i=""){return i.trim().replaceAll(/\s/g,"").replaceAll("-","")}const A=async(i,r={})=>{const{method:o="GET",headers:d={},body:e=null,...f}=r;try{const s={method:o,headers:{Accept:"*/*","Content-Type":"application/json",...d},...f};e&&["POST","PUT","PATCH","DELETE"].includes(o.toUpperCase())&&(s.body=typeof e=="string"?e:JSON.stringify(e));const l=await fetch(i,s),a=l.headers.get("content-type");let u;if(a?.includes("application/json")?u=await l.json():u=await l.text(),!l.ok){const x=u;throw new Error(x?.message||`HTTP error! status: ${l.status}`)}return{data:u,error:null}}catch(s){return{data:null,error:s instanceof Error?s.message:"An error occurred"}}},{View:m,Text:c,TextInput:T,ActivityIndicator:q,TouchableOpacity:O,StyleSheet:L}=require("react-native"),R=({token:i,endpoint:r,beneficiaryCard:o=!1,onCallback:d})=>{const[e,f]=g.useState({cardNumber:"",expiryDate:"",cvv:"",zipCode:""}),[s,l]=g.useState({}),[a,u]=g.useState(null),[x,h]=g.useState(!1),b=g.useMemo(()=>E(e).isValid,[e]),p=(y,D)=>{const C={...e,[y]:D};f(C);const{errors:v}=E(C);l(v),a&&u(null)},I=async()=>{const{isValid:y,errors:D}=E(e);if(!y){l(D);return}const{cardNumber:C,expiryDate:v,cvv:M,zipCode:V}=e,N=Number(v?.split("/")[0]),z=k(v?.split("/")[1]??""),P=S(C);if(!N||!z){u("Invalid expiry date");return}h(!0),u(null);const j=await A(r,{method:"POST",body:{token:i,pan:P,expiry_month:N,expiry_year:z,cvv:S(M),address:{postal_code:S(V)}}});h(!1),j.error?(u(j.error),d?.({success:!1,error:j.error})):d?.({success:!0,data:j.data})},Y=o?"Enter Recipient Debit Card Details":"Enter Your Debit Card Details",w=o?"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.";return n.jsxs(m,{style:t.container,children:[n.jsx(c,{style:t.title,children:Y}),n.jsx(c,{style:t.description,children:w}),n.jsxs(m,{style:t.field,children:[n.jsx(c,{style:t.label,children:o?"Debit Card Number":"Your Debit Card Number"}),n.jsx(T,{value:e.cardNumber,onChangeText:y=>p("cardNumber",y),keyboardType:"number-pad",placeholder:o?"Enter recipient's card number":"Enter your card number",style:t.input}),!!s.cardNumber&&n.jsx(c,{style:t.error,children:s.cardNumber})]}),n.jsxs(m,{style:t.row,children:[n.jsxs(m,{style:[t.field,t.half],children:[n.jsx(c,{style:t.label,children:"Expiration Date"}),n.jsx(T,{value:e.expiryDate,onChangeText:y=>p("expiryDate",y),keyboardType:"number-pad",placeholder:"MM/YY",style:t.input}),!!s.expiryDate&&n.jsx(c,{style:t.error,children:s.expiryDate})]}),n.jsxs(m,{style:[t.field,t.half],children:[n.jsx(c,{style:t.label,children:"CVV"}),n.jsx(T,{value:e.cvv,onChangeText:y=>p("cvv",y),keyboardType:"number-pad",secureTextEntry:!0,placeholder:"3-Digit",style:t.input}),!!s.cvv&&n.jsx(c,{style:t.error,children:s.cvv})]})]}),n.jsxs(m,{style:t.field,children:[n.jsx(c,{style:t.label,children:"ZIP Code"}),n.jsx(T,{value:e.zipCode,onChangeText:y=>p("zipCode",y),keyboardType:"number-pad",placeholder:o?"ZIP Code":"Enter your ZIP Code",style:t.input}),!!s.zipCode&&n.jsx(c,{style:t.error,children:s.zipCode})]}),!!a&&n.jsx(c,{style:t.submitError,children:a}),n.jsx(O,{style:[t.button,!b||x?t.buttonDisabled:null],onPress:I,disabled:!b||x,children:x?n.jsx(q,{color:"#ffffff"}):n.jsx(c,{style:t.buttonText,children:"Link Card"})})]})},t=L.create({container:{padding:16,borderRadius:12,backgroundColor:"#ffffff",gap:12},title:{fontSize:18,fontWeight:"600"},description:{fontSize:14,color:"#444"},field:{marginTop:8},row:{flexDirection:"row",gap:12},half:{flex:1},label:{fontSize:13,marginBottom:4,color:"#222"},input:{borderWidth:1,borderColor:"#ccc",borderRadius:8,paddingHorizontal:10,paddingVertical:8,fontSize:14},error:{color:"#cc0000",fontSize:12,marginTop:4},submitError:{color:"#cc0000",fontSize:13,marginTop:8},button:{marginTop:16,paddingVertical:12,borderRadius:999,alignItems:"center",justifyContent:"center",backgroundColor:"#111827"},buttonDisabled:{opacity:.6},buttonText:{color:"#ffffff",fontSize:15,fontWeight:"500"}});exports.AddCard=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),C=require("react"),z=(i,l=!1)=>{const e={},p=Object.values(i).every(o=>!o||o.trim()===""),t=i.cardNumber?.replace(/\s/g,"");if(t?/^\d{13,19}$/.test(t)||(e.cardNumber="Card number must be 13-19 digits"):e.cardNumber="Card number is required",!i.expiryDate&&!l)e.expiryDate="Expiry date is required";else if(i.expiryDate){const o=i.expiryDate.replace(/\D/g,"");if(o.length<4)e.expiryDate="Enter complete expiry date (MM/YY)";else{const y=parseInt(o.substring(0,2),10),a=parseInt(o.substring(2,4),10);if(isNaN(y)||y<1||y>12)e.expiryDate="Invalid month (must be 01-12)";else if(isNaN(a)||a<0||a>99)e.expiryDate="Invalid year";else{const f=new Date,d=f.getFullYear(),j=f.getMonth()+1,h=Math.floor(d/100)*100,v=h+a,m=h+100+a;let x;v>=d&&v<=d+20?x=v:(m>=d&&m<=d+20,x=m),x<d||x===d&&y<j?e.expiryDate="Card has expired":x>d+20&&(e.expiryDate="Expiry year is too far in the future")}}}const b=i.cvv.trim();b&&!/^\d{3,4}$/.test(b)&&(e.cvv="CVV must be 3 or 4 digits");const s=i.zipCode.trim();return s&&!/^[A-Z0-9\s-]{3,10}$/i.test(s)&&(e.zipCode="Invalid ZIP code format"),{isValid:Object.keys(e).length===0,errors:e,isEmpty:p}};function k(i){const l=parseInt(i,10);if(isNaN(l)||l<0||l>99)return null;const e=new Date().getFullYear(),p=Math.floor(e/100)*100;let t=p+l;return t>=e&&t<=e+20||(t=p+100+l,t>=e&&t<=e+20)?t:p+100+l}function I(i=""){return i.trim().replaceAll(/\s/g,"").replaceAll("-","")}const A=async(i,l={})=>{const{method:e="GET",headers:p={},body:t=null,...b}=l;try{const s={method:e,headers:{Accept:"*/*","Content-Type":"application/json",...p},...b};t&&["POST","PUT","PATCH","DELETE"].includes(e.toUpperCase())&&(s.body=typeof t=="string"?t:JSON.stringify(t));const o=await fetch(i,s),y=o.headers.get("content-type");let a;if(y?.includes("application/json")?a=await o.json():a=await o.text(),!o.ok){const f=a;throw new Error(f?.message||`HTTP error! status: ${o.status}`)}return{data:a,error:null}}catch(s){return{data:null,error:s instanceof Error?s.message:"An error occurred"}}},{View:g,Text:c,TextInput:S,ActivityIndicator:O,TouchableOpacity:q,StyleSheet:L}=require("react-native"),R=({token:i,endpoint:l,beneficiaryCard:e=!1,onCallback:p})=>{const[t,b]=C.useState({cardNumber:"",expiryDate:"",cvv:"",zipCode:""}),[s,o]=C.useState({}),[y,a]=C.useState(null),[f,d]=C.useState(!1),j=C.useMemo(()=>z(t,e).isValid,[t]),h=(u,N)=>{const D={...t,[u]:N};b(D);const{errors:T}=z(D,e);o(T),y&&a(null)},v=async()=>{const{isValid:u,errors:N}=z(t,e);if(!u){o(N);return}const{cardNumber:D,expiryDate:T,cvv:M,zipCode:P}=t,Y=Number(T?.split("/")[0]),w=k(T?.split("/")[1]??""),V=I(D);if(!Y||!w){a("Invalid expiry date");return}d(!0),a(null);const E=await A(l,{method:"POST",body:{token:i,pan:V,expiry_month:Y,expiry_year:w,cvv:I(M),address:{postal_code:I(P)}}});d(!1),E.error?(a(E.error),p?.({success:!1,error:E.error})):p?.({success:!0,data:E.data})},m=e?"Enter Recipient Debit Card Details":"Enter Your Debit Card Details",x=e?"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.";return n.jsxs(g,{style:r.container,children:[n.jsx(c,{style:r.title,children:m}),n.jsx(c,{style:r.description,children:x}),n.jsxs(g,{style:r.field,children:[n.jsx(c,{style:r.label,children:e?"Debit Card Number":"Your Debit Card Number"}),n.jsx(S,{value:t.cardNumber,onChangeText:u=>h("cardNumber",u),keyboardType:"number-pad",placeholder:e?"Enter recipient's card number":"Enter your card number",style:r.input}),!!s.cardNumber&&n.jsx(c,{style:r.error,children:s.cardNumber})]}),n.jsxs(g,{style:r.row,children:[n.jsxs(g,{style:[r.field,r.half],children:[n.jsx(c,{style:r.label,children:"Expiration Date"}),n.jsx(S,{value:t.expiryDate,onChangeText:u=>h("expiryDate",u),keyboardType:"number-pad",placeholder:"MM/YY",style:r.input}),!!s.expiryDate&&n.jsx(c,{style:r.error,children:s.expiryDate})]}),n.jsxs(g,{style:[r.field,r.half],children:[n.jsx(c,{style:r.label,children:"CVV"}),n.jsx(S,{value:t.cvv,onChangeText:u=>h("cvv",u),keyboardType:"number-pad",secureTextEntry:!0,placeholder:"3-Digit",style:r.input}),!!s.cvv&&n.jsx(c,{style:r.error,children:s.cvv})]})]}),n.jsxs(g,{style:r.field,children:[n.jsx(c,{style:r.label,children:"ZIP Code"}),n.jsx(S,{value:t.zipCode,onChangeText:u=>h("zipCode",u),keyboardType:"number-pad",placeholder:e?"ZIP Code":"Enter your ZIP Code",style:r.input}),!!s.zipCode&&n.jsx(c,{style:r.error,children:s.zipCode})]}),!!y&&n.jsx(c,{style:r.submitError,children:y}),n.jsx(q,{style:[r.button,!j||f?r.buttonDisabled:null],onPress:v,disabled:!j||f,children:f?n.jsx(O,{color:"#ffffff"}):n.jsx(c,{style:r.buttonText,children:"Link Card"})})]})},r=L.create({container:{padding:16,borderRadius:12,backgroundColor:"#ffffff",gap:12},title:{fontSize:18,fontWeight:"600"},description:{fontSize:14,color:"#444"},field:{marginTop:8},row:{flexDirection:"row",gap:12},half:{flex:1},label:{fontSize:13,marginBottom:4,color:"#222"},input:{borderWidth:1,borderColor:"#ccc",borderRadius:8,paddingHorizontal:10,paddingVertical:8,fontSize:14},error:{color:"#cc0000",fontSize:12,marginTop:4},submitError:{color:"#cc0000",fontSize:13,marginTop:8},button:{marginTop:16,paddingVertical:12,borderRadius:999,alignItems:"center",justifyContent:"center",backgroundColor:"#111827"},buttonDisabled:{opacity:.6},buttonText:{color:"#ffffff",fontSize:15,fontWeight:"500"}});exports.AddCard=R;
@@ -1,193 +1,196 @@
1
- import { jsxs as g, jsx as i } from "react/jsx-runtime";
2
- import { useState as D, useMemo as A } from "react";
3
- const z = (o) => {
4
- const r = {}, s = Object.values(o).every(
5
- (e) => !e || e.trim() === ""
6
- ), d = o.cardNumber?.replace(/\s/g, "");
7
- if (d ? /^\d{13,19}$/.test(d) || (r.cardNumber = "Card number must be 13-19 digits") : r.cardNumber = "Card number is required", !o.expiryDate)
8
- r.expiryDate = "Expiry date is required";
9
- else {
10
- const e = o.expiryDate.replace(/\D/g, "");
11
- if (e.length < 4)
12
- r.expiryDate = "Enter complete expiry date (MM/YY)";
1
+ import { jsxs as x, jsx as n } from "react/jsx-runtime";
2
+ import { useState as z, useMemo as A } from "react";
3
+ const Y = (s, l = !1) => {
4
+ const e = {}, p = Object.values(s).every(
5
+ (i) => !i || i.trim() === ""
6
+ ), t = s.cardNumber?.replace(/\s/g, "");
7
+ if (t ? /^\d{13,19}$/.test(t) || (e.cardNumber = "Card number must be 13-19 digits") : e.cardNumber = "Card number is required", !s.expiryDate && !l)
8
+ e.expiryDate = "Expiry date is required";
9
+ else if (s.expiryDate) {
10
+ const i = s.expiryDate.replace(/\D/g, "");
11
+ if (i.length < 4)
12
+ e.expiryDate = "Enter complete expiry date (MM/YY)";
13
13
  else {
14
- const f = parseInt(e.substring(0, 2), 10), n = parseInt(e.substring(2, 4), 10);
15
- if (isNaN(f) || f < 1 || f > 12)
16
- r.expiryDate = "Invalid month (must be 01-12)";
17
- else if (isNaN(n) || n < 0 || n > 99)
18
- r.expiryDate = "Invalid year";
14
+ const y = parseInt(i.substring(0, 2), 10), a = parseInt(i.substring(2, 4), 10);
15
+ if (isNaN(y) || y < 1 || y > 12)
16
+ e.expiryDate = "Invalid month (must be 01-12)";
17
+ else if (isNaN(a) || a < 0 || a > 99)
18
+ e.expiryDate = "Invalid year";
19
19
  else {
20
- const l = /* @__PURE__ */ new Date(), a = l.getFullYear(), u = l.getMonth() + 1, h = Math.floor(a / 100) * 100, m = h + n, b = h + 100 + n;
21
- let p;
22
- m >= a && m <= a + 20 ? p = m : (b >= a && b <= a + 20, p = b), p < a || p === a && f < u ? r.expiryDate = "Card has expired" : p > a + 20 && (r.expiryDate = "Expiry year is too far in the future");
20
+ const f = /* @__PURE__ */ new Date(), d = f.getFullYear(), D = f.getMonth() + 1, b = Math.floor(d / 100) * 100, C = b + a, g = b + 100 + a;
21
+ let h;
22
+ C >= d && C <= d + 20 ? h = C : (g >= d && g <= d + 20, h = g), h < d || h === d && y < D ? e.expiryDate = "Card has expired" : h > d + 20 && (e.expiryDate = "Expiry year is too far in the future");
23
23
  }
24
24
  }
25
25
  }
26
- return o.cvv?.trim() ? /^\d{3,4}$/.test(o.cvv.trim()) || (r.cvv = "CVV must be 3 or 4 digits") : r.cvv = "CVV is required", o.zipCode?.trim() ? /^[A-Z0-9\s-]{3,10}$/i.test(o.zipCode.trim()) || (r.zipCode = "Invalid ZIP code format") : r.zipCode = "Postal code is required", {
27
- isValid: Object.keys(r).length === 0,
28
- errors: r,
29
- isEmpty: s
26
+ const m = s.cvv.trim();
27
+ m && !/^\d{3,4}$/.test(m) && (e.cvv = "CVV must be 3 or 4 digits");
28
+ const o = s.zipCode.trim();
29
+ return o && !/^[A-Z0-9\s-]{3,10}$/i.test(o) && (e.zipCode = "Invalid ZIP code format"), {
30
+ isValid: Object.keys(e).length === 0,
31
+ errors: e,
32
+ isEmpty: p
30
33
  };
31
34
  };
32
- function O(o) {
33
- const r = parseInt(o, 10);
34
- if (isNaN(r) || r < 0 || r > 99) return null;
35
- const s = (/* @__PURE__ */ new Date()).getFullYear(), d = Math.floor(s / 100) * 100;
36
- let e = d + r;
37
- return e >= s && e <= s + 20 || (e = d + 100 + r, e >= s && e <= s + 20) ? e : d + 100 + r;
35
+ function O(s) {
36
+ const l = parseInt(s, 10);
37
+ if (isNaN(l) || l < 0 || l > 99) return null;
38
+ const e = (/* @__PURE__ */ new Date()).getFullYear(), p = Math.floor(e / 100) * 100;
39
+ let t = p + l;
40
+ return t >= e && t <= e + 20 || (t = p + 100 + l, t >= e && t <= e + 20) ? t : p + 100 + l;
38
41
  }
39
- function S(o = "") {
40
- return o.trim().replaceAll(/\s/g, "").replaceAll("-", "");
42
+ function w(s = "") {
43
+ return s.trim().replaceAll(/\s/g, "").replaceAll("-", "");
41
44
  }
42
- const q = async (o, r = {}) => {
43
- const { method: s = "GET", headers: d = {}, body: e = null, ...f } = r;
45
+ const L = async (s, l = {}) => {
46
+ const { method: e = "GET", headers: p = {}, body: t = null, ...m } = l;
44
47
  try {
45
- const n = {
46
- method: s,
48
+ const o = {
49
+ method: e,
47
50
  headers: {
48
51
  Accept: "*/*",
49
52
  "Content-Type": "application/json",
50
- ...d
53
+ ...p
51
54
  },
52
- ...f
55
+ ...m
53
56
  };
54
- e && ["POST", "PUT", "PATCH", "DELETE"].includes(s.toUpperCase()) && (n.body = typeof e == "string" ? e : JSON.stringify(e));
55
- const l = await fetch(o, n), a = l.headers.get("content-type");
56
- let u;
57
- if (a?.includes("application/json") ? u = await l.json() : u = await l.text(), !l.ok) {
58
- const h = u;
57
+ t && ["POST", "PUT", "PATCH", "DELETE"].includes(e.toUpperCase()) && (o.body = typeof t == "string" ? t : JSON.stringify(t));
58
+ const i = await fetch(s, o), y = i.headers.get("content-type");
59
+ let a;
60
+ if (y?.includes("application/json") ? a = await i.json() : a = await i.text(), !i.ok) {
61
+ const f = a;
59
62
  throw new Error(
60
- h?.message || `HTTP error! status: ${l.status}`
63
+ f?.message || `HTTP error! status: ${i.status}`
61
64
  );
62
65
  }
63
- return { data: u, error: null };
64
- } catch (n) {
65
- return { data: null, error: n instanceof Error ? n.message : "An error occurred" };
66
+ return { data: a, error: null };
67
+ } catch (o) {
68
+ return { data: null, error: o instanceof Error ? o.message : "An error occurred" };
66
69
  }
67
70
  }, {
68
- View: x,
71
+ View: v,
69
72
  Text: c,
70
- TextInput: E,
71
- ActivityIndicator: L,
72
- TouchableOpacity: Z,
73
- StyleSheet: F
73
+ TextInput: S,
74
+ ActivityIndicator: Z,
75
+ TouchableOpacity: F,
76
+ StyleSheet: R
74
77
  } = require("react-native"), H = ({
75
- token: o,
76
- endpoint: r,
77
- beneficiaryCard: s = !1,
78
- onCallback: d
78
+ token: s,
79
+ endpoint: l,
80
+ beneficiaryCard: e = !1,
81
+ onCallback: p
79
82
  }) => {
80
- const [e, f] = D({
83
+ const [t, m] = z({
81
84
  cardNumber: "",
82
85
  expiryDate: "",
83
86
  cvv: "",
84
87
  zipCode: ""
85
- }), [n, l] = D({}), [a, u] = D(null), [h, m] = D(!1), b = A(() => z(e).isValid, [e]), p = (y, N) => {
86
- const C = { ...e, [y]: N };
87
- f(C);
88
- const { errors: v } = z(C);
89
- l(v), a && u(null);
90
- }, w = async () => {
91
- const { isValid: y, errors: N } = z(e);
92
- if (!y) {
93
- l(N);
88
+ }), [o, i] = z({}), [y, a] = z(null), [f, d] = z(!1), D = A(() => Y(t, e).isValid, [t]), b = (u, I) => {
89
+ const T = { ...t, [u]: I };
90
+ m(T);
91
+ const { errors: E } = Y(T, e);
92
+ i(E), y && a(null);
93
+ }, C = async () => {
94
+ const { isValid: u, errors: I } = Y(t, e);
95
+ if (!u) {
96
+ i(I);
94
97
  return;
95
98
  }
96
- const { cardNumber: C, expiryDate: v, cvv: P, zipCode: k } = e, I = Number(v?.split("/")[0]), Y = O(v?.split("/")[1] ?? ""), j = S(C);
97
- if (!I || !Y) {
98
- u("Invalid expiry date");
99
+ const { cardNumber: T, expiryDate: E, cvv: k, zipCode: P } = t, M = Number(E?.split("/")[0]), V = O(E?.split("/")[1] ?? ""), j = w(T);
100
+ if (!M || !V) {
101
+ a("Invalid expiry date");
99
102
  return;
100
103
  }
101
- m(!0), u(null);
102
- const T = await q(r, {
104
+ d(!0), a(null);
105
+ const N = await L(l, {
103
106
  method: "POST",
104
107
  body: {
105
- token: o,
108
+ token: s,
106
109
  pan: j,
107
- expiry_month: I,
108
- expiry_year: Y,
109
- cvv: S(P),
110
+ expiry_month: M,
111
+ expiry_year: V,
112
+ cvv: w(k),
110
113
  address: {
111
- postal_code: S(k)
114
+ postal_code: w(P)
112
115
  }
113
116
  }
114
117
  });
115
- m(!1), T.error ? (u(T.error), d?.({ success: !1, error: T.error })) : d?.({ success: !0, data: T.data });
116
- }, V = s ? "Enter Recipient Debit Card Details" : "Enter Your Debit Card Details", M = s ? "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.";
117
- return /* @__PURE__ */ g(x, { style: t.container, children: [
118
- /* @__PURE__ */ i(c, { style: t.title, children: V }),
119
- /* @__PURE__ */ i(c, { style: t.description, children: M }),
120
- /* @__PURE__ */ g(x, { style: t.field, children: [
121
- /* @__PURE__ */ i(c, { style: t.label, children: s ? "Debit Card Number" : "Your Debit Card Number" }),
122
- /* @__PURE__ */ i(
123
- E,
118
+ d(!1), N.error ? (a(N.error), p?.({ success: !1, error: N.error })) : p?.({ success: !0, data: N.data });
119
+ }, g = e ? "Enter Recipient Debit Card Details" : "Enter Your Debit Card Details", h = e ? "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.";
120
+ return /* @__PURE__ */ x(v, { style: r.container, children: [
121
+ /* @__PURE__ */ n(c, { style: r.title, children: g }),
122
+ /* @__PURE__ */ n(c, { style: r.description, children: h }),
123
+ /* @__PURE__ */ x(v, { style: r.field, children: [
124
+ /* @__PURE__ */ n(c, { style: r.label, children: e ? "Debit Card Number" : "Your Debit Card Number" }),
125
+ /* @__PURE__ */ n(
126
+ S,
124
127
  {
125
- value: e.cardNumber,
126
- onChangeText: (y) => p("cardNumber", y),
128
+ value: t.cardNumber,
129
+ onChangeText: (u) => b("cardNumber", u),
127
130
  keyboardType: "number-pad",
128
- placeholder: s ? "Enter recipient's card number" : "Enter your card number",
129
- style: t.input
131
+ placeholder: e ? "Enter recipient's card number" : "Enter your card number",
132
+ style: r.input
130
133
  }
131
134
  ),
132
- !!n.cardNumber && /* @__PURE__ */ i(c, { style: t.error, children: n.cardNumber })
135
+ !!o.cardNumber && /* @__PURE__ */ n(c, { style: r.error, children: o.cardNumber })
133
136
  ] }),
134
- /* @__PURE__ */ g(x, { style: t.row, children: [
135
- /* @__PURE__ */ g(x, { style: [t.field, t.half], children: [
136
- /* @__PURE__ */ i(c, { style: t.label, children: "Expiration Date" }),
137
- /* @__PURE__ */ i(
138
- E,
137
+ /* @__PURE__ */ x(v, { style: r.row, children: [
138
+ /* @__PURE__ */ x(v, { style: [r.field, r.half], children: [
139
+ /* @__PURE__ */ n(c, { style: r.label, children: "Expiration Date" }),
140
+ /* @__PURE__ */ n(
141
+ S,
139
142
  {
140
- value: e.expiryDate,
141
- onChangeText: (y) => p("expiryDate", y),
143
+ value: t.expiryDate,
144
+ onChangeText: (u) => b("expiryDate", u),
142
145
  keyboardType: "number-pad",
143
146
  placeholder: "MM/YY",
144
- style: t.input
147
+ style: r.input
145
148
  }
146
149
  ),
147
- !!n.expiryDate && /* @__PURE__ */ i(c, { style: t.error, children: n.expiryDate })
150
+ !!o.expiryDate && /* @__PURE__ */ n(c, { style: r.error, children: o.expiryDate })
148
151
  ] }),
149
- /* @__PURE__ */ g(x, { style: [t.field, t.half], children: [
150
- /* @__PURE__ */ i(c, { style: t.label, children: "CVV" }),
151
- /* @__PURE__ */ i(
152
- E,
152
+ /* @__PURE__ */ x(v, { style: [r.field, r.half], children: [
153
+ /* @__PURE__ */ n(c, { style: r.label, children: "CVV" }),
154
+ /* @__PURE__ */ n(
155
+ S,
153
156
  {
154
- value: e.cvv,
155
- onChangeText: (y) => p("cvv", y),
157
+ value: t.cvv,
158
+ onChangeText: (u) => b("cvv", u),
156
159
  keyboardType: "number-pad",
157
160
  secureTextEntry: !0,
158
161
  placeholder: "3-Digit",
159
- style: t.input
162
+ style: r.input
160
163
  }
161
164
  ),
162
- !!n.cvv && /* @__PURE__ */ i(c, { style: t.error, children: n.cvv })
165
+ !!o.cvv && /* @__PURE__ */ n(c, { style: r.error, children: o.cvv })
163
166
  ] })
164
167
  ] }),
165
- /* @__PURE__ */ g(x, { style: t.field, children: [
166
- /* @__PURE__ */ i(c, { style: t.label, children: "ZIP Code" }),
167
- /* @__PURE__ */ i(
168
- E,
168
+ /* @__PURE__ */ x(v, { style: r.field, children: [
169
+ /* @__PURE__ */ n(c, { style: r.label, children: "ZIP Code" }),
170
+ /* @__PURE__ */ n(
171
+ S,
169
172
  {
170
- value: e.zipCode,
171
- onChangeText: (y) => p("zipCode", y),
173
+ value: t.zipCode,
174
+ onChangeText: (u) => b("zipCode", u),
172
175
  keyboardType: "number-pad",
173
- placeholder: s ? "ZIP Code" : "Enter your ZIP Code",
174
- style: t.input
176
+ placeholder: e ? "ZIP Code" : "Enter your ZIP Code",
177
+ style: r.input
175
178
  }
176
179
  ),
177
- !!n.zipCode && /* @__PURE__ */ i(c, { style: t.error, children: n.zipCode })
180
+ !!o.zipCode && /* @__PURE__ */ n(c, { style: r.error, children: o.zipCode })
178
181
  ] }),
179
- !!a && /* @__PURE__ */ i(c, { style: t.submitError, children: a }),
180
- /* @__PURE__ */ i(
181
- Z,
182
+ !!y && /* @__PURE__ */ n(c, { style: r.submitError, children: y }),
183
+ /* @__PURE__ */ n(
184
+ F,
182
185
  {
183
- style: [t.button, !b || h ? t.buttonDisabled : null],
184
- onPress: w,
185
- disabled: !b || h,
186
- children: h ? /* @__PURE__ */ i(L, { color: "#ffffff" }) : /* @__PURE__ */ i(c, { style: t.buttonText, children: "Link Card" })
186
+ style: [r.button, !D || f ? r.buttonDisabled : null],
187
+ onPress: C,
188
+ disabled: !D || f,
189
+ children: f ? /* @__PURE__ */ n(Z, { color: "#ffffff" }) : /* @__PURE__ */ n(c, { style: r.buttonText, children: "Link Card" })
187
190
  }
188
191
  )
189
192
  ] });
190
- }, t = F.create({
193
+ }, r = R.create({
191
194
  container: {
192
195
  padding: 16,
193
196
  borderRadius: 12,