@flopay/react 1.9.19 → 1.9.20

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
@@ -138,6 +138,7 @@ The billing API can route a checkout's cards to an approved Worldpay Corporate G
138
138
  - **No opt-in.** The billing API decides from the merchant's configured gateways whether a session can use Worldpay. The SDK sends no capability token or gateway hint, so routing is the same for every SDK version and create style. Auto, Confirm, and pre-tokenized sessions stay on the released routing because the billing API keeps them there, not because the SDK asks.
139
139
  - **Same card surface.** No Stripe runtime, Worldpay SDK, or browser credential is involved. An open session that advertises `gateways.worldpayCorporateGateway` but omits the embedded card form recovers it on demand; a completed or authorized session is never shown the card form again.
140
140
  - **Same callbacks.** Success reaches `onComplete` as `status: 'succeeded'`, and a manual-capture hold as `status: 'authorized'` with `paymentId`, `sessionId`, and `authorizationExpiresAt`; `paymentIntentId` is omitted because the processor's reference is not a Stripe object. A refusal reaches `onDecline` with `authorization_declined`. A payment still reconciling when the form stops waiting reaches `onError`, never `onComplete`, and a later session read reports the settled status.
141
+ - **Same authentication.** When the buyer's bank asks for 3DS, the SDK renders the provider-hosted challenge in a modal dialog over your page (`role="dialog"`, `aria-modal`, focus moved into the challenge and restored when it closes) and reports only the terminal outcome through the callbacks above. The challenge URL never reaches a callback or the instrument feed; the only signal is the opaque `3ds_challenge` instrument. Reloading a session still waiting on authentication re-presents the open challenge without reloading it and without charging the card again, and closing it takes the processing state down immediately and hands the buyer back to the card form, with its submit held until that attempt reports an outcome so a closed challenge can never start a second authorization — a server-resolved outcome that lands afterwards (an out-of-band bank approval, say) still reaches your callbacks.
141
142
  - The merchant instrument feed's `card_expanded` event omits `gateway` for these sessions, because the billing API chooses the card's gateway.
142
143
 
143
144
  #### Themes and layouts
@@ -206,7 +207,7 @@ When the saved payment method cannot complete silently, the button opens a `FloP
206
207
  `FloPayProvider`, `SplitCardForm`, and the hooks let you compose the provider and session yourself. Card checkout still uses the hosted card form: supply the session (with its `vault` block) and nonce, or a session whose `gateways.stripe.enabledPaymentMethods` includes `card` so the form can be fetched on demand. A session with neither never calls the recovery endpoint; its other methods remain usable, and if none remain `onError` receives `UnsupportedBackendVaultCapability`. `FloPayCheckout` and `SplitCardForm` never fall back to Stripe card fields.
207
208
 
208
209
  - Wallets, alternative methods, and PayPal create intents through the nonce-protected session intent route, and client-observed failures use the session decline route without tokens, provider object ids, card data, or personal data.
209
- - **Hosted card form.** The widget owns the card fields, its own submit button, tokenization, the charge, 3DS, and the result, so no Stripe.js runs on the card path. `SplitCardForm` renders no card fields or submit button of its own, and Host-collected AVS fields remain outside the PCI widget and gate its submit. After the widget reports it is submitting, the processing overlay stays up until `complete`, `decline`, or `error`. In `layout="buttons"`, the recovery request for the form waits until the buyer selects Card, and concurrent renders share one request.
210
+ - **Hosted card form.** The widget owns the card fields, its own submit button, tokenization, the charge, 3DS, and the result, so no Stripe.js runs on the card path. `SplitCardForm` renders no card fields or submit button of its own, and Host-collected AVS fields remain outside the PCI widget and gate its submit. After the widget reports it is submitting, the processing overlay stays up until `complete`, `decline`, `error`, or the buyer closing the authentication challenge — which takes the overlay down but keeps the form's submit held until that attempt reports an outcome. In `layout="buttons"`, the recovery request for the form waits until the buyer selects Card, and concurrent renders share one request.
210
211
  - **AVS.** With `enableAVS`, the SDK collects the billing address outside the PCI form and gates the form's submit synchronously on it. The postcode is validated against the selected country with the same rules as the billing API: a supported country blocks an empty or malformed postcode with an inline message, and a country without postcodes makes the field optional. Email and street, city, and state fields gate submit the same way. On submit, the address is saved in parallel with the charge: a rejected address (`4xx`) shows inline and reaches `onError` for the next attempt, while a transient failure or a 10-second timeout falls back to the session's saved address and still completes.
211
212
  - `useCheckout()` exposes `claimPending`, which stays true while a detached session shell is not yet safe to charge.
212
213
 
@@ -1,6 +1,6 @@
1
- "use strict";var J=Object.defineProperty;var xe=Object.getOwnPropertyDescriptor;var ve=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var Ee=(e,r)=>{for(var t in r)J(e,t,{get:r[t],enumerable:!0})},Pe=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of ve(r))!Fe.call(e,o)&&o!==t&&J(e,o,{get:()=>r[o],enumerable:!(n=xe(r,o))||n.enumerable});return e};var Te=e=>Pe(J({},"__esModule",{value:!0}),e);var Je={};Ee(Je,{FloPayCardSetup:()=>Re,FloPayCardSetupError:()=>W});module.exports=Te(Je);var U=require("@flopay/js/card-setup"),h=require("@flopay/shared"),u=require("react");function ae(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 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 Ae(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Ve.has(r.charAt(0).toLowerCase()+r.slice(1))}function Le(e,r){return typeof r=="number"&&r!==0&&!Ae(e)?`${r}px`:String(r).trim()}function ie(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]=Le(t,n)}}}var se={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ue(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?se.dark:se.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 Be={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function le({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=Be}){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 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:()=>xe,FloPayCardSetupError:()=>$});module.exports=Ve(Qe);var X=require("@flopay/js/card-setup"),b=require("@flopay/shared"),u=require("react");function ie(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 se(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 ue={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function le(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?ue.dark:ue.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 ce({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:`
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 b=require("react");var H=require("react"),ce=typeof window>"u"?H.useEffect:H.useLayoutEffect;var fe=require("react/jsx-runtime"),Q=new WeakSet;function de({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:i,onReady:l,onError:s,onValidation:f}){let c=(0,b.useRef)(null),m=(0,b.useRef)(l),C=(0,b.useRef)(s),g=(0,b.useRef)(f);m.current=l,C.current=s,g.current=f;let V=(0,b.useRef)(o);V.current=o;let v=(0,b.useRef)(null),w=a??void 0,A=(0,b.useRef)(w);A.current=w;let O=(0,b.useRef)(void 0);return(0,b.useEffect)(()=>{let F=c.current;if(!F)return;let S=!0,$=!1,I=()=>{!S||$||($=!0,m.current?.())},E=e.on("ready",()=>{I()}),M=e.on("error",x=>{C.current?.(x.message??"There was a problem loading the secure card form.")}),k=e.on("validation",x=>{g.current?.(x.message??null)}),G=A.current??(Q.has(e)?null:void 0),X={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...V.current?{theme:V.current}:{},...G===void 0?{}:{submitLabel:G}};return v.current=V.current??null,O.current=A.current,A.current!==void 0&&Q.add(e),e.mount(F,X).then(()=>{I()}).catch(x=>{S&&C.current?.(x instanceof Error?x.message:"Failed to load the secure card form.")}),()=>{S=!1,E(),M(),k(),e.unmount()}},[e,r,t,n]),ce(()=>{let F=c.current;F&&ie(F,i)},[i]),(0,b.useEffect)(()=>{o!==void 0&&(o===null&&v.current===null||(v.current=o,e.applyTheme?.(o)))},[e,o]),(0,b.useEffect)(()=>{w!==O.current&&(O.current=w,w!==void 0&&Q.add(e),e.setSubmitLabel?.(w??null))},[e,w]),(0,fe.jsx)("div",{ref:c,"data-testid":"flopay-vault-card-fields"})}var me=/^#([0-9a-f]{6})$/i,Oe=/^#([0-9a-f]{3})$/i,ge=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,ye=/^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,Me=/^(-?\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 be(e){if(typeof e!="string")return null;let r=e.trim(),t=me.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=Oe.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=ge.exec(r),a=o?null:ye.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 he({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 D(e){if(typeof e!="string")return;let r=e.trim();if(me.test(r)||ge.test(r))return r;let t=ye.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=be(r);return n?he(n):void 0}function Y(e,r=.12){let t=be(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return he({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function z(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=Me.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=z(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=z(o," "),i=D(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 Ge(e){if(typeof e!="string")return;let r=e.trim(),t=D(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 a=$e(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function He(e){return e.type==="solid"?{type:"solid",color:Y(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:Y(r.color)}))}}function Ye(e){let r=!1,t,n=[];for(let s of z(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let f=D(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 Ue(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=z(r,",").map(Ye);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function pe(e){if(typeof e!="string")return;let r=z(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=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 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 Ce({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=Ge(n.background??n.backgroundColor),i=D(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&He(a),s={fontFamilies:pe(n.fontFamily)??pe(t),fontSize:B(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:je(n.fontWeight)??600,letterSpacing:We(n.letterSpacing,-.1,.5)??.01,lineHeight:B(n.lineHeight,.8,2)??1,textTransform:ze.has(String(n.textTransform))?n.textTransform:"uppercase"},f=Xe(n.padding),c=Ue(n.boxShadow),m=B(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?B(Ne.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:D(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 qe(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)?Y(n,r):e}function Ke(e){if(typeof e=="number"||typeof e=="string")return e}function Se({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=Ce({appearance:e,buttonsStyles:r,fontFamily:f});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??qe(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(Ke(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}var R=require("react/jsx-runtime"),W=class extends h.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function we(e,r={}){let t=e instanceof h.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 W(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),[v,w]=(0,u.useState)(null),[A,O]=(0,u.useState)(null),[F,S]=(0,u.useState)(null),[$,I]=(0,u.useState)(null),E=(0,u.useRef)(!1),M=(0,u.useRef)(!1),k=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,h.resolveTheme)(o),[o]),G=(0,u.useMemo)(()=>typeof o=="object"?o:k?Se({appearance:k.appearance,buttonsStyles:k.buttonsLayout,layout:"default"}):null,[k,o]),X=(0,u.useMemo)(()=>ae(k?.buttonsLayout.cardFormContainer,a),[k,a]),x=(0,u.useMemo)(()=>k?ue(k):void 0,[k]),ee=(0,u.useRef)(l),j=(0,u.useRef)(C),re=(0,u.useRef)(s),te=(0,u.useRef)(f),ne=(0,u.useRef)(c),oe=(0,u.useRef)(m),_=(0,u.useRef)(!1),q=(0,u.useRef)(!1),K=(0,u.useRef)(0);return ee.current=l,j.current=C,re.current=s,te.current=f,ne.current=c,oe.current=m,(0,u.useEffect)(()=>{let p=K.current+1;return K.current=p,()=>{queueMicrotask(()=>{K.current===p&&(_.current||q.current||(q.current=!0,T(()=>{ne.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,L=new U.PaymentAPI((0,h.resolveBillingApiUrl)(t),{telemetry:n});return V(null),w(null),O(null),_.current=!1,q.current=!1,(async()=>{try{if(!e.trim())throw new h.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new h.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let N=await L.getUnifiedCheckoutSession(e,r);if(!p)return;let P=N.data.session;if(!P||!(0,h.isCardSetupCheckoutSession)(P))throw new h.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let y=P.vault;if(y?.html?.trim()||(y=await L.getVaultCapture(e,r)),!y.html?.trim())throw new h.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!p)return;w(y),V(new U.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(N){if(!p)return;let P=we(N);_.current=!0,O(P),T(()=>j.current?.(P))}})(),()=>{p=!1,L.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!g)return;let p=!1;M.current=!1,E.current=!1;let L=g.on("submitting",()=>{E.current=!0,I(null),S("processing")}),N=g.on("complete",y=>{_.current=!0,E.current=!1,S("success"),(async()=>(await new Promise(Z=>setTimeout(Z,600)),!M.current&&(M.current=!0,T(()=>{re.current?.({status:"succeeded",sessionId:e,...y.paymentMethod?{paymentMethod:y.paymentMethod}:{}})}),p||S(null))))()}),P=g.on("decline",y=>{_.current=!0,E.current=!1,I(y.message??null),S("error"),T(()=>{te.current?.({status:"declined",sessionId:e,...y.declineReason?{reason:y.declineReason}:{},...y.message?{message:y.message}:{}})}),(async()=>(await new Promise(Z=>setTimeout(Z,400)),p||S(null)))()});return()=>{p=!0,L(),N(),P()}},[g,e]),A?(0,R.jsx)("div",{role:"alert",children:A.message}):!g||!v?.html?(0,R.jsx)(R.Fragment,{children:i}):(0,R.jsxs)(R.Fragment,{children:[F&&(0,R.jsx)(le,{status:F,errorMessage:$,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...x?{theme:x}:{}}),(0,R.jsx)(de,{capture:g,html:v.html,messageToken:v.messageToken,expectedOrigin:v.expectedOrigin,theme:G,containerStyle:X,onReady:()=>{T(()=>ee.current?.())},onValidation:p=>{T(()=>oe.current?.(p))},onError:p=>{if(!p)return;E.current&&(E.current=!1,I(p),S("error"),setTimeout(()=>S(null),400));let L=we(new Error(p),{code:"card_setup_widget_failed",retryable:!0});T(()=>j.current?.(L))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
6
+ `})]})})}var y=require("react");var Y=require("react"),de=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;var pe=require("react/jsx-runtime"),ee=new WeakSet;function fe({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 x=(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",R=>{C.current?.(R.message??"There was a problem loading the secure card form.")}),S=e.on("validation",R=>{g.current?.(R.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 x.current=V.current??null,O.current=A.current,A.current!==void 0&&ee.add(e),e.mount(v,j).then(()=>{I()}).catch(R=>{h&&C.current?.(R instanceof Error?R.message:"Failed to load the secure card form.")}),()=>{h=!1,F(),_(),S(),e.unmount()}},[e,r,t,n]),de(()=>{let v=c.current;v&&se(v,i)},[i]),(0,y.useEffect)(()=>{o!==void 0&&(o===null&&x.current===null||(x.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,pe.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 w=require("react/jsx-runtime"),$=class extends b.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function Re(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 xe({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),[x,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)(()=>ie(S?.buttonsLayout.cardFormContainer,a),[S,a]),R=(0,u.useMemo)(()=>S?le(S):void 0,[S]),re=(0,u.useRef)(l),q=(0,u.useRef)(C),te=(0,u.useRef)(s),ne=(0,u.useRef)(f),oe=(0,u.useRef)(c),ae=(0,u.useRef)(m),N=(0,u.useRef)(!1),K=(0,u.useRef)(!1),Z=(0,u.useRef)(0);return re.current=l,q.current=C,te.current=s,ne.current=f,oe.current=c,ae.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(()=>{oe.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=Re(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(()=>{te.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(()=>{ne.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,w.jsx)("div",{role:"alert",children:A.message}):!g||!x?.html?(0,w.jsx)(w.Fragment,{children:i}):(0,w.jsxs)(w.Fragment,{children:[v&&(0,w.jsx)(ce,{status:v,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...R?{theme:R}:{}}),(0,w.jsx)(fe,{capture:g,html:x.html,messageToken:x.messageToken,expectedOrigin:x.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{T(()=>re.current?.())},onValidation:p=>{T(()=>ae.current?.(p))},onError:p=>{if(!p)return;F.current&&(F.current=!1,I(p),h("error"),setTimeout(()=>h(null),400));let L=Re(new Error(p),{code:"card_setup_widget_failed",retryable:!0});T(()=>q.current?.(L))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
@@ -1 +1 @@
1
- import{h as e,i as t}from"./chunk-Z6LBB432.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
1
+ import{h as e,i as t}from"./chunk-CSBYK62Y.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
@@ -0,0 +1,6 @@
1
+ import{useEffect as Q,useRef as F}from"react";function ue(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 Ee(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Fe.has(r.charAt(0).toLowerCase()+r.slice(1))}function Te(e,r){return typeof r=="number"&&r!==0&&!Ee(e)?`${r}px`:String(r).trim()}function le(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]=Te(t,n)}}}import{useEffect as Pe,useLayoutEffect as Ve}from"react";var ce=typeof window>"u"?Pe:Ve;import{jsx as Ae}from"react/jsx-runtime";var ee=new WeakSet;function de({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:i,containerStyle:a,onReady:u,onError:s,onValidation:c}){let l=F(null),f=F(u),y=F(s),p=F(c);f.current=u,y.current=s,p.current=c;let T=F(o);T.current=o;let k=F(null),C=i??void 0,P=F(C);P.current=C;let L=F(void 0);return Q(()=>{let w=l.current;if(!w)return;let m=!0,G=!1,B=()=>{!m||G||(G=!0,f.current?.())},R=e.on("ready",()=>{B()}),_=e.on("error",S=>{y.current?.(S.message??"There was a problem loading the secure card form.")}),b=e.on("validation",S=>{p.current?.(S.message??null)}),H=P.current??(ee.has(e)?null:void 0),j={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...T.current?{theme:T.current}:{},...H===void 0?{}:{submitLabel:H}};return k.current=T.current??null,L.current=P.current,P.current!==void 0&&ee.add(e),e.mount(w,j).then(()=>{B()}).catch(S=>{m&&y.current?.(S instanceof Error?S.message:"Failed to load the secure card form.")}),()=>{m=!1,R(),_(),b(),e.unmount()}},[e,r,t,n]),ce(()=>{let w=l.current;w&&le(w,a)},[a]),Q(()=>{o!==void 0&&(o===null&&k.current===null||(k.current=o,e.applyTheme?.(o)))},[e,o]),Q(()=>{C!==L.current&&(L.current=C,C!==void 0&&ee.add(e),e.setSubmitLabel?.(C??null))},[e,C]),Ae("div",{ref:l,"data-testid":"flopay-vault-card-fields"})}import{PaymentAPI as Ze,PciVaultCardCapture as Je}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as Qe,resolveBillingApiUrl as er,resolveTheme as rr}from"@flopay/shared";import{useEffect as re,useMemo as U,useRef as h,useState as $}from"react";var fe={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function pe(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?fe.dark:fe.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 g,jsxs as I}from"react/jsx-runtime";var Le={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function me({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=Le}){let s={fontSize:13,color:u.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return g("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:I("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:[I("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&I("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:[g("circle",{cx:"12",cy:"12",r:"10",stroke:u.spinnerTrackColor,strokeWidth:"3"}),g("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:u.spinnerAccentColor})]}),e==="success"&&g("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:I("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),g("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"&&g("div",{style:{animation:"flopay-shake 0.4s ease"},children:I("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),g("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"}})]})})]}),I("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&&g("p",{style:s,children:a}),e==="error"&&r&&g("p",{style:s,children:r}),g("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 ye=/^#([0-9a-f]{6})$/i,Be=/^#([0-9a-f]{3})$/i,be=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,he=/^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 Ce(e){if(typeof e!="string")return null;let r=e.trim(),t=ye.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=Be.exec(r);if(n){let[l,f,y]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:l,g:f,b:y,a:null}}let o=be.exec(r),i=o?null:he.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 Se({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(ye.test(r)||be.test(r))return r;let t=he.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Ce(r);return n?Se(n):void 0}function Y(e,r=.12){let t=Ce(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Se({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 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=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=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let i=W(o," "),a=z(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 $e(e){if(typeof e!="string")return;let r=e.trim(),t=z(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 i=We(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function Ge(e){return e.type==="solid"?{type:"solid",color:Y(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:Y(r.color)}))}}function He(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=z(s);if(c){t=c;continue}let l=A(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=W(r,",").map(He);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ge(e){if(typeof e!="string")return;let r=W(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=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 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 ke({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=$e(n.background??n.backgroundColor),a=z(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&Ge(i),s={fontFamilies:ge(n.fontFamily)??ge(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Xe(n.fontWeight)??600,letterSpacing:ze(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:De.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Ue(n.padding),l=Ye(n.boxShadow),f=A(n.borderRadius,0,9999),y=typeof n.backdropFilter=="string"?A(_e.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(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,...y===void 0?{}:{backdropBlur:y}}}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)?Y(n,r):e}function qe(e){if(typeof e=="number"||typeof e=="string")return e}function we({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=ke({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(qe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as ve,jsx as X,jsxs as tr}from"react/jsx-runtime";var te=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 te(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 Er({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:y}){let[p,T]=$(null),[k,C]=$(null),[P,L]=$(null),[w,m]=$(null),[G,B]=$(null),R=h(!1),_=h(!1),b=U(()=>typeof o=="object"?void 0:rr(o),[o]),H=U(()=>typeof o=="object"?o:b?we({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),j=U(()=>ue(b?.buttonsLayout.cardFormContainer,i),[b,i]),S=U(()=>b?pe(b):void 0,[b]),ne=h(u),q=h(y),oe=h(s),ie=h(c),ae=h(l),se=h(f),N=h(!1),K=h(!1),Z=h(0);return ne.current=u,q.current=y,oe.current=s,ie.current=c,ae.current=l,se.current=f,re(()=>{let d=Z.current+1;return Z.current=d,()=>{queueMicrotask(()=>{Z.current===d&&(N.current||K.current||(K.current=!0,E(()=>{ae.current?.({status:"cancelled",sessionId:e})})))})}},[e]),re(()=>{let d=!0,V=new Ze(er(t),{telemetry:n});return T(null),C(null),L(null),N.current=!1,K.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 D=await V.getUnifiedCheckoutSession(e,r);if(!d)return;let x=D.data.session;if(!x||!Qe(x))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let O=x.vault;if(O?.html?.trim()||(O=await V.getVaultCapture(e,r)),!O.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;C(O),T(new Je({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!d)return;let x=xe(D);N.current=!0,L(x),E(()=>q.current?.(x))}})(),()=>{d=!1,V.destroy()}},[t,r,e,n]),re(()=>{if(!p)return;let d=!1;_.current=!1,R.current=!1;let V=p.on("submitting",()=>{R.current=!0,B(null),m("processing")}),D=p.on("complete",v=>{N.current=!0,R.current=!1,m("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,E(()=>{oe.current?.({status:"succeeded",sessionId:e,...v.paymentMethod?{paymentMethod:v.paymentMethod}:{}})}),d||m(null))))()}),x=p.on("decline",v=>{N.current=!0,R.current=!1,B(v.message??null),m("error"),E(()=>{ie.current?.({status:"declined",sessionId:e,...v.declineReason?{reason:v.declineReason}:{},...v.message?{message:v.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),d||m(null)))()}),O=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,V(),D(),x(),O()}},[p,e]),P?X("div",{role:"alert",children:P.message}):!p||!k?.html?X(ve,{children:a}):tr(ve,{children:[w&&X(me,{status:w,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...S?{theme:S}:{}}),X(de,{capture:p,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{E(()=>ne.current?.())},onValidation:d=>{E(()=>se.current?.(d))},onError:d=>{if(!d)return;R.current&&(R.current=!1,B(d),m("error"),setTimeout(()=>m(null),400));let V=xe(new Error(d),{code:"card_setup_widget_failed",retryable:!0});E(()=>q.current?.(V))}})]})}export{E as a,me as b,ce as c,de as d,je as e,qe as f,we as g,te as h,Er as i};