@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/README.md +233 -0
- package/dist/index.cjs.js +13 -13
- package/dist/index.es.js +284 -281
- package/dist/index.umd.js +13 -13
- package/dist/native/native.cjs.js +1 -1
- package/dist/native/native.es.js +127 -124
- package/dist/react/react.cjs.js +12 -12
- package/dist/react/react.es.js +283 -278
- package/package.json +1 -1
package/dist/index.umd.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(M,
|
|
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
|
-
`,
|
|
49
|
-
<div class="tooltip-content">${
|
|
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
|
|
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:
|
|
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>${
|
|
57
|
-
`})}}},J=async(n
|
|
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:"×",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
|
-
${
|
|
60
|
-
`})},
|
|
61
|
-
<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
|
-
`}),
|
|
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>${
|
|
70
|
+
<h3>${m}</h3>
|
|
71
71
|
<span></span>
|
|
72
|
-
`}),
|
|
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"),
|
|
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;
|
package/dist/native/native.es.js
CHANGED
|
@@ -1,193 +1,196 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { useState as
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
(
|
|
6
|
-
),
|
|
7
|
-
if (
|
|
8
|
-
|
|
9
|
-
else {
|
|
10
|
-
const
|
|
11
|
-
if (
|
|
12
|
-
|
|
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
|
|
15
|
-
if (isNaN(
|
|
16
|
-
|
|
17
|
-
else if (isNaN(
|
|
18
|
-
|
|
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
|
|
21
|
-
let
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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(
|
|
33
|
-
const
|
|
34
|
-
if (isNaN(
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
return
|
|
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
|
|
40
|
-
return
|
|
42
|
+
function w(s = "") {
|
|
43
|
+
return s.trim().replaceAll(/\s/g, "").replaceAll("-", "");
|
|
41
44
|
}
|
|
42
|
-
const
|
|
43
|
-
const { method:
|
|
45
|
+
const L = async (s, l = {}) => {
|
|
46
|
+
const { method: e = "GET", headers: p = {}, body: t = null, ...m } = l;
|
|
44
47
|
try {
|
|
45
|
-
const
|
|
46
|
-
method:
|
|
48
|
+
const o = {
|
|
49
|
+
method: e,
|
|
47
50
|
headers: {
|
|
48
51
|
Accept: "*/*",
|
|
49
52
|
"Content-Type": "application/json",
|
|
50
|
-
...
|
|
53
|
+
...p
|
|
51
54
|
},
|
|
52
|
-
...
|
|
55
|
+
...m
|
|
53
56
|
};
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
let
|
|
57
|
-
if (
|
|
58
|
-
const
|
|
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
|
-
|
|
63
|
+
f?.message || `HTTP error! status: ${i.status}`
|
|
61
64
|
);
|
|
62
65
|
}
|
|
63
|
-
return { data:
|
|
64
|
-
} catch (
|
|
65
|
-
return { data: null, error:
|
|
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:
|
|
71
|
+
View: v,
|
|
69
72
|
Text: c,
|
|
70
|
-
TextInput:
|
|
71
|
-
ActivityIndicator:
|
|
72
|
-
TouchableOpacity:
|
|
73
|
-
StyleSheet:
|
|
73
|
+
TextInput: S,
|
|
74
|
+
ActivityIndicator: Z,
|
|
75
|
+
TouchableOpacity: F,
|
|
76
|
+
StyleSheet: R
|
|
74
77
|
} = require("react-native"), H = ({
|
|
75
|
-
token:
|
|
76
|
-
endpoint:
|
|
77
|
-
beneficiaryCard:
|
|
78
|
-
onCallback:
|
|
78
|
+
token: s,
|
|
79
|
+
endpoint: l,
|
|
80
|
+
beneficiaryCard: e = !1,
|
|
81
|
+
onCallback: p
|
|
79
82
|
}) => {
|
|
80
|
-
const [
|
|
83
|
+
const [t, m] = z({
|
|
81
84
|
cardNumber: "",
|
|
82
85
|
expiryDate: "",
|
|
83
86
|
cvv: "",
|
|
84
87
|
zipCode: ""
|
|
85
|
-
}), [
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
const { errors:
|
|
89
|
-
|
|
90
|
-
},
|
|
91
|
-
const { isValid:
|
|
92
|
-
if (!
|
|
93
|
-
|
|
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:
|
|
97
|
-
if (!
|
|
98
|
-
|
|
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
|
-
|
|
102
|
-
const
|
|
104
|
+
d(!0), a(null);
|
|
105
|
+
const N = await L(l, {
|
|
103
106
|
method: "POST",
|
|
104
107
|
body: {
|
|
105
|
-
token:
|
|
108
|
+
token: s,
|
|
106
109
|
pan: j,
|
|
107
|
-
expiry_month:
|
|
108
|
-
expiry_year:
|
|
109
|
-
cvv:
|
|
110
|
+
expiry_month: M,
|
|
111
|
+
expiry_year: V,
|
|
112
|
+
cvv: w(k),
|
|
110
113
|
address: {
|
|
111
|
-
postal_code:
|
|
114
|
+
postal_code: w(P)
|
|
112
115
|
}
|
|
113
116
|
}
|
|
114
117
|
});
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
return /* @__PURE__ */
|
|
118
|
-
/* @__PURE__ */
|
|
119
|
-
/* @__PURE__ */
|
|
120
|
-
/* @__PURE__ */
|
|
121
|
-
/* @__PURE__ */
|
|
122
|
-
/* @__PURE__ */
|
|
123
|
-
|
|
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:
|
|
126
|
-
onChangeText: (
|
|
128
|
+
value: t.cardNumber,
|
|
129
|
+
onChangeText: (u) => b("cardNumber", u),
|
|
127
130
|
keyboardType: "number-pad",
|
|
128
|
-
placeholder:
|
|
129
|
-
style:
|
|
131
|
+
placeholder: e ? "Enter recipient's card number" : "Enter your card number",
|
|
132
|
+
style: r.input
|
|
130
133
|
}
|
|
131
134
|
),
|
|
132
|
-
!!
|
|
135
|
+
!!o.cardNumber && /* @__PURE__ */ n(c, { style: r.error, children: o.cardNumber })
|
|
133
136
|
] }),
|
|
134
|
-
/* @__PURE__ */
|
|
135
|
-
/* @__PURE__ */
|
|
136
|
-
/* @__PURE__ */
|
|
137
|
-
/* @__PURE__ */
|
|
138
|
-
|
|
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:
|
|
141
|
-
onChangeText: (
|
|
143
|
+
value: t.expiryDate,
|
|
144
|
+
onChangeText: (u) => b("expiryDate", u),
|
|
142
145
|
keyboardType: "number-pad",
|
|
143
146
|
placeholder: "MM/YY",
|
|
144
|
-
style:
|
|
147
|
+
style: r.input
|
|
145
148
|
}
|
|
146
149
|
),
|
|
147
|
-
!!
|
|
150
|
+
!!o.expiryDate && /* @__PURE__ */ n(c, { style: r.error, children: o.expiryDate })
|
|
148
151
|
] }),
|
|
149
|
-
/* @__PURE__ */
|
|
150
|
-
/* @__PURE__ */
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
|
|
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:
|
|
155
|
-
onChangeText: (
|
|
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:
|
|
162
|
+
style: r.input
|
|
160
163
|
}
|
|
161
164
|
),
|
|
162
|
-
!!
|
|
165
|
+
!!o.cvv && /* @__PURE__ */ n(c, { style: r.error, children: o.cvv })
|
|
163
166
|
] })
|
|
164
167
|
] }),
|
|
165
|
-
/* @__PURE__ */
|
|
166
|
-
/* @__PURE__ */
|
|
167
|
-
/* @__PURE__ */
|
|
168
|
-
|
|
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:
|
|
171
|
-
onChangeText: (
|
|
173
|
+
value: t.zipCode,
|
|
174
|
+
onChangeText: (u) => b("zipCode", u),
|
|
172
175
|
keyboardType: "number-pad",
|
|
173
|
-
placeholder:
|
|
174
|
-
style:
|
|
176
|
+
placeholder: e ? "ZIP Code" : "Enter your ZIP Code",
|
|
177
|
+
style: r.input
|
|
175
178
|
}
|
|
176
179
|
),
|
|
177
|
-
!!
|
|
180
|
+
!!o.zipCode && /* @__PURE__ */ n(c, { style: r.error, children: o.zipCode })
|
|
178
181
|
] }),
|
|
179
|
-
!!
|
|
180
|
-
/* @__PURE__ */
|
|
181
|
-
|
|
182
|
+
!!y && /* @__PURE__ */ n(c, { style: r.submitError, children: y }),
|
|
183
|
+
/* @__PURE__ */ n(
|
|
184
|
+
F,
|
|
182
185
|
{
|
|
183
|
-
style: [
|
|
184
|
-
onPress:
|
|
185
|
-
disabled: !
|
|
186
|
-
children:
|
|
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
|
-
},
|
|
193
|
+
}, r = R.create({
|
|
191
194
|
container: {
|
|
192
195
|
padding: 16,
|
|
193
196
|
borderRadius: 12,
|