@flopay/react 1.11.4 → 1.11.5

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.
@@ -1,6 +1,6 @@
1
- "use strict";var Q=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Pe=(e,r)=>{for(var t in r)Q(e,t,{get:r[t],enumerable:!0})},Te=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Fe(r))!Ee.call(e,o)&&o!==t&&Q(e,o,{get:()=>r[o],enumerable:!(n=ve(r,o))||n.enumerable});return e};var Ve=e=>Te(Q({},"__esModule",{value:!0}),e);var Qe={};Pe(Qe,{FloPayCardSetup:()=>Re,FloPayCardSetupError:()=>$});module.exports=Ve(Qe);var X=require("@flopay/js/card-setup"),b=require("@flopay/shared"),u=require("react");function se(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(i=>i.startsWith("background")),a={};for(let[i,l]of Object.entries(e))i in t||o&&i.startsWith("background")||(a[i]=l);for(let i of n)a[i]=t[i];return a}var Ae=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Le(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Ae.has(r.charAt(0).toLowerCase()+r.slice(1))}function Be(e,r){return typeof r=="number"&&r!==0&&!Le(e)?`${r}px`:String(r).trim()}function ue(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Be(t,n)}}}var le={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ce(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?le.dark:le.light,a=r.colorText??(n?"#F1F5F9":"#262833"),i=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:a,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:i?.color??a}}function T(e){if(!e)return;let r=t=>{console.error("[FloPay] Merchant callback failed; checkout continued.",t)};try{Promise.resolve(e()).catch(r)}catch(t){r(t)}}var d=require("react/jsx-runtime");var Oe={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function de({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:i="You will be automatically redirected, do not close or navigate away from this window.",theme:l=Oe}){let s={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,d.jsx)("div",{"data-testid":"flopay-processing-overlay","data-status":e,role:"dialog","aria-modal":"true",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(2px)"},children:(0,d.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...l.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,d.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{animation:"flopay-spin 0.8s linear infinite"},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,d.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,d.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,d.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:20,strokeDashoffset:20,animation:"flopay-draw 0.4s 0.15s ease forwards"}})]})}),e==="error"&&(0,d.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,d.jsx)("path",{d:"M8 8l8 8M16 8l-8 8",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",style:{strokeDasharray:12,strokeDashoffset:12,animation:"flopay-draw 0.3s 0.1s ease forwards"}})]})})]}),(0,d.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&i!==null&&(0,d.jsx)("p",{style:s,children:i}),e==="error"&&r&&(0,d.jsx)("p",{style:s,children:r}),(0,d.jsx)("style",{children:`
1
+ "use strict";var ee=Object.defineProperty;var we=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Pe=(e,r)=>{for(var t in r)ee(e,t,{get:r[t],enumerable:!0})},Te=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Fe(r))!Ee.call(e,o)&&o!==t&&ee(e,o,{get:()=>r[o],enumerable:!(n=we(r,o))||n.enumerable});return e};var Ae=e=>Te(ee({},"__esModule",{value:!0}),e);var Qe={};Pe(Qe,{FloPayCardSetup:()=>xe,FloPayCardSetupError:()=>H});module.exports=Ae(Qe);var j=require("@flopay/js/card-setup"),m=require("@flopay/shared"),u=require("react");function se(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(a=>a.startsWith("background")),i={};for(let[a,l]of Object.entries(e))a in t||o&&a.startsWith("background")||(i[a]=l);for(let a of n)i[a]=t[a];return i}var Ve=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Le(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Ve.has(r.charAt(0).toLowerCase()+r.slice(1))}function Be(e,r){return typeof r=="number"&&r!==0&&!Le(e)?`${r}px`:String(r).trim()}function ue(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Be(t,n)}}}var le={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ce(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?le.dark:le.light,i=r.colorText??(n?"#F1F5F9":"#262833"),a=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:i,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:i,success:o.success,error:o.error},noteColor:a?.color??i}}function P(e){if(!e)return;let r=t=>{console.error("[FloPay] Merchant callback failed; checkout continued.",t)};try{Promise.resolve(e()).catch(r)}catch(t){r(t)}}var d=require("react/jsx-runtime");var Oe={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function de({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:i="PAYMENT FAILED",successNote:a="You will be automatically redirected, do not close or navigate away from this window.",theme:l=Oe}){let s={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,d.jsx)("div",{"data-testid":"flopay-processing-overlay","data-status":e,role:"dialog","aria-modal":"true",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(2px)"},children:(0,d.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...l.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,d.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{animation:"flopay-spin 0.8s linear infinite"},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,d.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,d.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,d.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:20,strokeDashoffset:20,animation:"flopay-draw 0.4s 0.15s ease forwards"}})]})}),e==="error"&&(0,d.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,d.jsx)("path",{d:"M8 8l8 8M16 8l-8 8",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",style:{strokeDasharray:12,strokeDashoffset:12,animation:"flopay-draw 0.3s 0.1s ease forwards"}})]})})]}),(0,d.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&a!==null&&(0,d.jsx)("p",{style:s,children:a}),e==="error"&&r&&(0,d.jsx)("p",{style:s,children:r}),(0,d.jsx)("style",{children:`
2
2
  @keyframes flopay-spin { to { transform: rotate(360deg); } }
3
3
  @keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
4
4
  @keyframes flopay-draw { to { stroke-dashoffset: 0; } }
5
5
  @keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
6
- `})]})})}var y=require("react");var Y=require("react"),fe=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;var re=require("react/jsx-runtime"),ee=new WeakSet;function pe({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:i,onReady:l,onError:s,onValidation:f}){let c=(0,y.useRef)(null),m=(0,y.useRef)(l),C=(0,y.useRef)(s),g=(0,y.useRef)(f);m.current=l,C.current=s,g.current=f;let V=(0,y.useRef)(o);V.current=o;let R=(0,y.useRef)(null),k=a??void 0,A=(0,y.useRef)(k);A.current=k;let O=(0,y.useRef)(void 0);return(0,y.useEffect)(()=>{let v=c.current;if(!v)return;let h=!0,G=!1,I=()=>{!h||G||(G=!0,m.current?.())},F=e.on("ready",()=>{I()}),_=e.on("error",w=>{C.current?.(w.message??"There was a problem loading the secure card form.")}),S=e.on("validation",w=>{g.current?.(w.message??null)}),H=A.current??(ee.has(e)?null:void 0),j={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...V.current?{theme:V.current}:{},...H===void 0?{}:{submitLabel:H}};return R.current=V.current??null,O.current=A.current,A.current!==void 0&&ee.add(e),e.mount(v,j).then(()=>{I()}).catch(w=>{h&&C.current?.(w instanceof Error?w.message:"Failed to load the secure card form.")}),()=>{h=!1,F(),_(),S(),e.unmount()}},[e,r,t,n]),fe(()=>{let v=c.current;v&&ue(v,i)},[i]),(0,y.useEffect)(()=>{o!==void 0&&(o===null&&R.current===null||(R.current=o,e.applyTheme?.(o)))},[e,o]),(0,y.useEffect)(()=>{k!==O.current&&(O.current=k,k!==void 0&&ee.add(e),e.setSubmitLabel?.(k??null))},[e,k]),(0,re.jsx)("div",{ref:c,"data-testid":"flopay-vault-card-fields"})}var ge=/^#([0-9a-f]{6})$/i,Ie=/^#([0-9a-f]{3})$/i,ye=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,be=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Me=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,_e=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Ne=/^(-?\d+(?:\.\d+)?)em$/,De=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,ze=/^[a-z][a-z0-9 -]{0,31}$/i,We=new Set(["none","uppercase","lowercase","capitalize"]);function he(e){if(typeof e!="string")return null;let r=e.trim(),t=ge.exec(r);if(t){let c=Number.parseInt(t[1],16);return{r:c>>16&255,g:c>>8&255,b:c&255,a:null}}let n=Ie.exec(r);if(n){let[c,m,C]=n[1].split("").map(g=>Number.parseInt(g+g,16));return{r:c,g:m,b:C,a:null}}let o=ye.exec(r),a=o?null:be.exec(r),i=o??a;if(!i)return null;let l=Number(i[1]),s=Number(i[2]),f=Number(i[3]);return l>255||s>255||f>255?null:{r:l,g:s,b:f,a:a?Number(a[4]):null}}function Ce({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(ge.test(r)||ye.test(r))return r;let t=be.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=he(r);return n?Ce(n):void 0}function U(e,r=.12){let t=he(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Ce({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=a}return o.trim()&&t.push(o.trim()),t}function B(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=_e.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e,r,t){if(typeof e!="string")return;let n=Ne.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function Ge(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=W(o," "),i=z(a[0]);if(!i)return;let l=n/(r.length-1)*100,s=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),f=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<f)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function He(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Me.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Ge(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Ye(e){return e.type==="solid"?{type:"solid",color:U(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:U(r.color)}))}}function Ue(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let f=z(s);if(f){t=f;continue}let c=B(s,-128,128);if(c===void 0)return;n.push(c)}if(!t||n.length<2||n.length>4)return;let[o,a,i=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||i>128||Math.abs(l)>32))return{color:t,inset:r,offsetX:o,offsetY:a,blur:i,spread:l}}function Xe(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(Ue);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function me(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>ze.test(t)).slice(0,4);return r.length>0?r:void 0}function je(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=B(r[0],0,64),n=B(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function qe(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function Se({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=He(n.background??n.backgroundColor),i=z(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&Ye(a),s={fontFamilies:me(n.fontFamily)??me(t),fontSize:B(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:qe(n.fontWeight)??600,letterSpacing:$e(n.letterSpacing,-.1,.5)??.01,lineHeight:B(n.lineHeight,.8,2)??1,textTransform:We.has(String(n.textTransform))?n.textTransform:"uppercase"},f=je(n.padding),c=Xe(n.boxShadow),m=B(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?B(De.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:s,...f?{spacing:f}:{},...c?{shadow:c}:{},...m===void 0?{}:{borderRadius:m},disabledOpacity:e?.theme==="night"?.8:.6,...C===void 0?{}:{backdropBlur:C}}}function Ke(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?U(n,r):e}function Ze(e){if(typeof e=="number"||typeof e=="string")return e}function ke({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=m=>typeof m=="string"&&m?m:void 0,a=r.submitButton,i=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=t==="buttons",s=r.nameInput,f=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",c=Se({appearance:e,buttonsStyles:r,fontFamily:f});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??Ke(i,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:f,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ze(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}var x=require("react/jsx-runtime"),$=class extends b.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function we(e,r={}){let t=e instanceof b.FloPayError?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new $(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Re({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:a,loading:i=null,onReady:l,onComplete:s,onDecline:f,onCancel:c,onValidation:m,onError:C}){let[g,V]=(0,u.useState)(null),[R,k]=(0,u.useState)(null),[A,O]=(0,u.useState)(null),[v,h]=(0,u.useState)(null),[G,I]=(0,u.useState)(null),F=(0,u.useRef)(!1),_=(0,u.useRef)(!1),S=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,b.resolveTheme)(o),[o]),H=(0,u.useMemo)(()=>typeof o=="object"?o:S?ke({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,o]),j=(0,u.useMemo)(()=>se(S?.buttonsLayout.cardFormContainer,a),[S,a]),w=(0,u.useMemo)(()=>S?ce(S):void 0,[S]),te=(0,u.useRef)(l),q=(0,u.useRef)(C),ne=(0,u.useRef)(s),oe=(0,u.useRef)(f),ae=(0,u.useRef)(c),ie=(0,u.useRef)(m),N=(0,u.useRef)(!1),K=(0,u.useRef)(!1),Z=(0,u.useRef)(0);return te.current=l,q.current=C,ne.current=s,oe.current=f,ae.current=c,ie.current=m,(0,u.useEffect)(()=>{let p=Z.current+1;return Z.current=p,()=>{queueMicrotask(()=>{Z.current===p&&(N.current||K.current||(K.current=!0,T(()=>{ae.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,L=new X.PaymentAPI((0,b.resolveBillingApiUrl)(t),{telemetry:n});return V(null),k(null),O(null),N.current=!1,K.current=!1,(async()=>{try{if(!e.trim())throw new b.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new b.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await L.getUnifiedCheckoutSession(e,r);if(!p)return;let E=D.data.session;if(!E||!(0,b.isCardSetupCheckoutSession)(E))throw new b.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let M=E.vault;if(M?.html?.trim()||(M=await L.getVaultCapture(e,r)),!M.html?.trim())throw new b.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!p)return;k(M),V(new X.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!p)return;let E=we(D);N.current=!0,O(E),T(()=>q.current?.(E))}})(),()=>{p=!1,L.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!g)return;let p=!1;_.current=!1,F.current=!1;let L=g.on("submitting",()=>{F.current=!0,I(null),h("processing")}),D=g.on("complete",P=>{N.current=!0,F.current=!1,h("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,T(()=>{ne.current?.({status:"succeeded",sessionId:e,...P.paymentMethod?{paymentMethod:P.paymentMethod}:{}})}),p||h(null))))()}),E=g.on("decline",P=>{N.current=!0,F.current=!1,I(P.message??null),h("error"),T(()=>{oe.current?.({status:"declined",sessionId:e,...P.declineReason?{reason:P.declineReason}:{},...P.message?{message:P.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),p||h(null)))()}),M=g.on("challenge_dismissed",()=>{h(null)});return()=>{p=!0,L(),D(),E(),M()}},[g,e]),A?(0,x.jsx)("div",{role:"alert",children:A.message}):!g||!R?.html?(0,x.jsx)(x.Fragment,{children:i}):(0,x.jsxs)(x.Fragment,{children:[v&&(0,x.jsx)(de,{status:v,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...w?{theme:w}:{}}),(0,x.jsx)(pe,{capture:g,html:R.html,messageToken:R.messageToken,expectedOrigin:R.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{T(()=>te.current?.())},onValidation:p=>{T(()=>ie.current?.(p))},onError:p=>{if(!p)return;F.current&&(F.current=!1,I(p),h("error"),setTimeout(()=>h(null),400));let L=we(new Error(p),{code:"card_setup_widget_failed",retryable:!0});T(()=>q.current?.(L))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
6
+ `})]})})}var h=require("react");var X=require("react"),fe=typeof window>"u"?X.useEffect:X.useLayoutEffect;var te=require("react/jsx-runtime"),re=new WeakSet;function pe({capture:e,html:r,messageToken:t,expectedOrigin:n,verificationRequired:o,theme:i,submitLabel:a,containerStyle:l,onReady:s,onError:f,onValidation:c}){let g=(0,h.useRef)(null),k=(0,h.useRef)(s),y=(0,h.useRef)(f),I=(0,h.useRef)(c);k.current=s,y.current=f,I.current=c;let v=(0,h.useRef)(i);v.current=i;let V=(0,h.useRef)(null),R=a??void 0,T=(0,h.useRef)(R);T.current=R;let L=(0,h.useRef)(void 0);return(0,h.useEffect)(()=>{let b=g.current;if(!b)return;let _=!0,B=!1,w=()=>{!_||B||(B=!0,k.current?.())},N=e.on("ready",()=>{w()}),S=e.on("error",F=>{y.current?.(F.message??"There was a problem loading the secure card form.")}),K=e.on("validation",F=>{I.current?.(F.message??null)}),U=T.current??(re.has(e)?null:void 0),Y={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...o?{verificationRequired:!0}:{},...v.current?{theme:v.current}:{},...U===void 0?{}:{submitLabel:U}};return V.current=v.current??null,L.current=T.current,T.current!==void 0&&re.add(e),e.mount(b,Y).then(()=>{w()}).catch(F=>{_&&y.current?.(F instanceof Error?F.message:"Failed to load the secure card form.")}),()=>{_=!1,N(),S(),K(),e.unmount()}},[e,r,t,n,o]),fe(()=>{let b=g.current;b&&ue(b,l)},[l]),(0,h.useEffect)(()=>{i!==void 0&&(i===null&&V.current===null||(V.current=i,e.applyTheme?.(i)))},[e,i]),(0,h.useEffect)(()=>{R!==L.current&&(L.current=R,R!==void 0&&re.add(e),e.setSubmitLabel?.(R??null))},[e,R]),(0,te.jsx)("div",{ref:g,"data-testid":"flopay-vault-card-fields"})}var ge=/^#([0-9a-f]{6})$/i,Me=/^#([0-9a-f]{3})$/i,ye=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,be=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Ie=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,_e=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Ne=/^(-?\d+(?:\.\d+)?)em$/,De=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,ze=/^[a-z][a-z0-9 -]{0,31}$/i,We=new Set(["none","uppercase","lowercase","capitalize"]);function he(e){if(typeof e!="string")return null;let r=e.trim(),t=ge.exec(r);if(t){let c=Number.parseInt(t[1],16);return{r:c>>16&255,g:c>>8&255,b:c&255,a:null}}let n=Me.exec(r);if(n){let[c,g,k]=n[1].split("").map(y=>Number.parseInt(y+y,16));return{r:c,g,b:k,a:null}}let o=ye.exec(r),i=o?null:be.exec(r),a=o??i;if(!a)return null;let l=Number(a[1]),s=Number(a[2]),f=Number(a[3]);return l>255||s>255||f>255?null:{r:l,g:s,b:f,a:i?Number(i[4]):null}}function Ce({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function $(e){if(typeof e!="string")return;let r=e.trim();if(ge.test(r)||ye.test(r))return r;let t=be.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=he(r);return n?Ce(n):void 0}function q(e,r=.12){let t=he(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Ce({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function G(e,r){let t=[],n=0,o="";for(let i of e){if(i==="("&&(n+=1),i===")"&&(n-=1),i===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=i}return o.trim()&&t.push(o.trim()),t}function A(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=_e.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e,r,t){if(typeof e!="string")return;let n=Ne.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function Ge(e){let r=G(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let i=G(o," "),a=$(i[0]);if(!a)return;let l=n/(r.length-1)*100,s=i[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(i[1])?.[1]),f=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<f)return;t.push({color:a,position:s})}return{type:"linearGradient",angle:0,stops:t}}function He(e){if(typeof e!="string")return;let r=e.trim(),t=$(r);if(t)return{type:"solid",color:t};let n=Ie.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=Ge(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function Ue(e){return e.type==="solid"?{type:"solid",color:q(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:q(r.color)}))}}function Ye(e){let r=!1,t,n=[];for(let s of G(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let f=$(s);if(f){t=f;continue}let c=A(s,-128,128);if(c===void 0)return;n.push(c)}if(!t||n.length<2||n.length>4)return;let[o,i,a=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(i)>64||a>128||Math.abs(l)>32))return{color:t,inset:r,offsetX:o,offsetY:i,blur:a,spread:l}}function Xe(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=G(r,",").map(Ye);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function me(e){if(typeof e!="string")return;let r=G(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>ze.test(t)).slice(0,4);return r.length>0?r:void 0}function qe(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=A(r[0],0,64),n=A(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function je(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function Se({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=He(n.background??n.backgroundColor),a=$(o?.colorPrimaryHover),l=a?{type:"solid",color:a}:i&&Ue(i),s={fontFamilies:me(n.fontFamily)??me(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:je(n.fontWeight)??600,letterSpacing:$e(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:We.has(String(n.textTransform))?n.textTransform:"uppercase"},f=qe(n.padding),c=Xe(n.boxShadow),g=A(n.borderRadius,0,9999),k=typeof n.backdropFilter=="string"?A(De.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:$(n.color)??"#FFFFFF",...i?{background:i,disabledBackground:i}:{},...l?{hoverBackground:l}:{},typography:s,...f?{spacing:f}:{},...c?{shadow:c}:{},...g===void 0?{}:{borderRadius:g},disabledOpacity:e?.theme==="night"?.8:.6,...k===void 0?{}:{backdropBlur:k}}}function Ke(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?q(n,r):e}function Ze(e){if(typeof e=="number"||typeof e=="string")return e}function ke({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=g=>typeof g=="string"&&g?g:void 0,i=r.submitButton,a=o(n?.colorPrimary)??o(i?.backgroundColor)??"#4A49FF",l=t==="buttons",s=r.nameInput,f=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",c=Se({appearance:e,buttonsStyles:r,fontFamily:f});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??Ke(a,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:f,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ze(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}var x=require("react/jsx-runtime"),H=class extends m.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function Re(e,r={}){let t=e instanceof m.FloPayError?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new H(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function xe({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:i,loading:a=null,onReady:l,onComplete:s,onDecline:f,onCancel:c,onValidation:g,onError:k}){let[y,I]=(0,u.useState)(null),[v,V]=(0,u.useState)(null),[R,T]=(0,u.useState)(null),[L,b]=(0,u.useState)(null),[_,B]=(0,u.useState)(null),w=(0,u.useRef)(!1),N=(0,u.useRef)(!1),S=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,m.resolveTheme)(o),[o]),K=(0,u.useMemo)(()=>typeof o=="object"?o:S?ke({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,o]),U=(0,u.useMemo)(()=>se(S?.buttonsLayout.cardFormContainer,i),[S,i]),Y=(0,u.useMemo)(()=>S?ce(S):void 0,[S]),F=(0,u.useRef)(l),Z=(0,u.useRef)(k),ne=(0,u.useRef)(s),oe=(0,u.useRef)(f),ie=(0,u.useRef)(c),ae=(0,u.useRef)(g),D=(0,u.useRef)(!1),J=(0,u.useRef)(!1),Q=(0,u.useRef)(0);return F.current=l,Z.current=k,ne.current=s,oe.current=f,ie.current=c,ae.current=g,(0,u.useEffect)(()=>{let p=Q.current+1;return Q.current=p,()=>{queueMicrotask(()=>{Q.current===p&&(D.current||J.current||(J.current=!0,P(()=>{ie.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,O=(0,m.resolveBillingApiUrl)(t),z=new j.PaymentAPI(O,{telemetry:n});return I(null),V(null),T(null),D.current=!1,J.current=!1,(async()=>{try{if(!e.trim())throw new m.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new m.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let W=await z.getUnifiedCheckoutSession(e,r);if(!p)return;let E=W.data.session;if(!E||!(0,m.isCardSetupCheckoutSession)(E))throw new m.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let C=E.vault;(0,m.isMountableVaultBlock)(C)||(C=await z.getVaultCapture(e,r));let M=(0,m.resolveVaultMountOptions)(C,{billingApiUrl:O,sessionId:e,nonce:r});if(!M)throw new m.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!p)return;V(M),I(new j.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(W){if(!p)return;let E=Re(W);D.current=!0,T(E),P(()=>Z.current?.(E))}})(),()=>{p=!1,z.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!y)return;let p=!1;N.current=!1,w.current=!1;let O=y.on("submitting",()=>{w.current=!0,B(null),b("processing")}),z=y.on("complete",C=>{D.current=!0,w.current=!1,b("success"),(async()=>(await new Promise(M=>setTimeout(M,600)),!N.current&&(N.current=!0,P(()=>{ne.current?.({status:"succeeded",sessionId:e,...C.paymentMethod?{paymentMethod:C.paymentMethod}:{}})}),p||b(null))))()}),W=y.on("decline",C=>{D.current=!0,w.current=!1,B(C.message??null),b("error"),P(()=>{oe.current?.({status:"declined",sessionId:e,...C.declineReason?{reason:C.declineReason}:{},...C.message?{message:C.message}:{}})}),(async()=>(await new Promise(M=>setTimeout(M,400)),p||b(null)))()}),E=y.on("challenge_dismissed",()=>{b(null)});return()=>{p=!0,O(),z(),W(),E()}},[y,e]),R?(0,x.jsx)("div",{role:"alert",children:R.message}):!y||!v?.html?(0,x.jsx)(x.Fragment,{children:a}):(0,x.jsxs)(x.Fragment,{children:[L&&(0,x.jsx)(de,{status:L,errorMessage:_,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...Y?{theme:Y}:{}}),(0,x.jsx)(pe,{capture:y,html:v.html,messageToken:v.messageToken,expectedOrigin:v.expectedOrigin,verificationRequired:v.verificationRequired,theme:K,containerStyle:U,onReady:()=>{P(()=>F.current?.())},onValidation:p=>{P(()=>ae.current?.(p))},onError:p=>{if(!p)return;w.current&&(w.current=!1,B(p),b("error"),setTimeout(()=>b(null),400));let O=Re(new Error(p),{code:"card_setup_widget_failed",retryable:!0});P(()=>Z.current?.(O))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
@@ -1 +1 @@
1
- import{k as e,m as t}from"./chunk-AZRGKPW7.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
1
+ import{k as e,m as t}from"./chunk-AW5LOT2K.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
@@ -0,0 +1 @@
1
+ import{a as De,b as Le,c as P,d as Ie,f as xe,g as Be,j as Ne,l as F}from"./chunk-AW5LOT2K.mjs";import{PaymentAPI as Ke,PciVaultCardCapture as lt}from"@flopay/js/card-setup";import{FloPayError as w,isCardSetupCheckoutSession as ct,isMountableVaultBlock as dt,resolveBillingApiUrl as ae,resolveTheme as pt,resolveVaultMountOptions as mt}from"@flopay/shared";import yt,{Suspense as ze,useCallback as V,useEffect as oe,useMemo as x,useRef as m,useState as M}from"react";import{PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as rt}from"@flopay/shared";var nt=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),at=new Set(["wallet","apm"]);function O(t){return typeof t=="string"&&t.trim().length>0}function ot(t){if(typeof t!="object"||t===null)return!1;let s=t;return O(s.family)&&O(s.paymentMethodType)}function st(t){let a=t.raw?.data?.currency;return O(a)?a.trim().toUpperCase():null}function Ye(t){let s=st(t),a=t.data.session?.advertisedPaymentMethods;if(!Array.isArray(a))return{card:!0,stripe:[],paypal:null,currency:s,skippedForMissingCurrency:[]};let i={card:!1,stripe:[],paypal:null,currency:s,skippedForMissingCurrency:[]},p=new Set;for(let u of a){if(!ot(u)||p.has(u.paymentMethodType))continue;let{family:l,paymentMethodType:f,providerType:B,publishableKey:R}=u;if(l==="card"){if(f!=="card")continue;i.card=!0}else if(at.has(l)){if(B!=="stripe"||f==="card"||!O(R))continue;if(s===null){i.skippedForMissingCurrency.includes(f)||i.skippedForMissingCurrency.push(f);continue}i.stripe.push({method:f,publishableKey:R,currency:s})}else if(l==="paypal"){if(f!==rt||B!=="paypal"||!O(R))continue;i.paypal={clientId:R,...O(u.environment)?{environment:u.environment}:{}}}else continue;p.add(f)}return i.paypal&&(i.stripe=i.stripe.filter(u=>u.method!=="paypal")),i}function j(t){return[...t.card?["card"]:[],...t.stripe.map(s=>s.method),...t.paypal?["paypal"]:[]]}function We(t){return j(t).length>0}function q(t){return nt.has(t)?"wallet":"apm"}var it=["setup_intent","setup_intent_client_secret","redirect_status"];function He(){if(typeof window>"u")return null;let t=new URLSearchParams(window.location.search);return!t.has("setup_intent")||!t.has("redirect_status")?null:{failed:t.get("redirect_status")==="failed"}}function Ge(){if(typeof window>"u")return;let t=new URL(window.location.href),s=!1;for(let a of it)t.searchParams.has(a)&&(t.searchParams.delete(a),s=!0);s&&window.history.replaceState(window.history.state,"",t.toString())}function je(t){return t==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}import{Fragment as $e,jsx as y,jsxs as ie}from"react/jsx-runtime";var ft=15,ht=2e3;function St(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function se(t){return new Promise(s=>setTimeout(s,t))}async function vt(t,s,a){if(!s.trim())throw new w("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new w("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let i=await t.getUnifiedCheckoutSession(s,a),p=i.data.session;if(!p||!ct(p))throw new w("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let u=Ye(i);if(!We(u)){let{skippedForMissingCurrency:l}=u,f=l.length>0?`FloPay: this setup session advertises only Stripe methods (${l.join(", ")}), and they need the session's currency, which the setup-session read did not carry.`:"FloPay: this setup session advertises no payment method.";throw new w(f,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:p,advertisement:u}}async function gt(t,s,a,i,p){let u=s.vault??null;dt(u)||(u=await t.getVaultCapture(a,i));let l=mt(u,{billingApiUrl:p,sessionId:a,nonce:i});if(!l)throw new w("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return l}var K=class extends yt.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(a){this.props.onFailed(a,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function Ot({branches:{StripeSetupMethod:t,PayPalSetupMethod:s},sessionId:a,nonce:i,billingApiUrl:p,telemetry:u,theme:l="modern-light",containerStyle:f,loading:B=null,onReady:R,onComplete:ue,onDecline:le,onCancel:ce,onValidation:de,onError:pe}){let[z]=M(He),[N,$]=M(null),[Je,J]=M(!1),[g,me]=M(null),[A,ye]=M(null),[fe,he]=M(null),[Y,h]=M(null),[Q,X]=M(()=>new Set),_=m(Q),Z=m(null);Z.current=N;let C=m(!1),ee=m(!1),D=m(!1),te=m(!1),re=m(0),W=m(0),k=m(!1),S=x(()=>typeof l=="object"?void 0:pt(l),[l]),Qe=x(()=>typeof l=="object"?l:S?Ne({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,l]),Xe=x(()=>De(S?.buttonsLayout.cardFormContainer,f),[S,f]),Se=x(()=>S?Le(S):void 0,[S]),c=m({sessionId:a,nonce:i,billingApiUrl:p,telemetry:u,onReady:R,onComplete:ue,onDecline:le,onCancel:ce,onValidation:de,onError:pe});c.current={sessionId:a,nonce:i,billingApiUrl:p,telemetry:u,onReady:R,onComplete:ue,onDecline:le,onCancel:ce,onValidation:de,onError:pe},oe(()=>{k.current=!0;let e=re.current+1;return re.current=e,()=>{k.current=!1,W.current+=1,queueMicrotask(()=>{re.current===e&&(D.current||te.current||(te.current=!0,P(()=>{c.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let T=V((e,r)=>{D.current=!0,C.current=!1,h({status:"success",wording:e,message:null}),(async()=>(await se(600),!ee.current&&(ee.current=!0,P(()=>{c.current.onComplete?.({status:"succeeded",sessionId:c.current.sessionId,...r?{paymentMethod:r}:{}})}),k.current&&h(null))))()},[]),U=V((e,r)=>{D.current=!0,C.current=!1,h({status:"error",wording:e,message:r.message??null}),P(()=>{c.current.onDecline?.({status:"declined",sessionId:c.current.sessionId,...r.reason?{reason:r.reason}:{},...r.message?{message:r.message}:{}})}),(async()=>(await se(400),k.current&&h(null)))()},[]),b=V((e,r)=>{C.current?(C.current=!1,h({status:"error",wording:e,message:r.message}),setTimeout(()=>{k.current&&h(null)},400)):h(null),P(()=>c.current.onError?.(r))},[]),H=V(async e=>{let r=W.current+1;W.current=r;let o=()=>!k.current||r!==W.current;C.current=!0,h({status:"processing",wording:"payment_method",message:null});let d=new Ke(ae(c.current.billingApiUrl),{telemetry:c.current.telemetry});try{for(let n=0;n<ft;n+=1){if((n>0||e.waitFirst)&&await se(ht),o())return;let v=await d.getUnifiedCheckoutSession(c.current.sessionId,c.current.nonce);if(o())return;let E=v.data.session?.status;if(E==="complete"){J(!0),T("payment_method");return}if(E==="expired")throw new w("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new w("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(n){if(o())return;let v=n instanceof w&&n.code==="payment_method_setup_unverified";b("payment_method",F(n,v?{retryable:!0}:{}))}finally{d.destroy()}},[b,T]);oe(()=>{let e=!0,r=ae(p),o=new Ke(r,{telemetry:u});$(null),J(!1),me(null),ye(null),he(null);let d=new Set;return _.current=d,X(d),D.current=!1,te.current=!1,ee.current=!1,(async()=>{try{let{session:n,advertisement:v}=await vt(o,a,i);if(!e)return;let E={advertisement:v,customer:St(n),...n.futureUse?{futureUse:n.futureUse}:{},...n.futureUseUnsupported?{futureUseUnsupported:n.futureUseUnsupported}:{}};if(z){if(Ge(),n.status==="complete"){J(!0),$(E),T("payment_method");return}z.failed?U("payment_method",{reason:"redirect_failed"}):H({waitFirst:!0})}let Ve=v.card?await gt(o,n,a,i,r):null;if(!e)return;$(E),Ve&&(ye(Ve),me(new lt({sessionId:a,operation:"card_setup",telemetry:u})))}catch(n){if(!e)return;let v=F(n);D.current=!0,he(v),P(()=>c.current.onError?.(v))}})(),()=>{e=!1,o.destroy()}},[p,i,z,U,T,a,u,H]),oe(()=>{if(!g)return;C.current=!1;let e=g.on("submitting",()=>{C.current=!0,h({status:"processing",wording:"card",message:null})}),r=g.on("complete",n=>{T("card",n.paymentMethod)}),o=g.on("decline",n=>{U("card",{...n.declineReason?{reason:n.declineReason}:{},...n.message?{message:n.message}:{}})}),d=g.on("challenge_dismissed",()=>{h(null)});return()=>{e(),r(),o(),d()}},[g,U,T]);let ve=V((e,r,o)=>{if(o.retryable){b("payment_method",F(r,o));return}if(_.current.has(e))return;let d=new Set(_.current);d.add(e),_.current=d,X(d);let n=Z.current?.advertisement,v=n?j(n).some(E=>!d.has(E)):!1;b("payment_method",F(r,{code:o.code,retryable:v}))},[b]),ge=x(()=>({onSubmitting:()=>{C.current=!0,h({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{H({waitFirst:!1})},onDeclined:e=>U("payment_method",e),onValidation:e=>{P(()=>c.current.onValidation?.(e))},onAbandoned:()=>{C.current=!1,h(null)}}),[U,H]),Ce=m(ve);Ce.current=ve;let Pe=m(new Map),G=e=>{let r=Pe.current.get(e);if(r)return r;let o=(d,n)=>Ce.current(e,d,n);return Pe.current.set(e,o),o},be=V(e=>{if(_.current.has(e))return;let r=new Set(_.current);r.add(e),_.current=r,X(r);let o=Z.current?.advertisement;o&&j(o).some(n=>!r.has(n))||b("payment_method",F(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[b]),Me=m(be);Me.current=be;let we=m(new Map),Re=e=>{let r=we.current.get(e);if(r)return r;let o=()=>Me.current(e);return we.current.set(e,o),o},_e=Y?y(Ie,{status:Y.status,errorMessage:Y.message,...je(Y.wording),successNote:null,...Se?{theme:Se}:{}}):null;if(fe)return y("div",{role:"alert",children:fe.message});if(!N||Je)return ie($e,{children:[_e,N?null:B]});let{advertisement:L,customer:Ze,futureUse:Ee,futureUseUnsupported:Fe}=N,Ae=ae(p),ke=u===void 0?{}:{telemetry:u},ne=L.stripe.filter(({method:e})=>!Q.has(e)),I=Q.has("paypal")?null:L.paypal,Te=!!(L.card&&g&&A?.html),Ue=({method:e,publishableKey:r,currency:o})=>y("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:y(K,{onFailed:G(e),children:y(ze,{fallback:null,children:y(t,{method:e,category:q(e),publishableKey:r,currency:o,...Ee?{futureUse:Ee}:{},...Fe?{futureUseUnsupported:Fe}:{},sessionId:a,nonce:i,billingApiUrl:Ae,...ke,...S?{appearance:S.appearance,buttonsLayout:S.buttonsLayout}:{},...typeof l=="string"?{themeId:l}:{},...ge,onFailed:G(e),onUnavailable:Re(e)})})})},e),et=ne.filter(({method:e})=>q(e)==="wallet"),tt=ne.filter(({method:e})=>q(e)!=="wallet"),Oe=ne.length>0||I!==null;return ie($e,{children:[_e,Oe?ie("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[et.map(Ue),I?y("div",{"data-flopay-payment-method":"paypal",children:y(K,{onFailed:G("paypal"),children:y(ze,{fallback:null,children:y(s,{clientId:I.clientId,...I.environment?{environment:I.environment}:{},...L.currency?{currency:L.currency}:{},sessionId:a,nonce:i,billingApiUrl:Ae,customer:Ze,...ke,...ge,onFailed:G("paypal"),onUnavailable:Re("paypal")})})})}):null,tt.map(Ue)]}):null,Te&&Oe?y(Be,{label:"or add a card"}):null,Te&&g&&A?.html?y("div",{"data-flopay-payment-method":"card",children:y(xe,{capture:g,html:A.html,messageToken:A.messageToken,expectedOrigin:A.expectedOrigin,verificationRequired:A.verificationRequired,theme:Qe,containerStyle:Xe,onReady:()=>{P(()=>c.current.onReady?.())},onValidation:e=>{P(()=>c.current.onValidation?.(e))},onError:e=>{e&&b("card",F(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{Ot as a};
@@ -0,0 +1,6 @@
1
+ import{useEffect as re,useRef as x}from"react";function le(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(a=>a.startsWith("background")),i={};for(let[a,u]of Object.entries(e))a in t||o&&a.startsWith("background")||(i[a]=u);for(let a of n)i[a]=t[a];return i}var Fe=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Te(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Fe.has(r.charAt(0).toLowerCase()+r.slice(1))}function Pe(e,r){return typeof r=="number"&&r!==0&&!Te(e)?`${r}px`:String(r).trim()}function ce(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Pe(t,n)}}}import{useEffect as Ae,useLayoutEffect as Ve}from"react";var de=typeof window>"u"?Ae:Ve;import{jsx as X,jsxs as Le}from"react/jsx-runtime";var te=new WeakSet;function fe({capture:e,html:r,messageToken:t,expectedOrigin:n,verificationRequired:o,theme:i,submitLabel:a,containerStyle:u,onReady:s,onError:c,onValidation:l}){let f=x(null),C=x(s),p=x(c),I=x(l);C.current=s,p.current=c,I.current=l;let S=x(i);S.current=i;let P=x(null),k=a??void 0,F=x(k);F.current=k;let A=x(void 0);return re(()=>{let m=f.current;if(!m)return;let _=!0,V=!1,R=()=>{!_||V||(V=!0,C.current?.())},N=e.on("ready",()=>{R()}),b=e.on("error",v=>{p.current?.(v.message??"There was a problem loading the secure card form.")}),Z=e.on("validation",v=>{I.current?.(v.message??null)}),U=F.current??(te.has(e)?null:void 0),Y={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...o?{verificationRequired:!0}:{},...S.current?{theme:S.current}:{},...U===void 0?{}:{submitLabel:U}};return P.current=S.current??null,A.current=F.current,F.current!==void 0&&te.add(e),e.mount(m,Y).then(()=>{R()}).catch(v=>{_&&p.current?.(v instanceof Error?v.message:"Failed to load the secure card form.")}),()=>{_=!1,N(),b(),Z(),e.unmount()}},[e,r,t,n,o]),de(()=>{let m=f.current;m&&ce(m,u)},[u]),re(()=>{i!==void 0&&(i===null&&P.current===null||(P.current=i,e.applyTheme?.(i)))},[e,i]),re(()=>{k!==A.current&&(A.current=k,k!==void 0&&te.add(e),e.setSubmitLabel?.(k??null))},[e,k]),X("div",{ref:f,"data-testid":"flopay-vault-card-fields"})}function fr({label:e}){return Le("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[X("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),X("span",{children:e}),X("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}import{PaymentAPI as Je,PciVaultCardCapture as Qe}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as er,isMountableVaultBlock as rr,resolveBillingApiUrl as tr,resolveTheme as nr,resolveVaultMountOptions as or}from"@flopay/shared";import{useEffect as ne,useMemo as j,useRef as h,useState as H}from"react";var pe={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function me(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?pe.dark:pe.light,i=r.colorText??(n?"#F1F5F9":"#262833"),a=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:i,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:i,success:o.success,error:o.error},noteColor:a?.color??i}}function E(e){if(!e)return;let r=t=>{console.error("[FloPay] Merchant callback failed; checkout continued.",t)};try{Promise.resolve(e()).catch(r)}catch(t){r(t)}}import{jsx as y,jsxs as O}from"react/jsx-runtime";var Be={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ge({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:i="PAYMENT FAILED",successNote:a="You will be automatically redirected, do not close or navigate away from this window.",theme:u=Be}){let s={fontSize:13,color:u.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return y("div",{"data-testid":"flopay-processing-overlay","data-status":e,role:"dialog","aria-modal":"true",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(2px)"},children:O("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...u.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[O("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&O("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{animation:"flopay-spin 0.8s linear infinite"},children:[y("circle",{cx:"12",cy:"12",r:"10",stroke:u.spinnerTrackColor,strokeWidth:"3"}),y("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:u.spinnerAccentColor})]}),e==="success"&&y("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:O("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[y("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),y("path",{d:"M7 12.5l3 3 7-7",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:20,strokeDashoffset:20,animation:"flopay-draw 0.4s 0.15s ease forwards"}})]})}),e==="error"&&y("div",{style:{animation:"flopay-shake 0.4s ease"},children:O("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[y("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),y("path",{d:"M8 8l8 8M16 8l-8 8",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",style:{strokeDasharray:12,strokeDashoffset:12,animation:"flopay-draw 0.3s 0.1s ease forwards"}})]})})]}),O("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:u.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&a!==null&&y("p",{style:s,children:a}),e==="error"&&r&&y("p",{style:s,children:r}),y("style",{children:`
2
+ @keyframes flopay-spin { to { transform: rotate(360deg); } }
3
+ @keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
4
+ @keyframes flopay-draw { to { stroke-dashoffset: 0; } }
5
+ @keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
6
+ `})]})})}var be=/^#([0-9a-f]{6})$/i,Oe=/^#([0-9a-f]{3})$/i,he=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ce=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Me=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Ie=/^(-?\d+(?:\.\d+)?)(?:px)?$/,_e=/^(-?\d+(?:\.\d+)?)em$/,Ne=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,De=/^[a-z][a-z0-9 -]{0,31}$/i,ze=new Set(["none","uppercase","lowercase","capitalize"]);function Se(e){if(typeof e!="string")return null;let r=e.trim(),t=be.exec(r);if(t){let l=Number.parseInt(t[1],16);return{r:l>>16&255,g:l>>8&255,b:l&255,a:null}}let n=Oe.exec(r);if(n){let[l,f,C]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:l,g:f,b:C,a:null}}let o=he.exec(r),i=o?null:Ce.exec(r),a=o??i;if(!a)return null;let u=Number(a[1]),s=Number(a[2]),c=Number(a[3]);return u>255||s>255||c>255?null:{r:u,g:s,b:c,a:i?Number(i[4]):null}}function ke({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function $(e){if(typeof e!="string")return;let r=e.trim();if(be.test(r)||he.test(r))return r;let t=Ce.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Se(r);return n?ke(n):void 0}function q(e,r=.12){let t=Se(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ke({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function G(e,r){let t=[],n=0,o="";for(let i of e){if(i==="("&&(n+=1),i===")"&&(n-=1),i===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=i}return o.trim()&&t.push(o.trim()),t}function T(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=Ie.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(e,r,t){if(typeof e!="string")return;let n=_e.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e){let r=G(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let i=G(o," "),a=$(i[0]);if(!a)return;let u=n/(r.length-1)*100,s=i[1]===void 0?u:Number(/^(\d+(?:\.\d+)?)%$/.exec(i[1])?.[1]),c=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<c)return;t.push({color:a,position:s})}return{type:"linearGradient",angle:0,stops:t}}function Ge(e){if(typeof e!="string")return;let r=e.trim(),t=$(r);if(t)return{type:"solid",color:t};let n=Me.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=$e(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function He(e){return e.type==="solid"?{type:"solid",color:q(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:q(r.color)}))}}function Ue(e){let r=!1,t,n=[];for(let s of G(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=$(s);if(c){t=c;continue}let l=T(s,-128,128);if(l===void 0)return;n.push(l)}if(!t||n.length<2||n.length>4)return;let[o,i,a=0,u=0]=n;if(!(Math.abs(o)>64||Math.abs(i)>64||a>128||Math.abs(u)>32))return{color:t,inset:r,offsetX:o,offsetY:i,blur:a,spread:u}}function Ye(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=G(r,",").map(Ue);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ye(e){if(typeof e!="string")return;let r=G(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>De.test(t)).slice(0,4);return r.length>0?r:void 0}function Xe(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=T(r[0],0,64),n=T(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function qe(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function Re({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=Ge(n.background??n.backgroundColor),a=$(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&He(i),s={fontFamilies:ye(n.fontFamily)??ye(t),fontSize:T(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:qe(n.fontWeight)??600,letterSpacing:We(n.letterSpacing,-.1,.5)??.01,lineHeight:T(n.lineHeight,.8,2)??1,textTransform:ze.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Xe(n.padding),l=Ye(n.boxShadow),f=T(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?T(Ne.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:$(n.color)??"#FFFFFF",...i?{background:i,disabledBackground:i}:{},...u?{hoverBackground:u}:{},typography:s,...c?{spacing:c}:{},...l?{shadow:l}:{},...f===void 0?{}:{borderRadius:f},disabledOpacity:e?.theme==="night"?.8:.6,...C===void 0?{}:{backdropBlur:C}}}function je(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?q(n,r):e}function Ke(e){if(typeof e=="number"||typeof e=="string")return e}function ve({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=f=>typeof f=="string"&&f?f:void 0,i=r.submitButton,a=o(n?.colorPrimary)??o(i?.backgroundColor)??"#4A49FF",u=t==="buttons",s=r.nameInput,c=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",l=Re({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??je(a,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ke(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as Ee,jsx as K,jsxs as ir}from"react/jsx-runtime";var oe=class extends M{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function xe(e,r={}){let t=e instanceof M?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new oe(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Vr({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:i,loading:a=null,onReady:u,onComplete:s,onDecline:c,onCancel:l,onValidation:f,onError:C}){let[p,I]=H(null),[S,P]=H(null),[k,F]=H(null),[A,m]=H(null),[_,V]=H(null),R=h(!1),N=h(!1),b=j(()=>typeof o=="object"?void 0:nr(o),[o]),Z=j(()=>typeof o=="object"?o:b?ve({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),U=j(()=>le(b?.buttonsLayout.cardFormContainer,i),[b,i]),Y=j(()=>b?me(b):void 0,[b]),v=h(u),J=h(C),ie=h(s),ae=h(c),se=h(l),ue=h(f),D=h(!1),Q=h(!1),ee=h(0);return v.current=u,J.current=C,ie.current=s,ae.current=c,se.current=l,ue.current=f,ne(()=>{let d=ee.current+1;return ee.current=d,()=>{queueMicrotask(()=>{ee.current===d&&(D.current||Q.current||(Q.current=!0,E(()=>{se.current?.({status:"cancelled",sessionId:e})})))})}},[e]),ne(()=>{let d=!0,L=tr(t),z=new Je(L,{telemetry:n});return I(null),P(null),F(null),D.current=!1,Q.current=!1,(async()=>{try{if(!e.trim())throw new M("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new M("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let W=await z.getUnifiedCheckoutSession(e,r);if(!d)return;let w=W.data.session;if(!w||!er(w))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let g=w.vault;rr(g)||(g=await z.getVaultCapture(e,r));let B=or(g,{billingApiUrl:L,sessionId:e,nonce:r});if(!B)throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;P(B),I(new Qe({sessionId:e,operation:"card_setup",telemetry:n}))}catch(W){if(!d)return;let w=xe(W);D.current=!0,F(w),E(()=>J.current?.(w))}})(),()=>{d=!1,z.destroy()}},[t,r,e,n]),ne(()=>{if(!p)return;let d=!1;N.current=!1,R.current=!1;let L=p.on("submitting",()=>{R.current=!0,V(null),m("processing")}),z=p.on("complete",g=>{D.current=!0,R.current=!1,m("success"),(async()=>(await new Promise(B=>setTimeout(B,600)),!N.current&&(N.current=!0,E(()=>{ie.current?.({status:"succeeded",sessionId:e,...g.paymentMethod?{paymentMethod:g.paymentMethod}:{}})}),d||m(null))))()}),W=p.on("decline",g=>{D.current=!0,R.current=!1,V(g.message??null),m("error"),E(()=>{ae.current?.({status:"declined",sessionId:e,...g.declineReason?{reason:g.declineReason}:{},...g.message?{message:g.message}:{}})}),(async()=>(await new Promise(B=>setTimeout(B,400)),d||m(null)))()}),w=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,L(),z(),W(),w()}},[p,e]),k?K("div",{role:"alert",children:k.message}):!p||!S?.html?K(Ee,{children:a}):ir(Ee,{children:[A&&K(ge,{status:A,errorMessage:_,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...Y?{theme:Y}:{}}),K(fe,{capture:p,html:S.html,messageToken:S.messageToken,expectedOrigin:S.expectedOrigin,verificationRequired:S.verificationRequired,theme:Z,containerStyle:U,onReady:()=>{E(()=>v.current?.())},onValidation:d=>{E(()=>ue.current?.(d))},onError:d=>{if(!d)return;R.current&&(R.current=!1,V(d),m("error"),setTimeout(()=>m(null),400));let L=xe(new Error(d),{code:"card_setup_widget_failed",retryable:!0});E(()=>J.current?.(L))}})]})}export{le as a,me as b,E as c,ge as d,de as e,fe as f,fr as g,je as h,Ke as i,ve as j,oe as k,xe as l,Vr as m};