@flopay/react 1.9.10 → 1.9.13

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 CHANGED
@@ -80,6 +80,29 @@ whitespace normalization, so an authorised wallet name can replace it. Name
80
80
  selection is atomic: first and last name always come from one source, and are
81
81
  omitted when neither source is usable. Email precedence is unchanged.
82
82
 
83
+ #### Wallet confirmation recovery
84
+
85
+ Google Pay and Apple Pay authentication may legitimately outlive the SDK's
86
+ provider observation threshold. The SDK does not cancel that provider promise.
87
+ Instead, it retrieves the original PaymentIntent or SetupIntent with the same
88
+ client secret and routes the provider promise and status read through one
89
+ settlement gate:
90
+
91
+ - an authoritative success continues to `/process` exactly once;
92
+ - `canceled` or `requires_payment_method` is treated as authoritative,
93
+ non-chargeable terminal evidence and exposes wallet retry;
94
+ - `requires_action`, an unavailable/mismatched status, or a failed/bounded-out
95
+ status read keeps payment submission locked and exposes only **Check payment
96
+ status**.
97
+
98
+ Rejected confirmations, returned technical errors, and malformed fulfilled
99
+ results use this same recovery contract. A lost intent-create response also
100
+ reuses the authorization-attempt UUID on deliberate retry, so provider
101
+ idempotency cannot mint a second intent. A bounded pending-confirmation handoff
102
+ keeps teardown/remount from exposing another wallet surface while the first
103
+ intent may still complete. Existing component props and merchant callbacks are
104
+ unchanged.
105
+
83
106
  #### Merchant instrument feed
84
107
 
85
108
  Use `onInstrument` on `FloPayCheckout` or `FloPayProvider` to forward a stable,
@@ -3,4 +3,4 @@
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 k=require("react");var z=require("react"),se=typeof window>"u"?z.useEffect:z.useLayoutEffect;var le=require("react/jsx-runtime");function ue({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,containerStyle:a,onReady:i,onError:l,onValidation:s}){let c=(0,k.useRef)(null),d=(0,k.useRef)(i),m=(0,k.useRef)(l),C=(0,k.useRef)(s);d.current=i,m.current=l,C.current=s;let g=(0,k.useRef)(o);g.current=o;let T=(0,k.useRef)(null);return(0,k.useEffect)(()=>{let S=c.current;if(!S)return;let V=!0,A=!1,L=()=>{!V||A||(A=!0,d.current?.())},D=e.on("ready",()=>{L()}),x=e.on("error",y=>{m.current?.(y.message??"There was a problem loading the secure card form.")}),G=e.on("validation",y=>{C.current?.(y.message??null)}),B={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...g.current?{theme:g.current}:{}};return T.current=g.current??null,e.mount(S,B).then(()=>{L()}).catch(y=>{V&&m.current?.(y instanceof Error?y.message:"Failed to load the secure card form.")}),()=>{V=!1,D(),x(),G(),e.unmount()}},[e,r,t,n]),se(()=>{let S=c.current;S&&ne(S,a)},[a]),(0,k.useEffect)(()=>{o!==void 0&&(o===null&&T.current===null||(T.current=o,e.applyTheme?.(o)))},[e,o]),(0,le.jsx)("div",{ref:c,"data-testid":"flopay-vault-card-fields"})}var de=/^#([0-9a-f]{6})$/i,Be=/^#([0-9a-f]{3})$/i,fe=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,pe=/^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,Oe=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Ie=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Me=/^(-?\d+(?:\.\d+)?)em$/,_e=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Ne=/^[a-z][a-z0-9 -]{0,31}$/i,De=new Set(["none","uppercase","lowercase","capitalize"]);function me(e){if(typeof e!="string")return null;let r=e.trim(),t=de.exec(r);if(t){let d=Number.parseInt(t[1],16);return{r:d>>16&255,g:d>>8&255,b:d&255,a:null}}let n=Be.exec(r);if(n){let[d,m,C]=n[1].split("").map(g=>Number.parseInt(g+g,16));return{r:d,g:m,b:C,a:null}}let o=fe.exec(r),a=o?null:pe.exec(r),i=o??a;if(!i)return null;let l=Number(i[1]),s=Number(i[2]),c=Number(i[3]);return l>255||s>255||c>255?null:{r:l,g:s,b:c,a:a?Number(a[4]):null}}function ge({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 M(e){if(typeof e!="string")return;let r=e.trim();if(de.test(r)||fe.test(r))return r;let t=pe.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=me(r);return n?ge(n):void 0}function W(e,r=.12){let t=me(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ge({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function _(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 P(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 ze(e,r,t){if(typeof e!="string")return;let n=Me.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(e){let r=_(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=_(o," "),i=M(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]),c=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<c)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function $e(e){if(typeof e!="string")return;let r=e.trim(),t=M(r);if(t)return{type:"solid",color:t};let n=Oe.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=We(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Ge(e){return e.type==="solid"?{type:"solid",color:W(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:W(r.color)}))}}function He(e){let r=!1,t,n=[];for(let s of _(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=M(s);if(c){t=c;continue}let d=P(s,-128,128);if(d===void 0)return;n.push(d)}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 Ye(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=_(r,",").map(He);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ce(e){if(typeof e!="string")return;let r=_(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>Ne.test(t)).slice(0,4);return r.length>0?r:void 0}function Ue(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=P(r[0],0,64),n=P(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function Xe(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 ye({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=$e(n.background??n.backgroundColor),i=M(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&Ge(a),s={fontFamilies:ce(n.fontFamily)??ce(t),fontSize:P(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Xe(n.fontWeight)??600,letterSpacing:ze(n.letterSpacing,-.1,.5)??.01,lineHeight:P(n.lineHeight,.8,2)??1,textTransform:De.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Ue(n.padding),d=Ye(n.boxShadow),m=P(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?P(_e.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:M(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:s,...c?{spacing:c}:{},...d?{shadow:d}:{},...m===void 0?{}:{borderRadius:m},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)?W(n,r):e}function qe(e){if(typeof e=="number"||typeof e=="string")return e}function he({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,c=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",d=ye({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??je(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:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(qe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...d?{submitButton:d}:{}}}var w=require("react/jsx-runtime"),N=class extends b.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function Ce(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 N(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 Se({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:a,loading:i=null,onReady:l,onComplete:s,onDecline:c,onCancel:d,onValidation:m,onError:C}){let[g,T]=(0,u.useState)(null),[S,V]=(0,u.useState)(null),[A,L]=(0,u.useState)(null),[D,x]=(0,u.useState)(null),[G,B]=(0,u.useState)(null),y=(0,u.useRef)(!1),H=(0,u.useRef)(!1),R=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,b.resolveTheme)(o),[o]),ke=(0,u.useMemo)(()=>typeof o=="object"?o:R?he({appearance:R.appearance,buttonsStyles:R.buttonsLayout,layout:"default"}):null,[R,o]),we=(0,u.useMemo)(()=>te(R?.buttonsLayout.cardFormContainer,a),[R,a]),K=(0,u.useMemo)(()=>R?ae(R):void 0,[R]),Z=(0,u.useRef)(l),Y=(0,u.useRef)(C),J=(0,u.useRef)(s),Q=(0,u.useRef)(c),ee=(0,u.useRef)(d),re=(0,u.useRef)(m),O=(0,u.useRef)(!1),U=(0,u.useRef)(!1),X=(0,u.useRef)(0);return Z.current=l,Y.current=C,J.current=s,Q.current=c,ee.current=d,re.current=m,(0,u.useEffect)(()=>{let p=X.current+1;return X.current=p,()=>{queueMicrotask(()=>{X.current===p&&(O.current||U.current||(U.current=!0,F(()=>{ee.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,E=new $.PaymentAPI((0,b.resolveBillingApiUrl)(t),{telemetry:n});return T(null),V(null),L(null),O.current=!1,U.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 I=await E.getUnifiedCheckoutSession(e,r);if(!p)return;let v=I.data.session;if(!v||!(0,b.isCardSetupCheckoutSession)(v))throw new b.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let h=v.vault;if(h?.html?.trim()||(h=await E.getVaultCapture(e,r)),!h.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;V(h),T(new $.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(I){if(!p)return;let v=Ce(I);O.current=!0,L(v),F(()=>Y.current?.(v))}})(),()=>{p=!1,E.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!g)return;let p=!1;H.current=!1,y.current=!1;let E=g.on("submitting",()=>{y.current=!0,B(null),x("processing")}),I=g.on("complete",h=>{O.current=!0,y.current=!1,x("success"),(async()=>(await new Promise(j=>setTimeout(j,1200)),!H.current&&(H.current=!0,F(()=>{J.current?.({status:"succeeded",sessionId:e,...h.paymentMethod?{paymentMethod:h.paymentMethod}:{}})}),p||x(null))))()}),v=g.on("decline",h=>{O.current=!0,y.current=!1,B(h.message??null),x("error"),F(()=>{Q.current?.({status:"declined",sessionId:e,...h.declineReason?{reason:h.declineReason}:{},...h.message?{message:h.message}:{}})}),(async()=>(await new Promise(j=>setTimeout(j,1500)),p||x(null)))()});return()=>{p=!0,E(),I(),v()}},[g,e]),A?(0,w.jsx)("div",{role:"alert",children:A.message}):!g||!S?.html?(0,w.jsx)(w.Fragment,{children:i}):(0,w.jsxs)(w.Fragment,{children:[D&&(0,w.jsx)(ie,{status:D,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...K?{theme:K}:{}}),(0,w.jsx)(ue,{capture:g,html:S.html,messageToken:S.messageToken,expectedOrigin:S.expectedOrigin,theme:ke,containerStyle:we,onReady:()=>{F(()=>Z.current?.())},onValidation:p=>{F(()=>re.current?.(p))},onError:p=>{if(!p)return;y.current&&(y.current=!1,B(p),x("error"),setTimeout(()=>x(null),1500));let E=Ce(new Error(p),{code:"card_setup_widget_failed",retryable:!0});F(()=>Y.current?.(E))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
6
+ `})]})})}var k=require("react");var z=require("react"),se=typeof window>"u"?z.useEffect:z.useLayoutEffect;var le=require("react/jsx-runtime");function ue({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,containerStyle:a,onReady:i,onError:l,onValidation:s}){let c=(0,k.useRef)(null),d=(0,k.useRef)(i),m=(0,k.useRef)(l),C=(0,k.useRef)(s);d.current=i,m.current=l,C.current=s;let g=(0,k.useRef)(o);g.current=o;let T=(0,k.useRef)(null);return(0,k.useEffect)(()=>{let S=c.current;if(!S)return;let V=!0,A=!1,L=()=>{!V||A||(A=!0,d.current?.())},D=e.on("ready",()=>{L()}),x=e.on("error",y=>{m.current?.(y.message??"There was a problem loading the secure card form.")}),G=e.on("validation",y=>{C.current?.(y.message??null)}),B={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...g.current?{theme:g.current}:{}};return T.current=g.current??null,e.mount(S,B).then(()=>{L()}).catch(y=>{V&&m.current?.(y instanceof Error?y.message:"Failed to load the secure card form.")}),()=>{V=!1,D(),x(),G(),e.unmount()}},[e,r,t,n]),se(()=>{let S=c.current;S&&ne(S,a)},[a]),(0,k.useEffect)(()=>{o!==void 0&&(o===null&&T.current===null||(T.current=o,e.applyTheme?.(o)))},[e,o]),(0,le.jsx)("div",{ref:c,"data-testid":"flopay-vault-card-fields"})}var de=/^#([0-9a-f]{6})$/i,Be=/^#([0-9a-f]{3})$/i,fe=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,pe=/^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,Oe=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Ie=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Me=/^(-?\d+(?:\.\d+)?)em$/,_e=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Ne=/^[a-z][a-z0-9 -]{0,31}$/i,De=new Set(["none","uppercase","lowercase","capitalize"]);function me(e){if(typeof e!="string")return null;let r=e.trim(),t=de.exec(r);if(t){let d=Number.parseInt(t[1],16);return{r:d>>16&255,g:d>>8&255,b:d&255,a:null}}let n=Be.exec(r);if(n){let[d,m,C]=n[1].split("").map(g=>Number.parseInt(g+g,16));return{r:d,g:m,b:C,a:null}}let o=fe.exec(r),a=o?null:pe.exec(r),i=o??a;if(!i)return null;let l=Number(i[1]),s=Number(i[2]),c=Number(i[3]);return l>255||s>255||c>255?null:{r:l,g:s,b:c,a:a?Number(a[4]):null}}function ge({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 M(e){if(typeof e!="string")return;let r=e.trim();if(de.test(r)||fe.test(r))return r;let t=pe.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=me(r);return n?ge(n):void 0}function W(e,r=.12){let t=me(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ge({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function _(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 P(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 ze(e,r,t){if(typeof e!="string")return;let n=Me.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(e){let r=_(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=_(o," "),i=M(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]),c=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<c)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function $e(e){if(typeof e!="string")return;let r=e.trim(),t=M(r);if(t)return{type:"solid",color:t};let n=Oe.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=We(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Ge(e){return e.type==="solid"?{type:"solid",color:W(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:W(r.color)}))}}function He(e){let r=!1,t,n=[];for(let s of _(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=M(s);if(c){t=c;continue}let d=P(s,-128,128);if(d===void 0)return;n.push(d)}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 Ye(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=_(r,",").map(He);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ce(e){if(typeof e!="string")return;let r=_(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>Ne.test(t)).slice(0,4);return r.length>0?r:void 0}function Ue(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=P(r[0],0,64),n=P(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function Xe(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 ye({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=$e(n.background??n.backgroundColor),i=M(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&Ge(a),s={fontFamilies:ce(n.fontFamily)??ce(t),fontSize:P(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Xe(n.fontWeight)??600,letterSpacing:ze(n.letterSpacing,-.1,.5)??.01,lineHeight:P(n.lineHeight,.8,2)??1,textTransform:De.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Ue(n.padding),d=Ye(n.boxShadow),m=P(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?P(_e.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:M(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:s,...c?{spacing:c}:{},...d?{shadow:d}:{},...m===void 0?{}:{borderRadius:m},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)?W(n,r):e}function qe(e){if(typeof e=="number"||typeof e=="string")return e}function he({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,c=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",d=ye({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??je(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:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(qe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...d?{submitButton:d}:{}}}var w=require("react/jsx-runtime"),N=class extends b.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function Ce(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 N(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 Se({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:a,loading:i=null,onReady:l,onComplete:s,onDecline:c,onCancel:d,onValidation:m,onError:C}){let[g,T]=(0,u.useState)(null),[S,V]=(0,u.useState)(null),[A,L]=(0,u.useState)(null),[D,x]=(0,u.useState)(null),[G,B]=(0,u.useState)(null),y=(0,u.useRef)(!1),H=(0,u.useRef)(!1),R=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,b.resolveTheme)(o),[o]),ke=(0,u.useMemo)(()=>typeof o=="object"?o:R?he({appearance:R.appearance,buttonsStyles:R.buttonsLayout,layout:"default"}):null,[R,o]),we=(0,u.useMemo)(()=>te(R?.buttonsLayout.cardFormContainer,a),[R,a]),K=(0,u.useMemo)(()=>R?ae(R):void 0,[R]),Z=(0,u.useRef)(l),Y=(0,u.useRef)(C),J=(0,u.useRef)(s),Q=(0,u.useRef)(c),ee=(0,u.useRef)(d),re=(0,u.useRef)(m),O=(0,u.useRef)(!1),U=(0,u.useRef)(!1),X=(0,u.useRef)(0);return Z.current=l,Y.current=C,J.current=s,Q.current=c,ee.current=d,re.current=m,(0,u.useEffect)(()=>{let p=X.current+1;return X.current=p,()=>{queueMicrotask(()=>{X.current===p&&(O.current||U.current||(U.current=!0,F(()=>{ee.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,E=new $.PaymentAPI((0,b.resolveBillingApiUrl)(t),{telemetry:n});return T(null),V(null),L(null),O.current=!1,U.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 I=await E.getUnifiedCheckoutSession(e,r);if(!p)return;let v=I.data.session;if(!v||!(0,b.isCardSetupCheckoutSession)(v))throw new b.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let h=v.vault;if(h?.html?.trim()||(h=await E.getVaultCapture(e,r)),!h.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;V(h),T(new $.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(I){if(!p)return;let v=Ce(I);O.current=!0,L(v),F(()=>Y.current?.(v))}})(),()=>{p=!1,E.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!g)return;let p=!1;H.current=!1,y.current=!1;let E=g.on("submitting",()=>{y.current=!0,B(null),x("processing")}),I=g.on("complete",h=>{O.current=!0,y.current=!1,x("success"),(async()=>(await new Promise(j=>setTimeout(j,600)),!H.current&&(H.current=!0,F(()=>{J.current?.({status:"succeeded",sessionId:e,...h.paymentMethod?{paymentMethod:h.paymentMethod}:{}})}),p||x(null))))()}),v=g.on("decline",h=>{O.current=!0,y.current=!1,B(h.message??null),x("error"),F(()=>{Q.current?.({status:"declined",sessionId:e,...h.declineReason?{reason:h.declineReason}:{},...h.message?{message:h.message}:{}})}),(async()=>(await new Promise(j=>setTimeout(j,400)),p||x(null)))()});return()=>{p=!0,E(),I(),v()}},[g,e]),A?(0,w.jsx)("div",{role:"alert",children:A.message}):!g||!S?.html?(0,w.jsx)(w.Fragment,{children:i}):(0,w.jsxs)(w.Fragment,{children:[D&&(0,w.jsx)(ie,{status:D,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...K?{theme:K}:{}}),(0,w.jsx)(ue,{capture:g,html:S.html,messageToken:S.messageToken,expectedOrigin:S.expectedOrigin,theme:ke,containerStyle:we,onReady:()=>{F(()=>Z.current?.())},onValidation:p=>{F(()=>re.current?.(p))},onError:p=>{if(!p)return;y.current&&(y.current=!1,B(p),x("error"),setTimeout(()=>x(null),400));let E=Ce(new Error(p),{code:"card_setup_widget_failed",retryable:!0});F(()=>Y.current?.(E))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
@@ -1 +1 @@
1
- import{h as e,i as t}from"./chunk-LI3VGXRI.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
1
+ import{h as e,i as t}from"./chunk-M4FGYFX6.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
@@ -3,4 +3,4 @@ import{useEffect as ie,useRef as T}from"react";function ne(e,r){if(!e)return r;l
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 fe=/^#([0-9a-f]{6})$/i,Ae=/^#([0-9a-f]{3})$/i,pe=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,me=/^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,Le=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Be=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Oe=/^(-?\d+(?:\.\d+)?)em$/,Ie=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Me=/^[a-z][a-z0-9 -]{0,31}$/i,_e=new Set(["none","uppercase","lowercase","capitalize"]);function ge(e){if(typeof e!="string")return null;let r=e.trim(),t=fe.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=Ae.exec(r);if(n){let[c,f,b]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:c,g:f,b,a:null}}let o=pe.exec(r),a=o?null:me.exec(r),i=o??a;if(!i)return null;let u=Number(i[1]),s=Number(i[2]),l=Number(i[3]);return u>255||s>255||l>255?null:{r:u,g:s,b:l,a:a?Number(a[4]):null}}function ye({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 M(e){if(typeof e!="string")return;let r=e.trim();if(fe.test(r)||pe.test(r))return r;let t=me.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=ge(r);return n?ye(n):void 0}function z(e,r=.12){let t=ge(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ye({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function _(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 v(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=Be.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function Ne(e,r,t){if(typeof e!="string")return;let n=Oe.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function De(e){let r=_(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=_(o," "),i=M(a[0]);if(!i)return;let u=n/(r.length-1)*100,s=a[1]===void 0?u:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),l=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<l)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function ze(e){if(typeof e!="string")return;let r=e.trim(),t=M(r);if(t)return{type:"solid",color:t};let n=Le.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=De(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function We(e){return e.type==="solid"?{type:"solid",color:z(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:z(r.color)}))}}function $e(e){let r=!1,t,n=[];for(let s of _(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let l=M(s);if(l){t=l;continue}let c=v(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,u=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||i>128||Math.abs(u)>32))return{color:t,inset:r,offsetX:o,offsetY:a,blur:i,spread:u}}function Ge(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=_(r,",").map($e);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function de(e){if(typeof e!="string")return;let r=_(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>Me.test(t)).slice(0,4);return r.length>0?r:void 0}function He(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=v(r[0],0,64),n=v(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function Ye(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 he({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=ze(n.background??n.backgroundColor),i=M(o?.colorPrimaryHover),u=i?{type:"solid",color:i}:a&&We(a),s={fontFamilies:de(n.fontFamily)??de(t),fontSize:v(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Ye(n.fontWeight)??600,letterSpacing:Ne(n.letterSpacing,-.1,.5)??.01,lineHeight:v(n.lineHeight,.8,2)??1,textTransform:_e.has(String(n.textTransform))?n.textTransform:"uppercase"},l=He(n.padding),c=Ge(n.boxShadow),f=v(n.borderRadius,0,9999),b=typeof n.backdropFilter=="string"?v(Ie.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:M(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...u?{hoverBackground:u}:{},typography:s,...l?{spacing:l}:{},...c?{shadow:c}:{},...f===void 0?{}:{borderRadius:f},disabledOpacity:e?.theme==="night"?.8:.6,...b===void 0?{}:{backdropBlur:b}}}function Ue(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)?z(n,r):e}function Xe(e){if(typeof e=="number"||typeof e=="string")return e}function be({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=f=>typeof f=="string"&&f?f:void 0,a=r.submitButton,i=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",u=t==="buttons",s=r.nameInput,l=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",c=he({appearance:e,buttonsStyles:r,fontFamily:l});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??Ue(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)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:l,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Xe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}import{Fragment as ke,jsx as $,jsxs as er}from"react/jsx-runtime";var K=class extends V{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function Se(e,r={}){let t=e instanceof V?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 K(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:a,loading:i=null,onReady:u,onComplete:s,onDecline:l,onCancel:c,onValidation:f,onError:b}){let[p,F]=N(null),[C,E]=N(null),[A,L]=N(null),[D,S]=N(null),[G,B]=N(null),m=h(!1),H=h(!1),k=W(()=>typeof o=="object"?void 0:Qe(o),[o]),we=W(()=>typeof o=="object"?o:k?be({appearance:k.appearance,buttonsStyles:k.buttonsLayout,layout:"default"}):null,[k,o]),xe=W(()=>ne(k?.buttonsLayout.cardFormContainer,a),[k,a]),Z=W(()=>k?le(k):void 0,[k]),J=h(u),Y=h(b),Q=h(s),ee=h(l),re=h(c),te=h(f),O=h(!1),U=h(!1),X=h(0);return J.current=u,Y.current=b,Q.current=s,ee.current=l,re.current=c,te.current=f,q(()=>{let d=X.current+1;return X.current=d,()=>{queueMicrotask(()=>{X.current===d&&(O.current||U.current||(U.current=!0,x(()=>{re.current?.({status:"cancelled",sessionId:e})})))})}},[e]),q(()=>{let d=!0,R=new qe(Je(t),{telemetry:n});return F(null),E(null),L(null),O.current=!1,U.current=!1,(async()=>{try{if(!e.trim())throw new V("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new V("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let I=await R.getUnifiedCheckoutSession(e,r);if(!d)return;let w=I.data.session;if(!w||!Ze(w))throw new V("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let g=w.vault;if(g?.html?.trim()||(g=await R.getVaultCapture(e,r)),!g.html?.trim())throw new V("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;E(g),F(new Ke({sessionId:e,operation:"card_setup",telemetry:n}))}catch(I){if(!d)return;let w=Se(I);O.current=!0,L(w),x(()=>Y.current?.(w))}})(),()=>{d=!1,R.destroy()}},[t,r,e,n]),q(()=>{if(!p)return;let d=!1;H.current=!1,m.current=!1;let R=p.on("submitting",()=>{m.current=!0,B(null),S("processing")}),I=p.on("complete",g=>{O.current=!0,m.current=!1,S("success"),(async()=>(await new Promise(j=>setTimeout(j,1200)),!H.current&&(H.current=!0,x(()=>{Q.current?.({status:"succeeded",sessionId:e,...g.paymentMethod?{paymentMethod:g.paymentMethod}:{}})}),d||S(null))))()}),w=p.on("decline",g=>{O.current=!0,m.current=!1,B(g.message??null),S("error"),x(()=>{ee.current?.({status:"declined",sessionId:e,...g.declineReason?{reason:g.declineReason}:{},...g.message?{message:g.message}:{}})}),(async()=>(await new Promise(j=>setTimeout(j,1500)),d||S(null)))()});return()=>{d=!0,R(),I(),w()}},[p,e]),A?$("div",{role:"alert",children:A.message}):!p||!C?.html?$(ke,{children:i}):er(ke,{children:[D&&$(ce,{status:D,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...Z?{theme:Z}:{}}),$(se,{capture:p,html:C.html,messageToken:C.messageToken,expectedOrigin:C.expectedOrigin,theme:we,containerStyle:xe,onReady:()=>{x(()=>J.current?.())},onValidation:d=>{x(()=>te.current?.(d))},onError:d=>{if(!d)return;m.current&&(m.current=!1,B(d),S("error"),setTimeout(()=>S(null),1500));let R=Se(new Error(d),{code:"card_setup_widget_failed",retryable:!0});x(()=>Y.current?.(R))}})]})}export{x as a,ce as b,ae as c,se as d,Ue as e,Xe as f,be as g,K as h,vr as i};
6
+ `})]})})}var fe=/^#([0-9a-f]{6})$/i,Ae=/^#([0-9a-f]{3})$/i,pe=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,me=/^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,Le=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Be=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Oe=/^(-?\d+(?:\.\d+)?)em$/,Ie=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Me=/^[a-z][a-z0-9 -]{0,31}$/i,_e=new Set(["none","uppercase","lowercase","capitalize"]);function ge(e){if(typeof e!="string")return null;let r=e.trim(),t=fe.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=Ae.exec(r);if(n){let[c,f,b]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:c,g:f,b,a:null}}let o=pe.exec(r),a=o?null:me.exec(r),i=o??a;if(!i)return null;let u=Number(i[1]),s=Number(i[2]),l=Number(i[3]);return u>255||s>255||l>255?null:{r:u,g:s,b:l,a:a?Number(a[4]):null}}function ye({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 M(e){if(typeof e!="string")return;let r=e.trim();if(fe.test(r)||pe.test(r))return r;let t=me.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=ge(r);return n?ye(n):void 0}function z(e,r=.12){let t=ge(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ye({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function _(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 v(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=Be.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function Ne(e,r,t){if(typeof e!="string")return;let n=Oe.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function De(e){let r=_(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=_(o," "),i=M(a[0]);if(!i)return;let u=n/(r.length-1)*100,s=a[1]===void 0?u:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),l=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<l)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function ze(e){if(typeof e!="string")return;let r=e.trim(),t=M(r);if(t)return{type:"solid",color:t};let n=Le.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=De(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function We(e){return e.type==="solid"?{type:"solid",color:z(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:z(r.color)}))}}function $e(e){let r=!1,t,n=[];for(let s of _(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let l=M(s);if(l){t=l;continue}let c=v(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,u=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||i>128||Math.abs(u)>32))return{color:t,inset:r,offsetX:o,offsetY:a,blur:i,spread:u}}function Ge(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=_(r,",").map($e);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function de(e){if(typeof e!="string")return;let r=_(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>Me.test(t)).slice(0,4);return r.length>0?r:void 0}function He(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=v(r[0],0,64),n=v(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function Ye(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 he({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=ze(n.background??n.backgroundColor),i=M(o?.colorPrimaryHover),u=i?{type:"solid",color:i}:a&&We(a),s={fontFamilies:de(n.fontFamily)??de(t),fontSize:v(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Ye(n.fontWeight)??600,letterSpacing:Ne(n.letterSpacing,-.1,.5)??.01,lineHeight:v(n.lineHeight,.8,2)??1,textTransform:_e.has(String(n.textTransform))?n.textTransform:"uppercase"},l=He(n.padding),c=Ge(n.boxShadow),f=v(n.borderRadius,0,9999),b=typeof n.backdropFilter=="string"?v(Ie.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:M(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...u?{hoverBackground:u}:{},typography:s,...l?{spacing:l}:{},...c?{shadow:c}:{},...f===void 0?{}:{borderRadius:f},disabledOpacity:e?.theme==="night"?.8:.6,...b===void 0?{}:{backdropBlur:b}}}function Ue(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)?z(n,r):e}function Xe(e){if(typeof e=="number"||typeof e=="string")return e}function be({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=f=>typeof f=="string"&&f?f:void 0,a=r.submitButton,i=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",u=t==="buttons",s=r.nameInput,l=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",c=he({appearance:e,buttonsStyles:r,fontFamily:l});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??Ue(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)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:l,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Xe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}import{Fragment as ke,jsx as $,jsxs as er}from"react/jsx-runtime";var K=class extends V{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function Se(e,r={}){let t=e instanceof V?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 K(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:a,loading:i=null,onReady:u,onComplete:s,onDecline:l,onCancel:c,onValidation:f,onError:b}){let[p,F]=N(null),[C,E]=N(null),[A,L]=N(null),[D,S]=N(null),[G,B]=N(null),m=h(!1),H=h(!1),k=W(()=>typeof o=="object"?void 0:Qe(o),[o]),we=W(()=>typeof o=="object"?o:k?be({appearance:k.appearance,buttonsStyles:k.buttonsLayout,layout:"default"}):null,[k,o]),xe=W(()=>ne(k?.buttonsLayout.cardFormContainer,a),[k,a]),Z=W(()=>k?le(k):void 0,[k]),J=h(u),Y=h(b),Q=h(s),ee=h(l),re=h(c),te=h(f),O=h(!1),U=h(!1),X=h(0);return J.current=u,Y.current=b,Q.current=s,ee.current=l,re.current=c,te.current=f,q(()=>{let d=X.current+1;return X.current=d,()=>{queueMicrotask(()=>{X.current===d&&(O.current||U.current||(U.current=!0,x(()=>{re.current?.({status:"cancelled",sessionId:e})})))})}},[e]),q(()=>{let d=!0,R=new qe(Je(t),{telemetry:n});return F(null),E(null),L(null),O.current=!1,U.current=!1,(async()=>{try{if(!e.trim())throw new V("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new V("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let I=await R.getUnifiedCheckoutSession(e,r);if(!d)return;let w=I.data.session;if(!w||!Ze(w))throw new V("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let g=w.vault;if(g?.html?.trim()||(g=await R.getVaultCapture(e,r)),!g.html?.trim())throw new V("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;E(g),F(new Ke({sessionId:e,operation:"card_setup",telemetry:n}))}catch(I){if(!d)return;let w=Se(I);O.current=!0,L(w),x(()=>Y.current?.(w))}})(),()=>{d=!1,R.destroy()}},[t,r,e,n]),q(()=>{if(!p)return;let d=!1;H.current=!1,m.current=!1;let R=p.on("submitting",()=>{m.current=!0,B(null),S("processing")}),I=p.on("complete",g=>{O.current=!0,m.current=!1,S("success"),(async()=>(await new Promise(j=>setTimeout(j,600)),!H.current&&(H.current=!0,x(()=>{Q.current?.({status:"succeeded",sessionId:e,...g.paymentMethod?{paymentMethod:g.paymentMethod}:{}})}),d||S(null))))()}),w=p.on("decline",g=>{O.current=!0,m.current=!1,B(g.message??null),S("error"),x(()=>{ee.current?.({status:"declined",sessionId:e,...g.declineReason?{reason:g.declineReason}:{},...g.message?{message:g.message}:{}})}),(async()=>(await new Promise(j=>setTimeout(j,400)),d||S(null)))()});return()=>{d=!0,R(),I(),w()}},[p,e]),A?$("div",{role:"alert",children:A.message}):!p||!C?.html?$(ke,{children:i}):er(ke,{children:[D&&$(ce,{status:D,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...Z?{theme:Z}:{}}),$(se,{capture:p,html:C.html,messageToken:C.messageToken,expectedOrigin:C.expectedOrigin,theme:we,containerStyle:xe,onReady:()=>{x(()=>J.current?.())},onValidation:d=>{x(()=>te.current?.(d))},onError:d=>{if(!d)return;m.current&&(m.current=!1,B(d),S("error"),setTimeout(()=>S(null),400));let R=Se(new Error(d),{code:"card_setup_widget_failed",retryable:!0});x(()=>Y.current?.(R))}})]})}export{x as a,ce as b,ae as c,se as d,Ue as e,Xe as f,be as g,K as h,vr as i};