@flopay/react 1.10.2 → 1.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -204,6 +204,8 @@ It drops only complete exception stacks with no app or `@flopay/*` frame and at
204
204
  `FloPayPaymentMethodSetup` lets a customer save any payment method the setup session offers, not only a card, without a purchase or charge. It takes the same `sessionId` and `nonce` as `FloPayCardSetup`, and the same callbacks, `theme` and `containerStyle`.
205
205
 
206
206
  - **The session decides what renders.** The component renders exactly the methods the setup session lists in `advertisedPaymentMethods`, and nothing else. It never reads the purchase-checkout `gateways` block, which lists nothing on a setup session. A `card` entry mounts the hosted card form. A `wallet` or `apm` entry from Stripe renders that method with Stripe Elements in setup mode, using that entry's own `publishableKey`. A `paypal` entry (`paypal_vaulted`) renders the PayPal vault flow, with the entry's key as the client id and its `environment`. An unknown family or type is skipped without an error, and the first entry for a method wins. A session without the field (an older backend) renders the card form only, exactly like `FloPayCardSetup`. An empty list reports `NoAdvertisedPaymentMethods`. The SDK does no gateway selection, filtering or inference. Each rendered method's wrapper carries `data-flopay-payment-method="<method>"`.
207
+ - **Laid out like checkout.** Wallets come first, then PayPal, then one tile per alternative method, then an `or add a card` rule and the hosted card form. The wallet buttons, the method tiles, the inline form a tile opens and its `Save …` button are the components `FloPayCheckout` draws, so a buyer sees the same thing whether paying or saving a method. A tile appears only once Stripe has confirmed it can render that method, and its form opens when the tile is pressed.
208
+ - **A method the provider cannot offer is left out.** A wallet the device does not have, or a method Stripe does not support in the session currency (`sepa_debit` outside EUR, for example), is not drawn and `onError` is not called. Only when no advertised method can be offered at all does `onError` receive `payment_method_setup_unavailable` (`retryable: false`).
207
209
  - **Stripe methods use the session's own currency.** Stripe wallets and alternative methods receive the `currency` the setup-session read carries, never a guessed one. When the read carries none, they are not rendered; the card form and PayPal are unaffected. If a session advertises only Stripe wallets or alternative methods and the read carries no currency, nothing can render: `onError` receives `NoAdvertisedPaymentMethods` (`retryable: false`) with a message that names those methods and the missing currency.
208
210
  - **A failing method never takes the card form down.** When a wallet, alternative method or PayPal fails for good (its code does not load, it throws, or the provider reports a failure that cannot be retried), that method is removed, the others stay mounted, and `onError` receives the failure with `retryable: true` while another advertised method is still usable. Keep the setup open on a retryable error. Only when nothing usable is left is it `retryable: false`. A failure the method itself reports as retryable is passed through unchanged, and the method stays.
209
211
  - **Card-only sessions behave exactly like `FloPayCardSetup`.** They use the same hosted form, overlay wording (`SAVING CARD...`, `CARD SAVED`, `CARD NOT SAVED`) and callbacks, and never request Stripe.js. Stripe.js loads lazily, only when the session advertises a Stripe wallet or alternative method. A PayPal-only session never loads Stripe either.
@@ -1,6 +1,6 @@
1
- "use strict";var Q=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Pe=(e,r)=>{for(var t in r)Q(e,t,{get:r[t],enumerable:!0})},Te=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Fe(r))!Ee.call(e,o)&&o!==t&&Q(e,o,{get:()=>r[o],enumerable:!(n=ve(r,o))||n.enumerable});return e};var Ve=e=>Te(Q({},"__esModule",{value:!0}),e);var Qe={};Pe(Qe,{FloPayCardSetup:()=>Re,FloPayCardSetupError:()=>$});module.exports=Ve(Qe);var X=require("@flopay/js/card-setup"),b=require("@flopay/shared"),u=require("react");function 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:`
1
+ "use strict";var Q=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Fe=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Pe=(e,r)=>{for(var t in r)Q(e,t,{get:r[t],enumerable:!0})},Te=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of Fe(r))!Ee.call(e,o)&&o!==t&&Q(e,o,{get:()=>r[o],enumerable:!(n=ve(r,o))||n.enumerable});return e};var Ve=e=>Te(Q({},"__esModule",{value:!0}),e);var Qe={};Pe(Qe,{FloPayCardSetup:()=>Re,FloPayCardSetupError:()=>$});module.exports=Ve(Qe);var X=require("@flopay/js/card-setup"),b=require("@flopay/shared"),u=require("react");function se(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(i=>i.startsWith("background")),a={};for(let[i,l]of Object.entries(e))i in t||o&&i.startsWith("background")||(a[i]=l);for(let i of n)a[i]=t[i];return a}var Ae=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Le(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Ae.has(r.charAt(0).toLowerCase()+r.slice(1))}function Be(e,r){return typeof r=="number"&&r!==0&&!Le(e)?`${r}px`:String(r).trim()}function ue(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Be(t,n)}}}var le={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ce(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?le.dark:le.light,a=r.colorText??(n?"#F1F5F9":"#262833"),i=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:a,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:i?.color??a}}function T(e){if(!e)return;let r=t=>{console.error("[FloPay] Merchant callback failed; checkout continued.",t)};try{Promise.resolve(e()).catch(r)}catch(t){r(t)}}var d=require("react/jsx-runtime");var Oe={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function de({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:i="You will be automatically redirected, do not close or navigate away from this window.",theme:l=Oe}){let s={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,d.jsx)("div",{"data-testid":"flopay-processing-overlay","data-status":e,role:"dialog","aria-modal":"true",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(2px)"},children:(0,d.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...l.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,d.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{animation:"flopay-spin 0.8s linear infinite"},children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,d.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,d.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,d.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:20,strokeDashoffset:20,animation:"flopay-draw 0.4s 0.15s ease forwards"}})]})}),e==="error"&&(0,d.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,d.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,d.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,d.jsx)("path",{d:"M8 8l8 8M16 8l-8 8",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",style:{strokeDasharray:12,strokeDashoffset:12,animation:"flopay-draw 0.3s 0.1s ease forwards"}})]})})]}),(0,d.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&i!==null&&(0,d.jsx)("p",{style:s,children:i}),e==="error"&&r&&(0,d.jsx)("p",{style:s,children:r}),(0,d.jsx)("style",{children:`
2
2
  @keyframes flopay-spin { to { transform: rotate(360deg); } }
3
3
  @keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
4
4
  @keyframes flopay-draw { to { stroke-dashoffset: 0; } }
5
5
  @keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
6
- `})]})})}var y=require("react");var Y=require("react"),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 R=(0,y.useRef)(null),k=a??void 0,A=(0,y.useRef)(k);A.current=k;let O=(0,y.useRef)(void 0);return(0,y.useEffect)(()=>{let v=c.current;if(!v)return;let h=!0,G=!1,I=()=>{!h||G||(G=!0,m.current?.())},F=e.on("ready",()=>{I()}),_=e.on("error",x=>{C.current?.(x.message??"There was a problem loading the secure card form.")}),S=e.on("validation",x=>{g.current?.(x.message??null)}),H=A.current??(ee.has(e)?null:void 0),j={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...V.current?{theme:V.current}:{},...H===void 0?{}:{submitLabel:H}};return R.current=V.current??null,O.current=A.current,A.current!==void 0&&ee.add(e),e.mount(v,j).then(()=>{I()}).catch(x=>{h&&C.current?.(x instanceof Error?x.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&&R.current===null||(R.current=o,e.applyTheme?.(o)))},[e,o]),(0,y.useEffect)(()=>{k!==O.current&&(O.current=k,k!==void 0&&ee.add(e),e.setSubmitLabel?.(k??null))},[e,k]),(0,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 xe(e,r={}){let t=e instanceof b.FloPayError?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new $(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Re({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:a,loading:i=null,onReady:l,onComplete:s,onDecline:f,onCancel:c,onValidation:m,onError:C}){let[g,V]=(0,u.useState)(null),[R,k]=(0,u.useState)(null),[A,O]=(0,u.useState)(null),[v,h]=(0,u.useState)(null),[G,I]=(0,u.useState)(null),F=(0,u.useRef)(!1),_=(0,u.useRef)(!1),S=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,b.resolveTheme)(o),[o]),H=(0,u.useMemo)(()=>typeof o=="object"?o:S?ke({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,o]),j=(0,u.useMemo)(()=>ie(S?.buttonsLayout.cardFormContainer,a),[S,a]),x=(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=xe(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||!R?.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,...x?{theme:x}:{}}),(0,w.jsx)(fe,{capture:g,html:R.html,messageToken:R.messageToken,expectedOrigin:R.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=xe(new Error(p),{code:"card_setup_widget_failed",retryable:!0});T(()=>q.current?.(L))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
6
+ `})]})})}var y=require("react");var Y=require("react"),fe=typeof window>"u"?Y.useEffect:Y.useLayoutEffect;var re=require("react/jsx-runtime"),ee=new WeakSet;function pe({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:i,onReady:l,onError:s,onValidation:f}){let c=(0,y.useRef)(null),m=(0,y.useRef)(l),C=(0,y.useRef)(s),g=(0,y.useRef)(f);m.current=l,C.current=s,g.current=f;let V=(0,y.useRef)(o);V.current=o;let R=(0,y.useRef)(null),k=a??void 0,A=(0,y.useRef)(k);A.current=k;let O=(0,y.useRef)(void 0);return(0,y.useEffect)(()=>{let v=c.current;if(!v)return;let h=!0,G=!1,I=()=>{!h||G||(G=!0,m.current?.())},F=e.on("ready",()=>{I()}),_=e.on("error",w=>{C.current?.(w.message??"There was a problem loading the secure card form.")}),S=e.on("validation",w=>{g.current?.(w.message??null)}),H=A.current??(ee.has(e)?null:void 0),j={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...V.current?{theme:V.current}:{},...H===void 0?{}:{submitLabel:H}};return R.current=V.current??null,O.current=A.current,A.current!==void 0&&ee.add(e),e.mount(v,j).then(()=>{I()}).catch(w=>{h&&C.current?.(w instanceof Error?w.message:"Failed to load the secure card form.")}),()=>{h=!1,F(),_(),S(),e.unmount()}},[e,r,t,n]),fe(()=>{let v=c.current;v&&ue(v,i)},[i]),(0,y.useEffect)(()=>{o!==void 0&&(o===null&&R.current===null||(R.current=o,e.applyTheme?.(o)))},[e,o]),(0,y.useEffect)(()=>{k!==O.current&&(O.current=k,k!==void 0&&ee.add(e),e.setSubmitLabel?.(k??null))},[e,k]),(0,re.jsx)("div",{ref:c,"data-testid":"flopay-vault-card-fields"})}var ge=/^#([0-9a-f]{6})$/i,Ie=/^#([0-9a-f]{3})$/i,ye=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,be=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Me=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,_e=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Ne=/^(-?\d+(?:\.\d+)?)em$/,De=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,ze=/^[a-z][a-z0-9 -]{0,31}$/i,We=new Set(["none","uppercase","lowercase","capitalize"]);function he(e){if(typeof e!="string")return null;let r=e.trim(),t=ge.exec(r);if(t){let c=Number.parseInt(t[1],16);return{r:c>>16&255,g:c>>8&255,b:c&255,a:null}}let n=Ie.exec(r);if(n){let[c,m,C]=n[1].split("").map(g=>Number.parseInt(g+g,16));return{r:c,g:m,b:C,a:null}}let o=ye.exec(r),a=o?null:be.exec(r),i=o??a;if(!i)return null;let l=Number(i[1]),s=Number(i[2]),f=Number(i[3]);return l>255||s>255||f>255?null:{r:l,g:s,b:f,a:a?Number(a[4]):null}}function Ce({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(ge.test(r)||ye.test(r))return r;let t=be.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=he(r);return n?Ce(n):void 0}function U(e,r=.12){let t=he(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Ce({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=a}return o.trim()&&t.push(o.trim()),t}function B(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=_e.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e,r,t){if(typeof e!="string")return;let n=Ne.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function Ge(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let a=W(o," "),i=z(a[0]);if(!i)return;let l=n/(r.length-1)*100,s=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),f=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<f)return;t.push({color:i,position:s})}return{type:"linearGradient",angle:0,stops:t}}function He(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Me.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Ge(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Ye(e){return e.type==="solid"?{type:"solid",color:U(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:U(r.color)}))}}function Ue(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let f=z(s);if(f){t=f;continue}let c=B(s,-128,128);if(c===void 0)return;n.push(c)}if(!t||n.length<2||n.length>4)return;let[o,a,i=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||i>128||Math.abs(l)>32))return{color:t,inset:r,offsetX:o,offsetY:a,blur:i,spread:l}}function Xe(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(Ue);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function me(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>ze.test(t)).slice(0,4);return r.length>0?r:void 0}function je(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=B(r[0],0,64),n=B(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function qe(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function Se({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,a=He(n.background??n.backgroundColor),i=z(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&Ye(a),s={fontFamilies:me(n.fontFamily)??me(t),fontSize:B(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:qe(n.fontWeight)??600,letterSpacing:$e(n.letterSpacing,-.1,.5)??.01,lineHeight:B(n.lineHeight,.8,2)??1,textTransform:We.has(String(n.textTransform))?n.textTransform:"uppercase"},f=je(n.padding),c=Xe(n.boxShadow),m=B(n.borderRadius,0,9999),C=typeof n.backdropFilter=="string"?B(De.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:s,...f?{spacing:f}:{},...c?{shadow:c}:{},...m===void 0?{}:{borderRadius:m},disabledOpacity:e?.theme==="night"?.8:.6,...C===void 0?{}:{backdropBlur:C}}}function Ke(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?U(n,r):e}function Ze(e){if(typeof e=="number"||typeof e=="string")return e}function ke({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=m=>typeof m=="string"&&m?m:void 0,a=r.submitButton,i=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=t==="buttons",s=r.nameInput,f=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",c=Se({appearance:e,buttonsStyles:r,fontFamily:f});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??Ke(i,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:f,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ze(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...c?{submitButton:c}:{}}}var x=require("react/jsx-runtime"),$=class extends b.FloPayError{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function we(e,r={}){let t=e instanceof b.FloPayError?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new $(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Re({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:a,loading:i=null,onReady:l,onComplete:s,onDecline:f,onCancel:c,onValidation:m,onError:C}){let[g,V]=(0,u.useState)(null),[R,k]=(0,u.useState)(null),[A,O]=(0,u.useState)(null),[v,h]=(0,u.useState)(null),[G,I]=(0,u.useState)(null),F=(0,u.useRef)(!1),_=(0,u.useRef)(!1),S=(0,u.useMemo)(()=>typeof o=="object"?void 0:(0,b.resolveTheme)(o),[o]),H=(0,u.useMemo)(()=>typeof o=="object"?o:S?ke({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,o]),j=(0,u.useMemo)(()=>se(S?.buttonsLayout.cardFormContainer,a),[S,a]),w=(0,u.useMemo)(()=>S?ce(S):void 0,[S]),te=(0,u.useRef)(l),q=(0,u.useRef)(C),ne=(0,u.useRef)(s),oe=(0,u.useRef)(f),ae=(0,u.useRef)(c),ie=(0,u.useRef)(m),N=(0,u.useRef)(!1),K=(0,u.useRef)(!1),Z=(0,u.useRef)(0);return te.current=l,q.current=C,ne.current=s,oe.current=f,ae.current=c,ie.current=m,(0,u.useEffect)(()=>{let p=Z.current+1;return Z.current=p,()=>{queueMicrotask(()=>{Z.current===p&&(N.current||K.current||(K.current=!0,T(()=>{ae.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,u.useEffect)(()=>{let p=!0,L=new X.PaymentAPI((0,b.resolveBillingApiUrl)(t),{telemetry:n});return V(null),k(null),O(null),N.current=!1,K.current=!1,(async()=>{try{if(!e.trim())throw new b.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new b.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await L.getUnifiedCheckoutSession(e,r);if(!p)return;let E=D.data.session;if(!E||!(0,b.isCardSetupCheckoutSession)(E))throw new b.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let M=E.vault;if(M?.html?.trim()||(M=await L.getVaultCapture(e,r)),!M.html?.trim())throw new b.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!p)return;k(M),V(new X.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!p)return;let E=we(D);N.current=!0,O(E),T(()=>q.current?.(E))}})(),()=>{p=!1,L.destroy()}},[t,r,e,n]),(0,u.useEffect)(()=>{if(!g)return;let p=!1;_.current=!1,F.current=!1;let L=g.on("submitting",()=>{F.current=!0,I(null),h("processing")}),D=g.on("complete",P=>{N.current=!0,F.current=!1,h("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,T(()=>{ne.current?.({status:"succeeded",sessionId:e,...P.paymentMethod?{paymentMethod:P.paymentMethod}:{}})}),p||h(null))))()}),E=g.on("decline",P=>{N.current=!0,F.current=!1,I(P.message??null),h("error"),T(()=>{oe.current?.({status:"declined",sessionId:e,...P.declineReason?{reason:P.declineReason}:{},...P.message?{message:P.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),p||h(null)))()}),M=g.on("challenge_dismissed",()=>{h(null)});return()=>{p=!0,L(),D(),E(),M()}},[g,e]),A?(0,x.jsx)("div",{role:"alert",children:A.message}):!g||!R?.html?(0,x.jsx)(x.Fragment,{children:i}):(0,x.jsxs)(x.Fragment,{children:[v&&(0,x.jsx)(de,{status:v,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...w?{theme:w}:{}}),(0,x.jsx)(pe,{capture:g,html:R.html,messageToken:R.messageToken,expectedOrigin:R.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{T(()=>te.current?.())},onValidation:p=>{T(()=>ie.current?.(p))},onError:p=>{if(!p)return;F.current&&(F.current=!1,I(p),h("error"),setTimeout(()=>h(null),400));let L=we(new Error(p),{code:"card_setup_widget_failed",retryable:!0});T(()=>q.current?.(L))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
@@ -1 +1 @@
1
- import{j as e,l as t}from"./chunk-I4TPZWBS.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
1
+ import{k as e,m as t}from"./chunk-AZRGKPW7.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
@@ -0,0 +1,6 @@
1
+ import{useEffect as ee,useRef as E}from"react";function le(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(a=>a.startsWith("background")),i={};for(let[a,u]of Object.entries(e))a in t||o&&a.startsWith("background")||(i[a]=u);for(let a of n)i[a]=t[a];return i}var Fe=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Te(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Fe.has(r.charAt(0).toLowerCase()+r.slice(1))}function Pe(e,r){return typeof r=="number"&&r!==0&&!Te(e)?`${r}px`:String(r).trim()}function ce(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Pe(t,n)}}}import{useEffect as Ve,useLayoutEffect as Ae}from"react";var de=typeof window>"u"?Ve:Ae;import{jsx as Y,jsxs as Le}from"react/jsx-runtime";var re=new WeakSet;function fe({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:i,containerStyle:a,onReady:u,onError:s,onValidation:c}){let l=E(null),f=E(u),y=E(s),p=E(c);f.current=u,y.current=s,p.current=c;let T=E(o);T.current=o;let k=E(null),C=i??void 0,P=E(C);P.current=C;let L=E(void 0);return ee(()=>{let w=l.current;if(!w)return;let m=!0,G=!1,B=()=>{!m||G||(G=!0,f.current?.())},x=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??(re.has(e)?null:void 0),q={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&&re.add(e),e.mount(w,q).then(()=>{B()}).catch(S=>{m&&y.current?.(S instanceof Error?S.message:"Failed to load the secure card form.")}),()=>{m=!1,x(),_(),b(),e.unmount()}},[e,r,t,n]),de(()=>{let w=l.current;w&&ce(w,a)},[a]),ee(()=>{o!==void 0&&(o===null&&k.current===null||(k.current=o,e.applyTheme?.(o)))},[e,o]),ee(()=>{C!==L.current&&(L.current=C,C!==void 0&&re.add(e),e.setSubmitLabel?.(C??null))},[e,C]),Y("div",{ref:l,"data-testid":"flopay-vault-card-fields"})}function cr({label:e}){return Le("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[Y("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),Y("span",{children:e}),Y("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}import{PaymentAPI as Je,PciVaultCardCapture as Qe}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as er,resolveBillingApiUrl as rr,resolveTheme as tr}from"@flopay/shared";import{useEffect as te,useMemo as X,useRef as h,useState as $}from"react";var pe={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function me(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?pe.dark:pe.light,i=r.colorText??(n?"#F1F5F9":"#262833"),a=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:i,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:i,success:o.success,error:o.error},noteColor:a?.color??i}}function F(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 Be={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ge({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:i="PAYMENT FAILED",successNote:a="You will be automatically redirected, do not close or navigate away from this window.",theme:u=Be}){let s={fontSize:13,color:u.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return 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 be=/^#([0-9a-f]{6})$/i,Oe=/^#([0-9a-f]{3})$/i,he=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ce=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,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 Se(e){if(typeof e!="string")return null;let r=e.trim(),t=be.exec(r);if(t){let l=Number.parseInt(t[1],16);return{r:l>>16&255,g:l>>8&255,b:l&255,a:null}}let n=Oe.exec(r);if(n){let[l,f,y]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:l,g:f,b:y,a:null}}let o=he.exec(r),i=o?null:Ce.exec(r),a=o??i;if(!a)return null;let u=Number(a[1]),s=Number(a[2]),c=Number(a[3]);return u>255||s>255||c>255?null:{r:u,g:s,b:c,a:i?Number(i[4]):null}}function ke({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(be.test(r)||he.test(r))return r;let t=Ce.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Se(r);return n?ke(n):void 0}function U(e,r=.12){let t=Se(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ke({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function 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=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=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 Ge(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Ie.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=$e(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function He(e){return e.type==="solid"?{type:"solid",color:U(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:U(r.color)}))}}function Ye(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 Ue(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(Ye);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ye(e){if(typeof e!="string")return;let r=W(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=A(r[0],0,64),n=A(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function je(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function we({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=Ge(n.background??n.backgroundColor),a=z(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&He(i),s={fontFamilies:ye(n.fontFamily)??ye(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:je(n.fontWeight)??600,letterSpacing:We(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:ze.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Xe(n.padding),l=Ue(n.boxShadow),f=A(n.borderRadius,0,9999),y=typeof n.backdropFilter=="string"?A(Ne.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 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)?U(n,r):e}function Ke(e){if(typeof e=="number"||typeof e=="string")return e}function xe({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=we({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??qe(a,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ke(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as Ee,jsx as j,jsxs as nr}from"react/jsx-runtime";var ne=class extends M{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ve(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 ne(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 Pr({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),x=h(!1),_=h(!1),b=X(()=>typeof o=="object"?void 0:tr(o),[o]),H=X(()=>typeof o=="object"?o:b?xe({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),q=X(()=>le(b?.buttonsLayout.cardFormContainer,i),[b,i]),S=X(()=>b?me(b):void 0,[b]),oe=h(u),K=h(y),ie=h(s),ae=h(c),se=h(l),ue=h(f),N=h(!1),Z=h(!1),J=h(0);return oe.current=u,K.current=y,ie.current=s,ae.current=c,se.current=l,ue.current=f,te(()=>{let d=J.current+1;return J.current=d,()=>{queueMicrotask(()=>{J.current===d&&(N.current||Z.current||(Z.current=!0,F(()=>{se.current?.({status:"cancelled",sessionId:e})})))})}},[e]),te(()=>{let d=!0,V=new Je(rr(t),{telemetry:n});return T(null),C(null),L(null),N.current=!1,Z.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 R=D.data.session;if(!R||!er(R))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let O=R.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 Qe({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!d)return;let R=ve(D);N.current=!0,L(R),F(()=>K.current?.(R))}})(),()=>{d=!1,V.destroy()}},[t,r,e,n]),te(()=>{if(!p)return;let d=!1;_.current=!1,x.current=!1;let V=p.on("submitting",()=>{x.current=!0,B(null),m("processing")}),D=p.on("complete",v=>{N.current=!0,x.current=!1,m("success"),(async()=>(await new Promise(Q=>setTimeout(Q,600)),!_.current&&(_.current=!0,F(()=>{ie.current?.({status:"succeeded",sessionId:e,...v.paymentMethod?{paymentMethod:v.paymentMethod}:{}})}),d||m(null))))()}),R=p.on("decline",v=>{N.current=!0,x.current=!1,B(v.message??null),m("error"),F(()=>{ae.current?.({status:"declined",sessionId:e,...v.declineReason?{reason:v.declineReason}:{},...v.message?{message:v.message}:{}})}),(async()=>(await new Promise(Q=>setTimeout(Q,400)),d||m(null)))()}),O=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,V(),D(),R(),O()}},[p,e]),P?j("div",{role:"alert",children:P.message}):!p||!k?.html?j(Ee,{children:a}):nr(Ee,{children:[w&&j(ge,{status:w,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...S?{theme:S}:{}}),j(fe,{capture:p,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:H,containerStyle:q,onReady:()=>{F(()=>oe.current?.())},onValidation:d=>{F(()=>ue.current?.(d))},onError:d=>{if(!d)return;x.current&&(x.current=!1,B(d),m("error"),setTimeout(()=>m(null),400));let V=ve(new Error(d),{code:"card_setup_widget_failed",retryable:!0});F(()=>K.current?.(V))}})]})}export{le as a,me as b,F as c,ge as d,de as e,fe as f,cr as g,qe as h,Ke as i,xe as j,ne as k,ve as l,Pr as m};
@@ -0,0 +1 @@
1
+ import{a as Ve,b as De,c as P,d as Le,f as Oe,g as Ie,j as Be,l as F}from"./chunk-AZRGKPW7.mjs";import{PaymentAPI as Ge,PciVaultCardCapture as st}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as it,resolveBillingApiUrl as ae,resolveTheme as lt}from"@flopay/shared";import ut,{Suspense as je,useCallback as D,useEffect as oe,useMemo as x,useRef as m,useState as w}from"react";import{PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as Ze}from"@flopay/shared";var et=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),tt=new Set(["wallet","apm"]);function V(t){return typeof t=="string"&&t.trim().length>0}function rt(t){if(typeof t!="object"||t===null)return!1;let o=t;return V(o.family)&&V(o.paymentMethodType)}function nt(t){let a=t.raw?.data?.currency;return V(a)?a.trim().toUpperCase():null}function xe(t){let o=nt(t),a=t.data.session?.advertisedPaymentMethods;if(!Array.isArray(a))return{card:!0,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]};let i={card:!1,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]},c=new Set;for(let l of a){if(!rt(l)||c.has(l.paymentMethodType))continue;let{family:d,paymentMethodType:f,providerType:U,publishableKey:_}=l;if(d==="card"){if(f!=="card")continue;i.card=!0}else if(tt.has(d)){if(U!=="stripe"||f==="card"||!V(_))continue;if(o===null){i.skippedForMissingCurrency.includes(f)||i.skippedForMissingCurrency.push(f);continue}i.stripe.push({method:f,publishableKey:_,currency:o})}else if(d==="paypal"){if(f!==Ze||U!=="paypal"||!V(_))continue;i.paypal={clientId:_,...V(l.environment)?{environment:l.environment}:{}}}else continue;c.add(f)}return i.paypal&&(i.stripe=i.stripe.filter(l=>l.method!=="paypal")),i}function j(t){return[...t.card?["card"]:[],...t.stripe.map(o=>o.method),...t.paypal?["paypal"]:[]]}function Ue(t){return j(t).length>0}function K(t){return et.has(t)?"wallet":"apm"}var at=["setup_intent","setup_intent_client_secret","redirect_status"];function Ne(){if(typeof window>"u")return null;let t=new URLSearchParams(window.location.search);return!t.has("setup_intent")||!t.has("redirect_status")?null:{failed:t.get("redirect_status")==="failed"}}function Ye(){if(typeof window>"u")return;let t=new URL(window.location.href),o=!1;for(let a of at)t.searchParams.has(a)&&(t.searchParams.delete(a),o=!0);o&&window.history.replaceState(window.history.state,"",t.toString())}function We(t){return t==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}import{Fragment as Ke,jsx as y,jsxs as ie}from"react/jsx-runtime";var ct=15,dt=2e3;function pt(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function se(t){return new Promise(o=>setTimeout(o,t))}async function mt(t,o,a){if(!o.trim())throw new M("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new M("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let i=await t.getUnifiedCheckoutSession(o,a),c=i.data.session;if(!c||!it(c))throw new M("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let l=xe(i);if(!Ue(l)){let{skippedForMissingCurrency:d}=l,f=d.length>0?`FloPay: this setup session advertises only Stripe methods (${d.join(", ")}), and they need the session's currency, which the setup-session read did not carry.`:"FloPay: this setup session advertises no payment method.";throw new M(f,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:c,advertisement:l}}async function yt(t,o,a,i){let c=o.vault??null;if(c?.html?.trim()||(c=await t.getVaultCapture(a,i)),!c.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return c}var z=class extends ut.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(a){this.props.onFailed(a,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function Ft({branches:{StripeSetupMethod:t,PayPalSetupMethod:o},sessionId:a,nonce:i,billingApiUrl:c,telemetry:l,theme:d="modern-light",containerStyle:f,loading:U=null,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe}){let[q]=w(Ne),[N,$]=w(null),[ze,J]=w(!1),[g,me]=w(null),[L,ye]=w(null),[fe,he]=w(null),[Y,h]=w(null),[Q,X]=w(()=>new Set),R=m(Q),Z=m(null);Z.current=N;let v=m(!1),ee=m(!1),O=m(!1),te=m(!1),re=m(0),W=m(0),A=m(!1),S=x(()=>typeof d=="object"?void 0:lt(d),[d]),qe=x(()=>typeof d=="object"?d:S?Be({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,d]),$e=x(()=>Ve(S?.buttonsLayout.cardFormContainer,f),[S,f]),Se=x(()=>S?De(S):void 0,[S]),p=m({sessionId:a,nonce:i,billingApiUrl:c,telemetry:l,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe});p.current={sessionId:a,nonce:i,billingApiUrl:c,telemetry:l,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe},oe(()=>{A.current=!0;let e=re.current+1;return re.current=e,()=>{A.current=!1,W.current+=1,queueMicrotask(()=>{re.current===e&&(O.current||te.current||(te.current=!0,P(()=>{p.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let k=D((e,r)=>{O.current=!0,v.current=!1,h({status:"success",wording:e,message:null}),(async()=>(await se(600),!ee.current&&(ee.current=!0,P(()=>{p.current.onComplete?.({status:"succeeded",sessionId:p.current.sessionId,...r?{paymentMethod:r}:{}})}),A.current&&h(null))))()},[]),T=D((e,r)=>{O.current=!0,v.current=!1,h({status:"error",wording:e,message:r.message??null}),P(()=>{p.current.onDecline?.({status:"declined",sessionId:p.current.sessionId,...r.reason?{reason:r.reason}:{},...r.message?{message:r.message}:{}})}),(async()=>(await se(400),A.current&&h(null)))()},[]),C=D((e,r)=>{v.current?(v.current=!1,h({status:"error",wording:e,message:r.message}),setTimeout(()=>{A.current&&h(null)},400)):h(null),P(()=>p.current.onError?.(r))},[]),H=D(async e=>{let r=W.current+1;W.current=r;let s=()=>!A.current||r!==W.current;v.current=!0,h({status:"processing",wording:"payment_method",message:null});let u=new Ge(ae(p.current.billingApiUrl),{telemetry:p.current.telemetry});try{for(let n=0;n<ct;n+=1){if((n>0||e.waitFirst)&&await se(dt),s())return;let b=await u.getUnifiedCheckoutSession(p.current.sessionId,p.current.nonce);if(s())return;let E=b.data.session?.status;if(E==="complete"){J(!0),k("payment_method");return}if(E==="expired")throw new M("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new M("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(n){if(s())return;let b=n instanceof M&&n.code==="payment_method_setup_unverified";C("payment_method",F(n,b?{retryable:!0}:{}))}finally{u.destroy()}},[C,k]);oe(()=>{let e=!0,r=new Ge(ae(c),{telemetry:l});$(null),J(!1),me(null),ye(null),he(null);let s=new Set;return R.current=s,X(s),O.current=!1,te.current=!1,ee.current=!1,(async()=>{try{let{session:u,advertisement:n}=await mt(r,a,i);if(!e)return;let b={advertisement:n,customer:pt(u)};if(q){if(Ye(),u.status==="complete"){J(!0),$(b),k("payment_method");return}q.failed?T("payment_method",{reason:"redirect_failed"}):H({waitFirst:!0})}let E=n.card?await yt(r,u,a,i):null;if(!e)return;$(b),E&&(ye(E),me(new st({sessionId:a,operation:"card_setup",telemetry:l})))}catch(u){if(!e)return;let n=F(u);O.current=!0,he(n),P(()=>p.current.onError?.(n))}})(),()=>{e=!1,r.destroy()}},[c,i,q,T,k,a,l,H]),oe(()=>{if(!g)return;v.current=!1;let e=g.on("submitting",()=>{v.current=!0,h({status:"processing",wording:"card",message:null})}),r=g.on("complete",n=>{k("card",n.paymentMethod)}),s=g.on("decline",n=>{T("card",{...n.declineReason?{reason:n.declineReason}:{},...n.message?{message:n.message}:{}})}),u=g.on("challenge_dismissed",()=>{h(null)});return()=>{e(),r(),s(),u()}},[g,T,k]);let ge=D((e,r,s)=>{if(s.retryable){C("payment_method",F(r,s));return}if(R.current.has(e))return;let u=new Set(R.current);u.add(e),R.current=u,X(u);let n=Z.current?.advertisement,b=n?j(n).some(E=>!u.has(E)):!1;C("payment_method",F(r,{code:s.code,retryable:b}))},[C]),ve=x(()=>({onSubmitting:()=>{v.current=!0,h({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{H({waitFirst:!1})},onDeclined:e=>T("payment_method",e),onValidation:e=>{P(()=>p.current.onValidation?.(e))},onAbandoned:()=>{v.current=!1,h(null)}}),[T,H]),Pe=m(ge);Pe.current=ge;let Ce=m(new Map),G=e=>{let r=Ce.current.get(e);if(r)return r;let s=(u,n)=>Pe.current(e,u,n);return Ce.current.set(e,s),s},be=D(e=>{if(R.current.has(e))return;let r=new Set(R.current);r.add(e),R.current=r,X(r);let s=Z.current?.advertisement;s&&j(s).some(n=>!r.has(n))||C("payment_method",F(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[C]),we=m(be);we.current=be;let Me=m(new Map),_e=e=>{let r=Me.current.get(e);if(r)return r;let s=()=>we.current(e);return Me.current.set(e,s),s},Re=Y?y(Le,{status:Y.status,errorMessage:Y.message,...We(Y.wording),successNote:null,...Se?{theme:Se}:{}}):null;if(fe)return y("div",{role:"alert",children:fe.message});if(!N||ze)return ie(Ke,{children:[Re,N?null:U]});let{advertisement:I,customer:Je}=N,Ee=ae(c),Fe=l===void 0?{}:{telemetry:l},ne=I.stripe.filter(({method:e})=>!Q.has(e)),B=Q.has("paypal")?null:I.paypal,Ae=!!(I.card&&g&&L?.html),ke=({method:e,publishableKey:r,currency:s})=>y("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:y(z,{onFailed:G(e),children:y(je,{fallback:null,children:y(t,{method:e,category:K(e),publishableKey:r,currency:s,sessionId:a,nonce:i,billingApiUrl:Ee,...Fe,...S?{appearance:S.appearance,buttonsLayout:S.buttonsLayout}:{},...typeof d=="string"?{themeId:d}:{},...ve,onFailed:G(e),onUnavailable:_e(e)})})})},e),Qe=ne.filter(({method:e})=>K(e)==="wallet"),Xe=ne.filter(({method:e})=>K(e)!=="wallet"),Te=ne.length>0||B!==null;return ie(Ke,{children:[Re,Te?ie("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Qe.map(ke),B?y("div",{"data-flopay-payment-method":"paypal",children:y(z,{onFailed:G("paypal"),children:y(je,{fallback:null,children:y(o,{clientId:B.clientId,...B.environment?{environment:B.environment}:{},...I.currency?{currency:I.currency}:{},sessionId:a,nonce:i,billingApiUrl:Ee,customer:Je,...Fe,...ve,onFailed:G("paypal"),onUnavailable:_e("paypal")})})})}):null,Xe.map(ke)]}):null,Ae&&Te?y(Ie,{label:"or add a card"}):null,Ae&&g&&L?.html?y("div",{"data-flopay-payment-method":"card",children:y(Oe,{capture:g,html:L.html,messageToken:L.messageToken,expectedOrigin:L.expectedOrigin,theme:qe,containerStyle:$e,onReady:()=>{P(()=>p.current.onReady?.())},onValidation:e=>{P(()=>p.current.onValidation?.(e))},onError:e=>{e&&C("card",F(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{Ft as a};
@@ -0,0 +1,22 @@
1
+ import{a as N,e as D,g as H,i as X,j as Y}from"./chunk-M7R46EDF.mjs";import{PaymentAPI as he}from"@flopay/js/card-setup";import{FloPayError as ge,getStripeMethodDisplayName as be}from"@flopay/shared";import{Elements as Se,ExpressCheckoutElement as ve,PaymentElement as Ee,useElements as ke,useStripe as xe}from"@stripe/react-stripe-js";import{loadStripe as we}from"@stripe/stripe-js";import{useCallback as Q,useMemo as Pe,useRef as Re,useState as h}from"react";import{getStripeMethodDisplayName as K,hasVendoredStripeMethodLogo as pe,resolveStripeMethodBrandVariant as de,stripeExpressMethodToOptionKey as ce}from"@flopay/shared";import{useState as ue}from"react";var z={alipay:"https://cdn.flopay.com/sdk-logos/v1/alipay.svg",bancontact:"https://cdn.flopay.com/sdk-logos/v1/bancontact.svg",blik:"https://cdn.flopay.com/sdk-logos/v1/blik.svg",eps:"https://cdn.flopay.com/sdk-logos/v1/eps.svg",giropay:"https://cdn.flopay.com/sdk-logos/v1/giropay.svg",ideal:"https://cdn.flopay.com/sdk-logos/v1/ideal.svg",klarna:"https://cdn.flopay.com/sdk-logos/v1/klarna.svg",p24:"https://cdn.flopay.com/sdk-logos/v1/p24.svg",sepa_debit:"https://cdn.flopay.com/sdk-logos/v1/sepa_debit.svg",wechat_pay:"https://cdn.flopay.com/sdk-logos/v1/wechat_pay.svg"};import{Fragment as fe,jsx as s,jsxs as L}from"react/jsx-runtime";var ye=`
2
+ .paypal-buttons { margin: 0 !important; vertical-align: top !important; }
3
+ @keyframes flopay-spin { to { transform: rotate(360deg); } }
4
+ @keyframes flopay-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
5
+ @keyframes flopay-fade-in { 0% { opacity: 0; } 100% { opacity: 1; } }
6
+ @keyframes flopay-buttons-enter {
7
+ 0% { opacity: 0; transform: translateX(-16px) scale(0.97); }
8
+ 100% { opacity: 1; transform: translateX(0) scale(1); }
9
+ }
10
+ @keyframes flopay-buttons-exit {
11
+ 0% { opacity: 1; transform: translateX(0) scale(1); }
12
+ 100% { opacity: 0; transform: translateX(-16px) scale(0.97); }
13
+ }
14
+ @keyframes flopay-card-enter {
15
+ 0% { opacity: 0; transform: translateX(16px) scale(0.97); }
16
+ 100% { opacity: 1; transform: translateX(0) scale(1); }
17
+ }
18
+ @keyframes flopay-card-exit {
19
+ 0% { opacity: 1; transform: translateX(0) scale(1); }
20
+ 100% { opacity: 0; transform: translateX(16px) scale(0.97); }
21
+ }
22
+ `,me=44;function U(){return s("style",{children:ye})}function W(e,r){let t=e.availablePaymentMethods;return t&&r.some(o=>t[o])?"ready":"unavailable"}function $({state:e,placeholderTestId:r,borderRadius:t=8,children:o}){return e==="unavailable"||e==="load_error"?null:L("div",{style:{position:"relative",minHeight:44},children:[s("div",{"data-testid":r,"aria-hidden":e==="ready",style:{position:"absolute",inset:0,height:44,borderRadius:t,background:"#e5e7eb",animation:e==="ready"?void 0:"flopay-pulse 1.5s ease-in-out infinite",opacity:e==="ready"?0:1,transform:e==="ready"?"scale(0.985)":"scale(1)",transition:"opacity 140ms ease-out, transform 140ms ease-out",pointerEvents:"none"}}),s("div",{style:{minHeight:44,opacity:e==="ready"?1:0,transform:e==="ready"?"translateY(0)":"translateY(2px)",transition:"opacity 140ms ease-out, transform 140ms ease-out",pointerEvents:e==="ready"?"auto":"none"},children:o})]})}function De(e){return e!=="unavailable"&&e!=="load_error"}function j({method:e,themeId:r,submitting:t=!1,disabled:o=!1,highlighted:l=!1,hasNextStep:c=!1,onClick:p,backgroundColor:u,borderColor:f,textColor:k,borderRadius:x,fontFamily:w}){let d=de(e,r),g=z[e],[S,b]=ue(!1),y=!!g&&!S,v=d?.backgroundColor??u??"#ffffff",P=d?.borderColor??f??"#d1d5db",R=d?.textColor??k??"#262833";return s("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!o&&p()},disabled:t||o,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:me,padding:"0 1rem",backgroundColor:v,color:R,border:`1px solid ${P}`,borderRadius:x??8,fontSize:"0.95rem",fontWeight:600,fontFamily:w,cursor:t||o?"not-allowed":"pointer",opacity:o&&!t?.55:1,animation:t?"flopay-pulse 1.5s ease-in-out infinite":void 0,display:"flex",alignItems:"center",justifyContent:"center",gap:8,transition:"transform 0.1s, opacity 140ms ease-out, border-color 140ms ease-out",boxShadow:l?"0 0 0 2px rgba(74, 73, 255, 0.15)":void 0},children:t?s("span",{style:{margin:"0 auto"},children:`Connecting to ${K(e)}\u2026`}):L(fe,{children:[L("span",{style:{display:"inline-flex",alignItems:"center",gap:pe(e)?8:0},children:[y?s("img",{src:g,alt:"","aria-hidden":"true",onError:()=>b(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!y&&d?.logoSvg?s("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:d.logoSvg}}):null,s("span",{children:K(e)})]}),c&&s("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:R,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:"1rem",top:"50%",transform:"translateY(-50%)",flexShrink:0,opacity:.7},"aria-hidden":"true",children:s("path",{d:"M9 18l6-6-6-6"})})]})})}function G(e){let r=new Set(e.map(ce)),t=o=>o==="applePay"||o==="googlePay"?"always":"auto";return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(o=>[o,r.has(o)?t(o):"never"]))}var V={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},q={type:"accordion",defaultCollapsed:!1,radios:"never"};function J({testId:e,attributes:r,disabled:t,onClick:o,color:l,borderRadius:c,style:p,children:u}){return s("button",{type:"button","data-testid":e,...r,onClick:o,disabled:t,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:l,color:"white",border:"none",borderRadius:c,fontSize:"1rem",fontWeight:600,cursor:t?"not-allowed":"pointer",opacity:t?.5:1,transition:"opacity 120ms ease-out",...p??{}},children:u})}import{Fragment as ee,jsx as m,jsxs as B}from"react/jsx-runtime";var te={apple_pay:{types:["card"],wallet:"applePay"},google_pay:{types:["card"],wallet:"googlePay"},link:{types:["link"],wallet:"link"},paypal:{types:["paypal"],wallet:"paypal"},amazon_pay:{types:["amazon_pay"],wallet:"amazonPay"}},I=new Map;function _e(e){let r=I.get(e);if(r)return r;let t=we(e).catch(o=>{throw I.delete(e),o});return I.set(e,t),t}var Ce={night:"night",flat:"flat"};function Me(e){return e?{theme:Ce[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function Te(e){return D(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Z(e){return e==="paypal"?"PayPal":be(e)}function Le(){return typeof window>"u"?"":window.location.href}var Ie={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"};function Ve(e){let{publishableKey:r,method:t,currency:o,appearance:l}=e,[c]=h(()=>_e(r)),p=Pe(()=>{let u=Me(l);return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:te[t]?.types??[t],...u?{appearance:u}:{}}},[l,o,t]);return m(Se,{stripe:c,options:p,children:m(Be,{...e})})}function Be({method:e,category:r,sessionId:t,nonce:o,billingApiUrl:l,telemetry:c,appearance:p,themeId:u,buttonsLayout:f,onSubmitting:k,onConfirmed:x,onDeclined:w,onFailed:d,onValidation:g,onUnavailable:S}){let b=xe(),y=ke(),[v,P]=h(!1),[R,A]=h("loading"),[oe,re]=h(!1),[_,ae]=h(!1),C=Re(!1),[E]=h(()=>X()),[ne,se]=h(!1),M=Q((a,i)=>{if(H(a,{inAppBrowser:E.inAppBrowser,handoffObserved:!1}).popupBlocked){se(!0),d(new Error(N(Z(e),!0,E.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}d(i.message===void 0?a:new Error(i.message),{code:i.code,retryable:!0})},[E.inAppBrowser,e,d]),O=Q(async()=>{if(!(!b||!y||C.current)){C.current=!0,P(!0);try{let a=await y.submit();if(a.error){g(a.error.message??null);return}k();let i=await new he(l,{telemetry:c}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(i.provider!=="stripe"||i.intentKind!=="setup")throw new ge("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let n=await b.confirmSetup({elements:y,clientSecret:i.clientSecret,confirmParams:{return_url:Le()},redirect:"if_required"});if(n.error){Te(n.error)?w({...n.error.decline_code||n.error.code?{reason:n.error.decline_code??n.error.code}:{},...n.error.message?{message:n.error.message}:{}}):M(n.error,{code:"payment_method_setup_provider_failed",message:n.error.message??"The payment method could not be saved."});return}x()}catch(a){M(a,{code:"payment_method_setup_failed"})}finally{C.current=!1,P(!1)}}},[l,r,y,e,o,x,w,k,g,M,t,b,c]),T=te[e]?.wallet,ie=T==="paypal"&&Y(E,"auto",ne?"blocked":E.popupCapability)==="redirect",F=p?.variables?.borderRadius??f?.cardButton?.borderRadius??8;if(r==="wallet"&&T&&!ie)return B(ee,{children:[m(U,{}),m($,{state:R,borderRadius:F,children:m(ve,{options:{...V,paymentMethods:G([e])},onReady:a=>{let i=W(a,[T]);A(i),i==="unavailable"&&S()},onLoadError:()=>{A("load_error"),S()},onConfirm:()=>{O()}})})]});let le=Z(e);return B(ee,{children:[oe?m(j,{method:e,themeId:u,hasNextStep:!0,highlighted:_,disabled:v,onClick:()=>ae(a=>!a),backgroundColor:f?.cardButton?.backgroundColor,borderColor:f?.cardInputBorder,textColor:f?.cardButton?.color,borderRadius:F}):null,B("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!_,style:_?{display:"flex",flexDirection:"column"}:Ie,children:[m(Ee,{options:{layout:q},onReady:()=>re(!0),onLoadError:()=>S(),onChange:a=>{a.complete&&g(null)}}),m(J,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!b||!y||v||!_,onClick:()=>{O()},color:p?.variables?.colorPrimary??"#4A49FF",borderRadius:p?.variables?.borderRadius??"8px",style:f?.submitButton,children:v?"Saving\u2026":`Save ${le}`})]})]})}export{me as a,U as b,W as c,$ as d,De as e,j as f,G as g,V as h,q as i,J as j,Ve as k};