@flopay/react 1.12.0 → 1.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- "use strict";var Kt=Object.create;var we=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var qt=Object.getPrototypeOf,$t=Object.prototype.hasOwnProperty;var he=(e,r)=>()=>(e&&(r=e(e=0)),r);var Te=(e,r)=>{for(var t in r)we(e,t,{get:r[t],enumerable:!0})},st=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of jt(r))!$t.call(e,s)&&s!==t&&we(e,s,{get:()=>r[s],enumerable:!(o=Xt(r,s))||o.enumerable});return e};var Zt=(e,r,t)=>(t=e!=null?Kt(qt(e)):{},st(r||!e||!e.__esModule?we(t,"default",{value:e,enumerable:!0}):t,e)),Jt=e=>st(we({},"__esModule",{value:!0}),e);var b,De=he(()=>{"use strict";b=require("@flopay/shared")});var dr,be,_e,Ve=he(()=>{"use strict";dr=require("@flopay/shared"),be=require("@flopay/shared"),_e=require("@flopay/shared")});var ht,gt=he(()=>{"use strict";ht={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"}});function vt(){return(0,k.jsx)("style",{children:pr})}function Ct(e,r){let t=e.availablePaymentMethods;return t&&r.some(o=>t[o])?"ready":"unavailable"}function Pt({state:e,placeholderTestId:r,borderRadius:t=8,children:o}){return e==="unavailable"||e==="load_error"?null:(0,k.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,k.jsx)("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"}}),(0,k.jsx)("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 bt({method:e,themeId:r,submitting:t=!1,disabled:o=!1,highlighted:s=!1,hasNextStep:i=!1,onClick:u,backgroundColor:p,borderColor:g,textColor:_,borderRadius:F,fontFamily:V}){let E=(0,ee.resolveStripeMethodBrandVariant)(e,r),T=ht[e],[R,C]=(0,St.useState)(!1),c=!!T&&!R,S=E?.backgroundColor??p??"#ffffff",L=E?.borderColor??g??"#d1d5db",I=E?.textColor??_??"#262833";return(0,k.jsx)("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!o&&u()},disabled:t||o,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:cr,padding:"0 1rem",backgroundColor:S,color:I,border:`1px solid ${L}`,borderRadius:F??8,fontSize:"0.95rem",fontWeight:600,fontFamily:V,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:s?"0 0 0 2px rgba(74, 73, 255, 0.15)":void 0},children:t?(0,k.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,ee.getStripeMethodDisplayName)(e)}\u2026`}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,ee.hasVendoredStripeMethodLogo)(e)?8:0},children:[c?(0,k.jsx)("img",{src:T,alt:"","aria-hidden":"true",onError:()=>C(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!c&&E?.logoSvg?(0,k.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:E.logoSvg}}):null,(0,k.jsx)("span",{children:(0,ee.getStripeMethodDisplayName)(e)})]}),i&&(0,k.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:I,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:(0,k.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function Et(e){let r=new Set(e.map(ee.stripeExpressMethodToOptionKey)),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"]))}function kt({testId:e,attributes:r,disabled:t,onClick:o,color:s,borderRadius:i,style:u,children:p}){return(0,k.jsx)("button",{type:"button","data-testid":e,...r,onClick:o,disabled:t,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:s,color:"white",border:"none",borderRadius:i,fontSize:"1rem",fontWeight:600,cursor:t?"not-allowed":"pointer",opacity:t?.5:1,transition:"opacity 120ms ease-out",...u??{}},children:p})}var ee,St,k,pr,cr,Rt,wt,Mt=he(()=>{"use strict";ee=require("@flopay/shared"),St=require("react");gt();k=require("react/jsx-runtime"),pr=`
1
+ "use strict";var jt=Object.create;var Re=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var Jt=Object.getPrototypeOf,Qt=Object.prototype.hasOwnProperty;var fe=(e,r)=>()=>(e&&(r=e(e=0)),r);var Ae=(e,r)=>{for(var t in r)Re(e,t,{get:r[t],enumerable:!0})},ut=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Zt(r))!Qt.call(e,s)&&s!==t&&Re(e,s,{get:()=>r[s],enumerable:!(o=$t(r,s))||o.enumerable});return e};var er=(e,r,t)=>(t=e!=null?jt(Jt(e)):{},ut(r||!e||!e.__esModule?Re(t,"default",{value:e,enumerable:!0}):t,e)),tr=e=>ut(Re({},"__esModule",{value:!0}),e);var P,De=fe(()=>{"use strict";P=require("@flopay/shared")});var mr,Pe,xe,Ve=fe(()=>{"use strict";mr=require("@flopay/shared"),Pe=require("@flopay/shared"),xe=require("@flopay/shared")});var vt,Ct=fe(()=>{"use strict";vt={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"}});function bt(){return(0,M.jsx)("style",{children:yr})}function Et(e,r){let t=e.availablePaymentMethods;return t&&r.some(o=>t[o])?"ready":"unavailable"}function wt({state:e,placeholderTestId:r,borderRadius:t=8,children:o}){return e==="unavailable"||e==="load_error"?null:(0,M.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,M.jsx)("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"}}),(0,M.jsx)("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 Rt({method:e,themeId:r,submitting:t=!1,disabled:o=!1,highlighted:s=!1,hasNextStep:i=!1,onClick:d,backgroundColor:p,borderColor:f,textColor:F,borderRadius:B,fontFamily:W}){let b=(0,J.resolveStripeMethodBrandVariant)(e,r),T=vt[e],[E,w]=(0,Pt.useState)(!1),y=!!T&&!E,g=b?.backgroundColor??p??"#ffffff",R=b?.borderColor??f??"#d1d5db",I=b?.textColor??F??"#262833";return(0,M.jsx)("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!o&&d()},disabled:t||o,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:fr,padding:"0 1rem",backgroundColor:g,color:I,border:`1px solid ${R}`,borderRadius:B??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:s?"0 0 0 2px rgba(74, 73, 255, 0.15)":void 0},children:t?(0,M.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,J.getStripeMethodDisplayName)(e)}\u2026`}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,J.hasVendoredStripeMethodLogo)(e)?8:0},children:[y?(0,M.jsx)("img",{src:T,alt:"","aria-hidden":"true",onError:()=>w(!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&&b?.logoSvg?(0,M.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:b.logoSvg}}):null,(0,M.jsx)("span",{children:(0,J.getStripeMethodDisplayName)(e)})]}),i&&(0,M.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:I,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:(0,M.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function kt(e){let r=new Set(e.map(J.stripeExpressMethodToOptionKey)),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"]))}function xt({testId:e,attributes:r,disabled:t,onClick:o,color:s,borderRadius:i,style:d,children:p}){return(0,M.jsx)("button",{type:"button","data-testid":e,...r,onClick:o,disabled:t,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:s,color:"white",border:"none",borderRadius:i,fontSize:"1rem",fontWeight:600,cursor:t?"not-allowed":"pointer",opacity:t?.5:1,transition:"opacity 120ms ease-out",...d??{}},children:p})}var J,Pt,M,yr,fr,Mt,_t,Ft=fe(()=>{"use strict";J=require("@flopay/shared"),Pt=require("react");Ct();M=require("react/jsx-runtime"),yr=`
2
2
  .paypal-buttons { margin: 0 !important; vertical-align: top !important; }
3
3
  @keyframes flopay-spin { to { transform: rotate(360deg); } }
4
4
  @keyframes flopay-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
@@ -19,9 +19,9 @@
19
19
  0% { opacity: 1; transform: translateX(0) scale(1); }
20
20
  100% { opacity: 0; transform: translateX(16px) scale(0.97); }
21
21
  }
22
- `,cr=44;Rt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},wt={type:"accordion",defaultCollapsed:!1,radios:"never"}});var At={};Te(At,{StripeSetupMethod:()=>Sr});function mr(e){let r=Ne.get(e);if(r)return r;let t=(0,Ft.loadStripe)(e).catch(o=>{throw Ne.delete(e),o});return Ne.set(e,t),t}function yr(e){return e?(0,re.toStripeAppearance)(e):void 0}function fr(e){return(0,b.isProviderDecline)(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function xt(e){return e==="paypal"?"PayPal":(0,re.getStripeMethodDisplayName)(e)}function hr(){return typeof window>"u"?"":window.location.href}function Sr(e){let{publishableKey:r,method:t,currency:o,futureUse:s,futureUseUnsupported:i,appearance:u}=e,[p]=(0,D.useState)(()=>mr(r)),g=(0,D.useMemo)(()=>{let _=yr(u),F=(0,re.resolveSetupFutureUsage)({futureUse:s,futureUseUnsupported:i},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:Tt[t]?.types??[t],...F?{setupFutureUsage:F}:{},..._?{appearance:_}:{}}},[u,o,s,i,t]);return(0,O.jsx)(Q.Elements,{stripe:p,options:g,children:(0,O.jsx)(vr,{...e})})}function vr({method:e,category:r,sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,appearance:u,themeId:p,buttonsLayout:g,onSubmitting:_,onConfirmed:F,onDeclined:V,onFailed:E,onValidation:T,onUnavailable:R}){let C=(0,Q.useStripe)(),c=(0,Q.useElements)(),[S,L]=(0,D.useState)(!1),[I,y]=(0,D.useState)("loading"),[X,N]=(0,D.useState)(!1),[P,H]=(0,D.useState)(!1),j=(0,D.useRef)(!1),[G]=(0,D.useState)(()=>(0,be.detectPayPalEnvironment)()),[M,ne]=(0,D.useState)(!1),Y=(0,D.useCallback)((x,W)=>{if((0,b.classifyExternalMethodFailure)(x,{inAppBrowser:G.inAppBrowser,handoffObserved:!1}).popupBlocked){ne(!0),E(new Error((0,b.buildExternalMethodRecoveryMessage)(xt(e),!0,G.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}E(W.message===void 0?x:new Error(W.message),{code:W.code,retryable:!0})},[G.inAppBrowser,e,E]),Z=(0,D.useCallback)(async()=>{if(!(!C||!c||j.current)){j.current=!0,L(!0);try{let x=await c.submit();if(x.error){T(x.error.message??null);return}_();let W=await new _t.PaymentAPI(s,{telemetry:i}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(W.provider!=="stripe"||W.intentKind!=="setup")throw new re.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let A=await C.confirmSetup({elements:c,clientSecret:W.clientSecret,confirmParams:{return_url:hr()},redirect:"if_required"});if(A.error){fr(A.error)?V({...A.error.decline_code||A.error.code?{reason:A.error.decline_code??A.error.code}:{},...A.error.message?{message:A.error.message}:{}}):Y(A.error,{code:"payment_method_setup_provider_failed",message:A.error.message??"The payment method could not be saved."});return}F()}catch(x){Y(x,{code:"payment_method_setup_failed"})}finally{j.current=!1,L(!1)}}},[s,r,c,e,o,F,V,_,T,Y,t,C,i]),ae=Tt[e]?.wallet,q=ae==="paypal"&&(0,_e.resolveStripePayPalPresentation)(G,"auto",M?"blocked":G.popupCapability)==="redirect",ce=u?.variables?.borderRadius??g?.cardButton?.borderRadius??8;if(r==="wallet"&&ae&&!q)return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(vt,{}),(0,O.jsx)(Pt,{state:I,borderRadius:ce,children:(0,O.jsx)(Q.ExpressCheckoutElement,{options:{...Rt,paymentMethods:Et([e])},onReady:x=>{let W=Ct(x,[ae]);y(W),W==="unavailable"&&R()},onLoadError:()=>{y("load_error"),R()},onConfirm:()=>{Z()}})})]});let se=xt(e);return(0,O.jsxs)(O.Fragment,{children:[X?(0,O.jsx)(bt,{method:e,themeId:p,hasNextStep:!0,highlighted:P,disabled:S,onClick:()=>H(x=>!x),backgroundColor:g?.cardButton?.backgroundColor,borderColor:g?.cardInputBorder,textColor:g?.cardButton?.color,borderRadius:ce}):null,(0,O.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!P,style:P?{display:"flex",flexDirection:"column"}:gr,children:[(0,O.jsx)(Q.PaymentElement,{options:{layout:wt},onReady:()=>N(!0),onLoadError:()=>R(),onChange:x=>{x.complete&&T(null)}}),(0,O.jsx)(kt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!C||!c||S||!P,onClick:()=>{Z()},color:u?.variables?.colorPrimary??"#4A49FF",borderRadius:u?.variables?.borderRadius??"8px",style:g?.submitButton,children:S?"Saving\u2026":`Save ${se}`})]})]})}var _t,re,Q,Ft,D,O,Tt,Ne,gr,Ot=he(()=>{"use strict";_t=require("@flopay/js/card-setup"),re=require("@flopay/shared"),Q=require("@stripe/react-stripe-js"),Ft=require("@stripe/stripe-js"),D=require("react");De();Ve();Mt();O=require("react/jsx-runtime"),Tt={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"}},Ne=new Map;gr={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var Bt={};Te(Bt,{PayPalSetupMethod:()=>Cr});function Cr({clientId:e,environment:r,currency:t,sessionId:o,nonce:s,billingApiUrl:i,telemetry:u,customer:{userId:p,email:g},onSubmitting:_,onConfirmed:F,onFailed:V,onAbandoned:E}){let T=(0,pe.useRef)(null),R=(0,pe.useRef)({onSubmitting:_,onConfirmed:F,onFailed:V,onAbandoned:E});R.current={onSubmitting:_,onConfirmed:F,onFailed:V,onAbandoned:E};let[C]=(0,pe.useState)(()=>(0,be.detectPayPalEnvironment)().inAppBrowser);return(0,pe.useEffect)(()=>{let c=!0,S,L=new Lt.PaymentAPI(i,{telemetry:u}),I={userId:p,email:g};return(async()=>{try{let y=await(0,It.loadScript)({clientId:e,...t?{currency:t.toUpperCase()}:{},components:"buttons",...r==="sandbox"||r==="production"?{environment:r}:{}}),X=T.current;if(!c||!X)return;if(!y?.Buttons)throw new oe.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=y.Buttons({createVaultSetupToken:async()=>{R.current.onSubmitting();let P=await L.createSessionIntent(o,s,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:oe.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(P.provider!=="paypal"||P.providerObjectType!=="setup_token")throw new oe.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return P.providerObjectId},onApprove:async P=>{let H=P.vaultSetupToken;if(!H)throw new oe.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let j=await L.processPayment(I.userId,{sessionId:o,nonce:s,paymentMethodCategory:"paypal",tokenizedData:{id:H,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:oe.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:I});if(!j.ok)throw new oe.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:j.status});c&&R.current.onConfirmed()},onCancel:()=>{c&&R.current.onAbandoned()},onError:P=>{if(!c)return;let{popupBlocked:H}=(0,b.classifyExternalMethodFailure)(P,{inAppBrowser:C,handoffObserved:!1});R.current.onFailed(H?new Error((0,b.buildExternalMethodRecoveryMessage)("PayPal",!0,C)):P,{code:H?"popup_blocked":"paypal_setup_failed",retryable:!0})}});S=()=>N.close(),await N.render(X)}catch(y){if(!c)return;R.current.onFailed(y,{code:"paypal_unavailable",retryable:!0})}})(),()=>{c=!1,S?.().catch(()=>{}),L.destroy()}},[i,e,t,g,r,C,s,o,u,p]),(0,Ut.jsx)("div",{ref:T,"data-flopay-paypal-setup":""})}var Lt,oe,It,pe,Ut,Dt=he(()=>{"use strict";Lt=require("@flopay/js/card-setup"),oe=require("@flopay/shared"),It=require("@paypal/paypal-js"),pe=require("react");De();Ve();Ut=require("react/jsx-runtime")});var br={};Te(br,{FloPayCardSetupError:()=>Ce,FloPayPaymentMethodSetup:()=>Vt});module.exports=Jt(br);var mt=require("@flopay/js/card-setup"),ue=require("@flopay/shared"),Me=require("react");var Ae=require("@flopay/shared"),Qt=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 er(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Qt.has(r.charAt(0).toLowerCase()+r.slice(1))}function tr(e,r){return typeof r=="number"&&r!==0&&!er(e)?`${r}px`:String(r).trim()}function it(e,r){if(e.style.cssText="",!!r){for(let[t,o]of Object.entries(r))if(!(o==null||o==="")){if(t.startsWith("--")){e.style.setProperty(t,String(o));continue}e.style[t]=tr(t,o)}}}var Oe=require("@flopay/shared"),rr=require("@flopay/shared");function lt(e){return(0,Oe.computeCardSetupOverlayTheme)(e)}var J=require("@flopay/shared");var v=require("react/jsx-runtime");var or={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ut({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:s,errorLabel:i="PAYMENT FAILED",successNote:u="You will be automatically redirected, do not close or navigate away from this window.",theme:p=or}){let g={fontSize:13,color:p.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,v.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,v.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...p.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,v.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:p.spinnerTrackColor,strokeWidth:"3"}),(0,v.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:p.spinnerAccentColor})]}),e==="success"&&(0,v.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,v.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,v.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,v.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,v.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:p.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(s??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&u!==null&&(0,v.jsx)("p",{style:g,children:u}),e==="error"&&r&&(0,v.jsx)("p",{style:g,children:r}),(0,v.jsx)("style",{children:`
22
+ `,fr=44;Mt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},_t={type:"accordion",defaultCollapsed:!1,radios:"never"}});var Bt={};Ae(Bt,{StripeSetupMethod:()=>Pr});function hr(e){let r=Ne.get(e);if(r)return r;let t=(0,Ot.loadStripe)(e).catch(o=>{throw Ne.delete(e),o});return Ne.set(e,t),t}function gr(e){return e?(0,te.toStripeAppearance)(e):void 0}function Sr(e){return(0,P.isProviderDecline)(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Tt(e){return e==="paypal"?"PayPal":(0,te.getStripeMethodDisplayName)(e)}function vr(){return typeof window>"u"?"":window.location.href}function Pr(e){let{publishableKey:r,method:t,currency:o,futureUse:s,futureUseUnsupported:i,appearance:d}=e,[p]=(0,Y.useState)(()=>hr(r)),f=(0,Y.useMemo)(()=>{let F=gr(d),B=(0,te.resolveSetupFutureUsage)({futureUse:s,futureUseUnsupported:i},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:Lt[t]?.types??[t],...B?{setupFutureUsage:B}:{},...F?{appearance:F}:{}}},[d,o,s,i,t]);return(0,L.jsx)($.Elements,{stripe:p,options:f,children:(0,L.jsx)(br,{...e})})}function br({method:e,category:r,sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,appearance:d,themeId:p,buttonsLayout:f,onSubmitting:F,onConfirmed:B,onDeclined:W,onFailed:b,onValidation:T,onUnavailable:E}){let w=(0,$.useStripe)(),y=(0,$.useElements)(),[g,R]=(0,Y.useState)(!1),[I,U]=(0,Y.useState)("loading"),[H,_]=(0,Y.useState)(!1),[v,A]=(0,Y.useState)(!1),G=(0,Y.useRef)(!1),[q]=(0,Y.useState)(()=>(0,Pe.detectPayPalEnvironment)()),[oe,Q]=(0,Y.useState)(!1),m=(0,Y.useCallback)((x,O)=>{if((0,P.classifyExternalMethodFailure)(x,{inAppBrowser:q.inAppBrowser,handoffObserved:!1}).popupBlocked){Q(!0),b(new Error((0,P.buildExternalMethodRecoveryMessage)(Tt(e),!0,q.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}b(O.message===void 0?x:new Error(O.message),{code:O.code,retryable:!0})},[q.inAppBrowser,e,b]),de=(0,Y.useCallback)(async()=>{if(!(!w||!y||G.current)){G.current=!0,R(!0);try{let x=await y.submit();if(x.error){T(x.error.message??null);return}F();let O=await new At.PaymentAPI(s,{telemetry:i}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(O.provider!=="stripe"||O.intentKind!=="setup")throw new te.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let D=await w.confirmSetup({elements:y,clientSecret:O.clientSecret,confirmParams:{return_url:vr()},redirect:"if_required"});if(D.error){Sr(D.error)?W({...D.error.decline_code||D.error.code?{reason:D.error.decline_code??D.error.code}:{},...D.error.message?{message:D.error.message}:{}}):m(D.error,{code:"payment_method_setup_provider_failed",message:D.error.message??"The payment method could not be saved."});return}B()}catch(x){m(x,{code:"payment_method_setup_failed"})}finally{G.current=!1,R(!1)}}},[s,r,y,e,o,B,W,F,T,m,t,w,i]),ne=Lt[e]?.wallet,Z=ne==="paypal"&&(0,xe.resolveStripePayPalPresentation)(q,"auto",oe?"blocked":q.popupCapability)==="redirect",pe=d?.variables?.borderRadius??f?.cardButton?.borderRadius??8;if(r==="wallet"&&ne&&!Z)return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(bt,{}),(0,L.jsx)(wt,{state:I,borderRadius:pe,children:(0,L.jsx)($.ExpressCheckoutElement,{options:{...Mt,paymentMethods:kt([e])},onReady:x=>{let O=Et(x,[ne]);U(O),O==="unavailable"&&E()},onLoadError:()=>{U("load_error"),E()},onConfirm:()=>{de()}})})]});let K=Tt(e);return(0,L.jsxs)(L.Fragment,{children:[H?(0,L.jsx)(Rt,{method:e,themeId:p,hasNextStep:!0,highlighted:v,disabled:g,onClick:()=>A(x=>!x),backgroundColor:f?.cardButton?.backgroundColor,borderColor:f?.cardInputBorder,textColor:f?.cardButton?.color,borderRadius:pe}):null,(0,L.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!v,style:v?{display:"flex",flexDirection:"column"}:Cr,children:[(0,L.jsx)($.PaymentElement,{options:{layout:_t},onReady:()=>_(!0),onLoadError:()=>E(),onChange:x=>{x.complete&&T(null)}}),(0,L.jsx)(xt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!w||!y||g||!v,onClick:()=>{de()},color:d?.variables?.colorPrimary??"#4A49FF",borderRadius:d?.variables?.borderRadius??"8px",style:f?.submitButton,children:g?"Saving\u2026":`Save ${K}`})]})]})}var At,te,$,Ot,Y,L,Lt,Ne,Cr,It=fe(()=>{"use strict";At=require("@flopay/js/card-setup"),te=require("@flopay/shared"),$=require("@stripe/react-stripe-js"),Ot=require("@stripe/stripe-js"),Y=require("react");De();Ve();Ft();L=require("react/jsx-runtime"),Lt={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"}},Ne=new Map;Cr={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var Vt={};Ae(Vt,{PayPalSetupMethod:()=>Er});function Er({clientId:e,environment:r,currency:t,sessionId:o,nonce:s,billingApiUrl:i,telemetry:d,customer:{userId:p,email:f},onSubmitting:F,onConfirmed:B,onFailed:W,onAbandoned:b}){let T=(0,ue.useRef)(null),E=(0,ue.useRef)({onSubmitting:F,onConfirmed:B,onFailed:W,onAbandoned:b});E.current={onSubmitting:F,onConfirmed:B,onFailed:W,onAbandoned:b};let[w]=(0,ue.useState)(()=>(0,Pe.detectPayPalEnvironment)().inAppBrowser);return(0,ue.useEffect)(()=>{let y=!0,g,R=new Ut.PaymentAPI(i,{telemetry:d}),I={userId:p,email:f};return(async()=>{try{let U=await(0,Dt.loadScript)({clientId:e,...t?{currency:t.toUpperCase()}:{},components:"buttons",...r==="sandbox"||r==="production"?{environment:r}:{}}),H=T.current;if(!y||!H)return;if(!U?.Buttons)throw new re.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let _=U.Buttons({createVaultSetupToken:async()=>{E.current.onSubmitting();let v=await R.createSessionIntent(o,s,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:re.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(v.provider!=="paypal"||v.providerObjectType!=="setup_token")throw new re.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return v.providerObjectId},onApprove:async v=>{let A=v.vaultSetupToken;if(!A)throw new re.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let G=await R.processPayment(I.userId,{sessionId:o,nonce:s,paymentMethodCategory:"paypal",tokenizedData:{id:A,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:re.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:I});if(!G.ok)throw new re.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:G.status});y&&E.current.onConfirmed()},onCancel:()=>{y&&E.current.onAbandoned()},onError:v=>{if(!y)return;let{popupBlocked:A}=(0,P.classifyExternalMethodFailure)(v,{inAppBrowser:w,handoffObserved:!1});E.current.onFailed(A?new Error((0,P.buildExternalMethodRecoveryMessage)("PayPal",!0,w)):v,{code:A?"popup_blocked":"paypal_setup_failed",retryable:!0})}});g=()=>_.close(),await _.render(H)}catch(U){if(!y)return;E.current.onFailed(U,{code:"paypal_unavailable",retryable:!0})}})(),()=>{y=!1,g?.().catch(()=>{}),R.destroy()}},[i,e,t,f,r,w,s,o,d,p]),(0,Nt.jsx)("div",{ref:T,"data-flopay-paypal-setup":""})}var Ut,re,Dt,ue,Nt,Yt=fe(()=>{"use strict";Ut=require("@flopay/js/card-setup"),re=require("@flopay/shared"),Dt=require("@paypal/paypal-js"),ue=require("react");De();Ve();Nt=require("react/jsx-runtime")});var Rr={};Ae(Rr,{FloPayCardSetupError:()=>ve,FloPayPaymentMethodSetup:()=>Wt});module.exports=tr(Rr);var ht=require("@flopay/js/card-setup"),ie=require("@flopay/shared"),Me=require("react");var Oe=require("@flopay/shared"),rr=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 or(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return rr.has(r.charAt(0).toLowerCase()+r.slice(1))}function nr(e,r){return typeof r=="number"&&r!==0&&!or(e)?`${r}px`:String(r).trim()}function dt(e,r){if(e.style.cssText="",!!r){for(let[t,o]of Object.entries(r))if(!(o==null||o==="")){if(t.startsWith("--")){e.style.setProperty(t,String(o));continue}e.style[t]=nr(t,o)}}}var Le=require("@flopay/shared"),ar=require("@flopay/shared");function pt(e){let r=(0,Le.resolveCardSetupTheme)(e);return{...r,surface:r.surface,overlayTheme:r.overlayTheme}}var j=require("@flopay/shared");var S=require("react/jsx-runtime");var sr={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ct({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:s,errorLabel:i="PAYMENT FAILED",successNote:d="You will be automatically redirected, do not close or navigate away from this window.",theme:p=sr}){let f={fontSize:13,color:p.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,S.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,S.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...p.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,S.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,S.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,S.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:p.spinnerTrackColor,strokeWidth:"3"}),(0,S.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:p.spinnerAccentColor})]}),e==="success"&&(0,S.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,S.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,S.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,S.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,S.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,S.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,S.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,S.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,S.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:p.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(s??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&d!==null&&(0,S.jsx)("p",{style:f,children:d}),e==="error"&&r&&(0,S.jsx)("p",{style:f,children:r}),(0,S.jsx)("style",{children:`
23
23
  @keyframes flopay-spin { to { transform: rotate(360deg); } }
24
24
  @keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
25
25
  @keyframes flopay-draw { to { stroke-dashoffset: 0; } }
26
26
  @keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
27
- `})]})})}var z=require("react");var ke=require("react"),dt=typeof window>"u"?ke.useEffect:ke.useLayoutEffect;var le=require("react/jsx-runtime"),Le=new WeakSet;function pt({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:s,theme:i,submitLabel:u,containerStyle:p,onReady:g,onError:_,onValidation:F}){let V=(0,z.useRef)(null),E=(0,z.useRef)(g),T=(0,z.useRef)(_),R=(0,z.useRef)(F);E.current=g,T.current=_,R.current=F;let C=(0,z.useRef)(i);C.current=i;let c=(0,z.useRef)(null),S=u??void 0,L=(0,z.useRef)(S);L.current=S;let I=(0,z.useRef)(void 0);return(0,z.useEffect)(()=>{let y=V.current;if(!y)return;let X=!0,N=!1,P=()=>{!X||N||(N=!0,E.current?.())},H=e.on("ready",()=>{P()}),j=e.on("error",Y=>{T.current?.(Y.message??"There was a problem loading the secure card form.")}),G=e.on("validation",Y=>{R.current?.(Y.message??null)}),M=L.current??(Le.has(e)?null:void 0),ne={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...C.current?{theme:C.current}:{},...M===void 0?{}:{submitLabel:M}};return c.current=C.current??null,I.current=L.current,L.current!==void 0&&Le.add(e),e.mount(y,ne).then(()=>{P()}).catch(Y=>{X&&T.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{X=!1,H(),j(),G(),e.unmount()}},[e,r,t,o,s]),dt(()=>{let y=V.current;y&&it(y,p)},[p]),(0,z.useEffect)(()=>{i!==void 0&&(i===null&&c.current===null||(c.current=i,e.applyTheme?.(i)))},[e,i]),(0,z.useEffect)(()=>{S!==I.current&&(I.current=S,S!==void 0&&Le.add(e),e.setSubmitLabel?.(S??null))},[e,S]),(0,le.jsx)("div",{ref:V,"data-testid":"flopay-vault-card-fields"})}function ct({label:e}){return(0,le.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,le.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,le.jsx)("span",{children:e}),(0,le.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var Ie=require("react/jsx-runtime"),Ce=class extends ue.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function de(e,r={}){let t=e instanceof ue.FloPayError?e:void 0,o=t?.statusCode,s=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof o=="number"&&o>=500||t?.code==="vault_capture_timeout"||!t);return new Ce(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:s,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}var Ye=require("react");var Pe=require("@flopay/js/card-setup"),h=require("@flopay/shared"),a=Zt(require("react"),1);var ge=require("@flopay/js/card-setup"),w=require("@flopay/shared");var Be=require("@flopay/shared");var f=require("react/jsx-runtime"),ar=15,sr=2e3;function ir(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(r=>setTimeout(r,e))}async function lr(e,r,t){if(!r.trim())throw new h.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!t.trim())throw new h.FloPayError("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let o=await e.getUnifiedCheckoutSession(r,t),s=o.data.session;if(!s||!(0,h.isCardSetupCheckoutSession)(s))throw new h.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let i=(0,w.readSetupAdvertisement)(o);if(!(0,w.advertisesAnyMethod)(i)){let{skippedForMissingCurrency:u}=i,p=u.length>0?`FloPay: this setup session advertises only Stripe methods (${u.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 h.FloPayError(p,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:s,advertisement:i}}async function ur(e,r,t,o,s){let i=r.vault??null;(0,h.isMountableVaultBlock)(i)||(i=await e.getVaultCapture(t,o));let u=(0,h.resolveVaultMountOptions)(i,{billingApiUrl:s,sessionId:t,nonce:o});if(!u)throw new h.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return u}var xe=class extends a.default.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(t){this.props.onFailed(t,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function ft({branches:{StripeSetupMethod:e,PayPalSetupMethod:r},sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,theme:u="modern-light",containerStyle:p,loading:g=null,onReady:_,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:R}){let[C]=(0,a.useState)(ge.readSetupRedirectReturn),[c,S]=(0,a.useState)(null),[L,I]=(0,a.useState)(!1),[y,X]=(0,a.useState)(null),[N,P]=(0,a.useState)(null),[H,j]=(0,a.useState)(null),[G,M]=(0,a.useState)(null),[ne,Y]=(0,a.useState)(()=>new Set),Z=(0,a.useRef)(ne),ae=(0,a.useRef)(null);ae.current=c;let q=(0,a.useRef)(!1),ce=(0,a.useRef)(!1),se=(0,a.useRef)(!1),x=(0,a.useRef)(!1),W=(0,a.useRef)(0),A=(0,a.useRef)(0),me=(0,a.useRef)(!1),K=(0,a.useMemo)(()=>typeof u=="object"?void 0:(0,h.resolveTheme)(u),[u]),Yt=(0,a.useMemo)(()=>typeof u=="object"?u:K?(0,Be.computeVaultCardThemeColors)({appearance:K.appearance,buttonsStyles:K.buttonsLayout,layout:"default"}):null,[K,u]),Wt=(0,a.useMemo)(()=>(0,Ae.mergeCardSetupSurface)(K?.buttonsLayout.cardFormContainer,p),[K,p]),We=(0,a.useMemo)(()=>K?lt(K):void 0,[K]),B=(0,a.useRef)({sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:_,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:R});B.current={sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:_,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:R},(0,a.useEffect)(()=>{me.current=!0;let n=W.current+1;return W.current=n,()=>{me.current=!1,A.current+=1,queueMicrotask(()=>{W.current===n&&(se.current||x.current||(x.current=!0,(0,J.invokeMerchantCallback)(()=>{B.current.onCancel?.({status:"cancelled",sessionId:t})})))})}},[t]);let ye=(0,a.useCallback)((n,l)=>{se.current=!0,q.current=!1,M({status:"success",wording:n,message:null}),(async()=>(await Ue(600),!ce.current&&(ce.current=!0,(0,J.invokeMerchantCallback)(()=>{B.current.onComplete?.({status:"succeeded",sessionId:B.current.sessionId,...l?{paymentMethod:l}:{}})}),me.current&&M(null))))()},[]),fe=(0,a.useCallback)((n,l)=>{se.current=!0,q.current=!1,M({status:"error",wording:n,message:l.message??null}),(0,J.invokeMerchantCallback)(()=>{B.current.onDecline?.({status:"declined",sessionId:B.current.sessionId,...l.reason?{reason:l.reason}:{},...l.message?{message:l.message}:{}})}),(async()=>(await Ue(400),me.current&&M(null)))()},[]),te=(0,a.useCallback)((n,l)=>{q.current?(q.current=!1,M({status:"error",wording:n,message:l.message}),setTimeout(()=>{me.current&&M(null)},400)):M(null),(0,J.invokeMerchantCallback)(()=>B.current.onError?.(l))},[]),Ee=(0,a.useCallback)(async n=>{let l=A.current+1;A.current=l;let m=()=>!me.current||l!==A.current;q.current=!0,M({status:"processing",wording:"payment_method",message:null});let U=new Pe.PaymentAPI((0,h.resolveBillingApiUrl)(B.current.billingApiUrl),{telemetry:B.current.telemetry});try{for(let d=0;d<ar;d+=1){if((d>0||n.waitFirst)&&await Ue(sr),m())return;let $=await U.getUnifiedCheckoutSession(B.current.sessionId,B.current.nonce);if(m())return;let ie=$.data.session?.status;if(ie==="complete"){I(!0),ye("payment_method");return}if(ie==="expired")throw new h.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new h.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(d){if(m())return;let $=d instanceof h.FloPayError&&d.code==="payment_method_setup_unverified";te("payment_method",de(d,$?{retryable:!0}:{}))}finally{U.destroy()}},[te,ye]);(0,a.useEffect)(()=>{let n=!0,l=(0,h.resolveBillingApiUrl)(s),m=new Pe.PaymentAPI(l,{telemetry:i});S(null),I(!1),X(null),P(null),j(null);let U=new Set;return Z.current=U,Y(U),se.current=!1,x.current=!1,ce.current=!1,(async()=>{try{let{session:d,advertisement:$}=await lr(m,t,o);if(!n)return;let ie={advertisement:$,customer:ir(d),...d.futureUse?{futureUse:d.futureUse}:{},...d.futureUseUnsupported?{futureUseUnsupported:d.futureUseUnsupported}:{}};if(C){if((0,ge.clearSetupRedirectParams)(),d.status==="complete"){I(!0),S(ie),ye("payment_method");return}C.failed?fe("payment_method",{reason:"redirect_failed"}):Ee({waitFirst:!0})}let at=$.card?await ur(m,d,t,o,l):null;if(!n)return;S(ie),at&&(P(at),X(new Pe.PciVaultCardCapture({sessionId:t,operation:"card_setup",telemetry:i})))}catch(d){if(!n)return;let $=de(d);se.current=!0,j($),(0,J.invokeMerchantCallback)(()=>B.current.onError?.($))}})(),()=>{n=!1,m.destroy()}},[s,o,C,fe,ye,t,i,Ee]),(0,a.useEffect)(()=>{if(!y)return;q.current=!1;let n=y.on("submitting",()=>{q.current=!0,M({status:"processing",wording:"card",message:null})}),l=y.on("complete",d=>{ye("card",d.paymentMethod)}),m=y.on("decline",d=>{fe("card",{...d.declineReason?{reason:d.declineReason}:{},...d.message?{message:d.message}:{}})}),U=y.on("challenge_dismissed",()=>{M(null)});return()=>{n(),l(),m(),U()}},[y,fe,ye]);let ze=(0,a.useCallback)((n,l,m)=>{if(m.retryable){te("payment_method",de(l,m));return}if(Z.current.has(n))return;let U=new Set(Z.current);U.add(n),Z.current=U,Y(U);let d=ae.current?.advertisement,$=d?(0,w.advertisedMethodKeys)(d).some(ie=>!U.has(ie)):!1;te("payment_method",de(l,{code:m.code,retryable:$}))},[te]),He=(0,a.useMemo)(()=>({onSubmitting:()=>{q.current=!0,M({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{Ee({waitFirst:!1})},onDeclined:n=>fe("payment_method",n),onValidation:n=>{(0,J.invokeMerchantCallback)(()=>B.current.onValidation?.(n))},onAbandoned:()=>{q.current=!1,M(null)}}),[fe,Ee]),Ge=(0,a.useRef)(ze);Ge.current=ze;let Ke=(0,a.useRef)(new Map),Re=n=>{let l=Ke.current.get(n);if(l)return l;let m=(U,d)=>Ge.current(n,U,d);return Ke.current.set(n,m),m},Xe=(0,a.useCallback)(n=>{if(Z.current.has(n))return;let l=new Set(Z.current);l.add(n),Z.current=l,Y(l);let m=ae.current?.advertisement;m&&(0,w.advertisedMethodKeys)(m).some(d=>!l.has(d))||te("payment_method",de(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[te]),je=(0,a.useRef)(Xe);je.current=Xe;let qe=(0,a.useRef)(new Map),$e=n=>{let l=qe.current.get(n);if(l)return l;let m=()=>je.current(n);return qe.current.set(n,m),m},Ze=G?(0,f.jsx)(ut,{status:G.status,errorMessage:G.message,...(0,w.setupOverlayLabels)(G.wording),successNote:null,...We?{theme:We}:{}}):null;if(H)return(0,f.jsx)("div",{role:"alert",children:H.message});if(!c||L)return(0,f.jsxs)(f.Fragment,{children:[Ze,c?null:g]});let{advertisement:Se,customer:zt,futureUse:Je,futureUseUnsupported:Qe}=c,et=(0,h.resolveBillingApiUrl)(s),tt=i===void 0?{}:{telemetry:i},Fe=Se.stripe.filter(({method:n})=>!ne.has(n)),ve=ne.has("paypal")?null:Se.paypal,rt=!!(Se.card&&y&&N?.html),ot=({method:n,publishableKey:l,currency:m})=>(0,f.jsx)("div",{"data-flopay-payment-method":n,style:{display:"contents"},children:(0,f.jsx)(xe,{onFailed:Re(n),children:(0,f.jsx)(a.Suspense,{fallback:null,children:(0,f.jsx)(e,{method:n,category:(0,w.stripeMethodCategory)(n),publishableKey:l,currency:m,...Je?{futureUse:Je}:{},...Qe?{futureUseUnsupported:Qe}:{},sessionId:t,nonce:o,billingApiUrl:et,...tt,...K?{appearance:K.appearance,buttonsLayout:K.buttonsLayout}:{},...typeof u=="string"?{themeId:u}:{},...He,onFailed:Re(n),onUnavailable:$e(n)})})})},n),Ht=Fe.filter(({method:n})=>(0,w.stripeMethodCategory)(n)==="wallet"),Gt=Fe.filter(({method:n})=>(0,w.stripeMethodCategory)(n)!=="wallet"),nt=Fe.length>0||ve!==null;return(0,f.jsxs)(f.Fragment,{children:[Ze,nt?(0,f.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ht.map(ot),ve?(0,f.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,f.jsx)(xe,{onFailed:Re("paypal"),children:(0,f.jsx)(a.Suspense,{fallback:null,children:(0,f.jsx)(r,{clientId:ve.clientId,...ve.environment?{environment:ve.environment}:{},...Se.currency?{currency:Se.currency}:{},sessionId:t,nonce:o,billingApiUrl:et,customer:zt,...tt,...He,onFailed:Re("paypal"),onUnavailable:$e("paypal")})})})}):null,Gt.map(ot)]}):null,rt&&nt?(0,f.jsx)(ct,{label:"or add a card"}):null,rt&&y&&N?.html?(0,f.jsx)("div",{"data-flopay-payment-method":"card",children:(0,f.jsx)(pt,{capture:y,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,verificationRequired:N.verificationRequired,theme:Yt,containerStyle:Wt,onReady:()=>{(0,J.invokeMerchantCallback)(()=>B.current.onReady?.())},onValidation:n=>{(0,J.invokeMerchantCallback)(()=>B.current.onValidation?.(n))},onError:n=>{n&&te("card",de(new Error(n),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var Nt=require("react/jsx-runtime"),Pr={StripeSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(Ot(),At)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(Dt(),Bt)).then(e=>({default:e.PayPalSetupMethod})))};function Vt(e){return(0,Nt.jsx)(ft,{...e,branches:Pr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
27
+ `})]})})}var z=require("react");var ke=require("react"),mt=typeof window>"u"?ke.useEffect:ke.useLayoutEffect;var se=require("react/jsx-runtime"),Be=new WeakSet;function yt({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:s,theme:i,submitLabel:d,containerStyle:p,onReady:f,onError:F,onValidation:B}){let W=(0,z.useRef)(null),b=(0,z.useRef)(f),T=(0,z.useRef)(F),E=(0,z.useRef)(B);b.current=f,T.current=F,E.current=B;let w=(0,z.useRef)(i);w.current=i;let y=(0,z.useRef)(null),g=d??void 0,R=(0,z.useRef)(g);R.current=g;let I=(0,z.useRef)(void 0);return(0,z.useEffect)(()=>{let U=W.current;if(!U)return;let H=!0,_=!1,v=()=>{!H||_||(_=!0,b.current?.())},A=e.on("ready",()=>{v()}),G=e.on("error",m=>{T.current?.(m.message??"There was a problem loading the secure card form.")}),q=e.on("validation",m=>{E.current?.(m.message??null)}),oe=R.current??(Be.has(e)?null:void 0),Q={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...w.current?{theme:w.current}:{},...oe===void 0?{}:{submitLabel:oe}};return y.current=w.current??null,I.current=R.current,R.current!==void 0&&Be.add(e),e.mount(U,Q).then(()=>{v()}).catch(m=>{H&&T.current?.(m instanceof Error?m.message:"Failed to load the secure card form.")}),()=>{H=!1,A(),G(),q(),e.unmount()}},[e,r,t,o,s]),mt(()=>{let U=W.current;U&&dt(U,p)},[p]),(0,z.useEffect)(()=>{i!==void 0&&(i===null&&y.current===null||(y.current=i,e.applyTheme?.(i)))},[e,i]),(0,z.useEffect)(()=>{g!==I.current&&(I.current=g,g!==void 0&&Be.add(e),e.setSubmitLabel?.(g??null))},[e,g]),(0,se.jsx)("div",{ref:W,"data-testid":"flopay-vault-card-fields"})}function ft({label:e}){return(0,se.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,se.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,se.jsx)("span",{children:e}),(0,se.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var Ie=require("react/jsx-runtime"),ve=class extends ie.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function le(e,r={}){let t=e instanceof ie.FloPayError?e:void 0,o=t?.statusCode,s=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof o=="number"&&o>=500||t?.code==="vault_capture_timeout"||!t);return new ve(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:s,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}var Ye=require("react");var Ce=require("@flopay/js/card-setup"),C=require("@flopay/shared"),a=er(require("react"),1);var he=require("@flopay/js/card-setup"),k=require("@flopay/shared");var h=require("react/jsx-runtime"),lr=15,ur=2e3;function dr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(r=>setTimeout(r,e))}async function pr(e,r,t){if(!r.trim())throw new C.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!t.trim())throw new C.FloPayError("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let o=await e.getUnifiedCheckoutSession(r,t),s=o.data.session;if(!s||!(0,C.isCardSetupCheckoutSession)(s))throw new C.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let i=(0,k.readSetupAdvertisement)(o);if(!(0,k.advertisesAnyMethod)(i)){let{skippedForMissingCurrency:d}=i,p=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 C.FloPayError(p,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:s,advertisement:i}}async function cr(e,r,t,o,s){let i=r.vault??null;(0,C.isMountableVaultBlock)(i)||(i=await e.getVaultCapture(t,o));let d=(0,C.resolveVaultMountOptions)(i,{billingApiUrl:s,sessionId:t,nonce:o});if(!d)throw new C.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return d}var _e=class extends a.default.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(t){this.props.onFailed(t,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function St({branches:{StripeSetupMethod:e,PayPalSetupMethod:r},sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,theme:d="modern-light",containerStyle:p,appearance:f,buttonsStyles:F,loading:B=null,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:w,onError:y}){let[g]=(0,a.useState)(he.readSetupRedirectReturn),[R,I]=(0,a.useState)(null),[U,H]=(0,a.useState)(!1),[_,v]=(0,a.useState)(null),[A,G]=(0,a.useState)(null),[q,oe]=(0,a.useState)(null),[Q,m]=(0,a.useState)(null),[de,ne]=(0,a.useState)(()=>new Set),Z=(0,a.useRef)(de),pe=(0,a.useRef)(null);pe.current=R;let K=(0,a.useRef)(!1),x=(0,a.useRef)(!1),O=(0,a.useRef)(!1),D=(0,a.useRef)(!1),Fe=(0,a.useRef)(0),be=(0,a.useRef)(0),ce=(0,a.useRef)(!1),{vaultTheme:Ht,surface:We,overlayTheme:ze,appearance:He,buttonsLayout:Ge}=(0,a.useMemo)(()=>pt({theme:d,appearance:f,buttonsStyles:F}),[d,f,F]),Gt=(0,a.useMemo)(()=>(0,Oe.mergeCardSetupSurface)(We,p),[We,p]),V=(0,a.useRef)({sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:w,onError:y});V.current={sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:w,onError:y},(0,a.useEffect)(()=>{ce.current=!0;let n=Fe.current+1;return Fe.current=n,()=>{ce.current=!1,be.current+=1,queueMicrotask(()=>{Fe.current===n&&(O.current||D.current||(D.current=!0,(0,j.invokeMerchantCallback)(()=>{V.current.onCancel?.({status:"cancelled",sessionId:t})})))})}},[t]);let me=(0,a.useCallback)((n,l)=>{O.current=!0,K.current=!1,m({status:"success",wording:n,message:null}),(async()=>(await Ue(600),!x.current&&(x.current=!0,(0,j.invokeMerchantCallback)(()=>{V.current.onComplete?.({status:"succeeded",sessionId:V.current.sessionId,...l?{paymentMethod:l}:{}})}),ce.current&&m(null))))()},[]),ye=(0,a.useCallback)((n,l)=>{O.current=!0,K.current=!1,m({status:"error",wording:n,message:l.message??null}),(0,j.invokeMerchantCallback)(()=>{V.current.onDecline?.({status:"declined",sessionId:V.current.sessionId,...l.reason?{reason:l.reason}:{},...l.message?{message:l.message}:{}})}),(async()=>(await Ue(400),ce.current&&m(null)))()},[]),ee=(0,a.useCallback)((n,l)=>{K.current?(K.current=!1,m({status:"error",wording:n,message:l.message}),setTimeout(()=>{ce.current&&m(null)},400)):m(null),(0,j.invokeMerchantCallback)(()=>V.current.onError?.(l))},[]),Ee=(0,a.useCallback)(async n=>{let l=be.current+1;be.current=l;let c=()=>!ce.current||l!==be.current;K.current=!0,m({status:"processing",wording:"payment_method",message:null});let N=new Ce.PaymentAPI((0,C.resolveBillingApiUrl)(V.current.billingApiUrl),{telemetry:V.current.telemetry});try{for(let u=0;u<lr;u+=1){if((u>0||n.waitFirst)&&await Ue(ur),c())return;let X=await N.getUnifiedCheckoutSession(V.current.sessionId,V.current.nonce);if(c())return;let ae=X.data.session?.status;if(ae==="complete"){H(!0),me("payment_method");return}if(ae==="expired")throw new C.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new C.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(u){if(c())return;let X=u instanceof C.FloPayError&&u.code==="payment_method_setup_unverified";ee("payment_method",le(u,X?{retryable:!0}:{}))}finally{N.destroy()}},[ee,me]);(0,a.useEffect)(()=>{let n=!0,l=(0,C.resolveBillingApiUrl)(s),c=new Ce.PaymentAPI(l,{telemetry:i});I(null),H(!1),v(null),G(null),oe(null);let N=new Set;return Z.current=N,ne(N),O.current=!1,D.current=!1,x.current=!1,(async()=>{try{let{session:u,advertisement:X}=await pr(c,t,o);if(!n)return;let ae={advertisement:X,customer:dr(u),...u.futureUse?{futureUse:u.futureUse}:{},...u.futureUseUnsupported?{futureUseUnsupported:u.futureUseUnsupported}:{}};if(g){if((0,he.clearSetupRedirectParams)(),u.status==="complete"){H(!0),I(ae),me("payment_method");return}g.failed?ye("payment_method",{reason:"redirect_failed"}):Ee({waitFirst:!0})}let lt=X.card?await cr(c,u,t,o,l):null;if(!n)return;I(ae),lt&&(G(lt),v(new Ce.PciVaultCardCapture({sessionId:t,operation:"card_setup",telemetry:i})))}catch(u){if(!n)return;let X=le(u);O.current=!0,oe(X),(0,j.invokeMerchantCallback)(()=>V.current.onError?.(X))}})(),()=>{n=!1,c.destroy()}},[s,o,g,ye,me,t,i,Ee]),(0,a.useEffect)(()=>{if(!_)return;K.current=!1;let n=_.on("submitting",()=>{K.current=!0,m({status:"processing",wording:"card",message:null})}),l=_.on("complete",u=>{me("card",u.paymentMethod)}),c=_.on("decline",u=>{ye("card",{...u.declineReason?{reason:u.declineReason}:{},...u.message?{message:u.message}:{}})}),N=_.on("challenge_dismissed",()=>{m(null)});return()=>{n(),l(),c(),N()}},[_,ye,me]);let Ke=(0,a.useCallback)((n,l,c)=>{if(c.retryable){ee("payment_method",le(l,c));return}if(Z.current.has(n))return;let N=new Set(Z.current);N.add(n),Z.current=N,ne(N);let u=pe.current?.advertisement,X=u?(0,k.advertisedMethodKeys)(u).some(ae=>!N.has(ae)):!1;ee("payment_method",le(l,{code:c.code,retryable:X}))},[ee]),Xe=(0,a.useMemo)(()=>({onSubmitting:()=>{K.current=!0,m({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{Ee({waitFirst:!1})},onDeclined:n=>ye("payment_method",n),onValidation:n=>{(0,j.invokeMerchantCallback)(()=>V.current.onValidation?.(n))},onAbandoned:()=>{K.current=!1,m(null)}}),[ye,Ee]),qe=(0,a.useRef)(Ke);qe.current=Ke;let je=(0,a.useRef)(new Map),we=n=>{let l=je.current.get(n);if(l)return l;let c=(N,u)=>qe.current(n,N,u);return je.current.set(n,c),c},$e=(0,a.useCallback)(n=>{if(Z.current.has(n))return;let l=new Set(Z.current);l.add(n),Z.current=l,ne(l);let c=pe.current?.advertisement;c&&(0,k.advertisedMethodKeys)(c).some(u=>!l.has(u))||ee("payment_method",le(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[ee]),Ze=(0,a.useRef)($e);Ze.current=$e;let Je=(0,a.useRef)(new Map),Qe=n=>{let l=Je.current.get(n);if(l)return l;let c=()=>Ze.current(n);return Je.current.set(n,c),c},et=Q?(0,h.jsx)(ct,{status:Q.status,errorMessage:Q.message,...(0,k.setupOverlayLabels)(Q.wording),successNote:null,...ze?{theme:ze}:{}}):null;if(q)return(0,h.jsx)("div",{role:"alert",children:q.message});if(!R||U)return(0,h.jsxs)(h.Fragment,{children:[et,R?null:B]});let{advertisement:ge,customer:Kt,futureUse:tt,futureUseUnsupported:rt}=R,ot=(0,C.resolveBillingApiUrl)(s),nt=i===void 0?{}:{telemetry:i},Te=ge.stripe.filter(({method:n})=>!de.has(n)),Se=de.has("paypal")?null:ge.paypal,at=!!(ge.card&&_&&A?.html),st=({method:n,publishableKey:l,currency:c})=>(0,h.jsx)("div",{"data-flopay-payment-method":n,style:{display:"contents"},children:(0,h.jsx)(_e,{onFailed:we(n),children:(0,h.jsx)(a.Suspense,{fallback:null,children:(0,h.jsx)(e,{method:n,category:(0,k.stripeMethodCategory)(n),publishableKey:l,currency:c,...tt?{futureUse:tt}:{},...rt?{futureUseUnsupported:rt}:{},sessionId:t,nonce:o,billingApiUrl:ot,...nt,...He?{appearance:He}:{},...Ge?{buttonsLayout:Ge}:{},...typeof d=="string"?{themeId:d}:{},...Xe,onFailed:we(n),onUnavailable:Qe(n)})})})},n),Xt=Te.filter(({method:n})=>(0,k.stripeMethodCategory)(n)==="wallet"),qt=Te.filter(({method:n})=>(0,k.stripeMethodCategory)(n)!=="wallet"),it=Te.length>0||Se!==null;return(0,h.jsxs)(h.Fragment,{children:[et,it?(0,h.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Xt.map(st),Se?(0,h.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,h.jsx)(_e,{onFailed:we("paypal"),children:(0,h.jsx)(a.Suspense,{fallback:null,children:(0,h.jsx)(r,{clientId:Se.clientId,...Se.environment?{environment:Se.environment}:{},...ge.currency?{currency:ge.currency}:{},sessionId:t,nonce:o,billingApiUrl:ot,customer:Kt,...nt,...Xe,onFailed:we("paypal"),onUnavailable:Qe("paypal")})})})}):null,qt.map(st)]}):null,at&&it?(0,h.jsx)(ft,{label:"or add a card"}):null,at&&_&&A?.html?(0,h.jsx)("div",{"data-flopay-payment-method":"card",children:(0,h.jsx)(yt,{capture:_,html:A.html,messageToken:A.messageToken,expectedOrigin:A.expectedOrigin,verificationRequired:A.verificationRequired,theme:Ht,containerStyle:Gt,onReady:()=>{(0,j.invokeMerchantCallback)(()=>V.current.onReady?.())},onValidation:n=>{(0,j.invokeMerchantCallback)(()=>V.current.onValidation?.(n))},onError:n=>{n&&ee("card",le(new Error(n),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var zt=require("react/jsx-runtime"),wr={StripeSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(It(),Bt)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(Yt(),Vt)).then(e=>({default:e.PayPalSetupMethod})))};function Wt(e){return(0,zt.jsx)(St,{...e,branches:wr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
@@ -1,7 +1,7 @@
1
1
  export { FloPayCardSetupError } from './card-setup-entry.cjs';
2
2
  import React from 'react';
3
- import { F as FloPayPaymentMethodSetupProps } from './payment-method-setup-surface-BQltFPXs.cjs';
4
- export { a as FloPayPaymentMethodSetupCancelEvent, b as FloPayPaymentMethodSetupCompleteEvent, c as FloPayPaymentMethodSetupDeclineEvent } from './payment-method-setup-surface-BQltFPXs.cjs';
3
+ import { F as FloPayPaymentMethodSetupProps } from './payment-method-setup-surface-DWGNLM0I.cjs';
4
+ export { a as FloPayPaymentMethodSetupCancelEvent, b as FloPayPaymentMethodSetupCompleteEvent, c as FloPayPaymentMethodSetupDeclineEvent } from './payment-method-setup-surface-DWGNLM0I.cjs';
5
5
  import '@flopay/shared';
6
6
 
7
7
  /**
@@ -1,7 +1,7 @@
1
1
  export { FloPayCardSetupError } from './card-setup-entry.js';
2
2
  import React from 'react';
3
- import { F as FloPayPaymentMethodSetupProps } from './payment-method-setup-surface-Zf-DUxA0.js';
4
- export { a as FloPayPaymentMethodSetupCancelEvent, b as FloPayPaymentMethodSetupCompleteEvent, c as FloPayPaymentMethodSetupDeclineEvent } from './payment-method-setup-surface-Zf-DUxA0.js';
3
+ import { F as FloPayPaymentMethodSetupProps } from './payment-method-setup-surface-B9TI-00C.js';
4
+ export { a as FloPayPaymentMethodSetupCancelEvent, b as FloPayPaymentMethodSetupCompleteEvent, c as FloPayPaymentMethodSetupDeclineEvent } from './payment-method-setup-surface-B9TI-00C.js';
5
5
  import '@flopay/shared';
6
6
 
7
7
  /**
@@ -1 +1 @@
1
- import{a as t}from"./chunk-4DGIEZ4S.mjs";import{h as a}from"./chunk-XVCGDHF2.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-6O2YE4RY.mjs").then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:o(()=>import("./payment-method-setup-paypal-AGIJIZDK.mjs").then(e=>({default:e.PayPalSetupMethod})))};function y(e){return P(t,{...e,branches:p})}export{a as FloPayCardSetupError,y as FloPayPaymentMethodSetup};
1
+ import{a as t}from"./chunk-D4CVZRT4.mjs";import{h as a}from"./chunk-YR36EYW2.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-6O2YE4RY.mjs").then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:o(()=>import("./payment-method-setup-paypal-AGIJIZDK.mjs").then(e=>({default:e.PayPalSetupMethod})))};function y(e){return P(t,{...e,branches:p})}export{a as FloPayCardSetupError,y as FloPayPaymentMethodSetup};
@@ -1,4 +1,4 @@
1
- import { ThemeId, VaultCardThemeColors } from '@flopay/shared';
1
+ import { ThemeId, VaultCardThemeColors, FloPayAppearance, ButtonsLayoutStyles } from '@flopay/shared';
2
2
  import React from 'react';
3
3
  import { FloPayCardSetupCompleteEvent, FloPayCardSetupDeclineEvent, FloPayCardSetupCancelEvent, FloPayCardSetupError } from './card-setup-entry.js';
4
4
 
@@ -21,11 +21,38 @@ interface FloPayPaymentMethodSetupProps {
21
21
  /**
22
22
  * The same {@link ThemeId} bundle `FloPayCheckout` and `FloPayCardSetup`
23
23
  * resolve, or raw {@link VaultCardThemeColors} for the hosted card widget.
24
- * Defaults to `'modern-light'`.
24
+ * A preset also themes the Stripe wallets, APM tiles and the outcome
25
+ * overlay. Defaults to `'modern-light'`, which an unrecognized preset id
26
+ * also falls back to; pass `'classic'` for the historic FloPay look.
25
27
  */
26
28
  theme?: ThemeId | VaultCardThemeColors;
27
- /** Inline styles for the hosted card-widget container (as `FloPayCardSetup`). */
29
+ /**
30
+ * Inline styles for the hosted card-widget container, with the same
31
+ * precedence over the preset's pane surface (and a stored
32
+ * `buttonsStyles.cardFormContainer`) as `FloPayCardSetup`.
33
+ */
28
34
  containerStyle?: React.CSSProperties;
35
+ /**
36
+ * Appearance override, the same prop and type as `FloPayCheckout`'s and
37
+ * `FloPayCardSetup`'s (for example a client's saved embed theme
38
+ * `appearance`). It replaces the preset's appearance outright, as checkout
39
+ * does: its variables drive the hosted card fields and submit button, the
40
+ * Stripe Elements of every wallet and APM (`appearance`), the method tiles'
41
+ * radius, their save buttons, and the outcome overlay. Ignored with raw
42
+ * {@link VaultCardThemeColors}; an empty `{}` is the same as omitting it.
43
+ */
44
+ appearance?: FloPayAppearance;
45
+ /**
46
+ * Buttons-layout style overrides, the same prop and type as
47
+ * `FloPayCheckout`'s and `FloPayCardSetup`'s (for example a client's saved
48
+ * embed theme `buttonsStyles`), merged over the preset's buttons layout the
49
+ * way checkout merges them. `submitButton` and the `cardInput*` members style
50
+ * the hosted card form; `cardButton`, `cardInputBorder` and `submitButton`
51
+ * the APM tiles and their save buttons; `cardFormContainer` the pane around
52
+ * the card form and the outcome overlay's panel. Ignored with raw
53
+ * {@link VaultCardThemeColors}; an empty `{}` is the same as omitting it.
54
+ */
55
+ buttonsStyles?: ButtonsLayoutStyles;
29
56
  /** Optional content shown while the session and methods are loading. */
30
57
  loading?: React.ReactNode;
31
58
  /** Fired once the hosted card widget has mounted and can accept card input. */
@@ -1,4 +1,4 @@
1
- import { ThemeId, VaultCardThemeColors } from '@flopay/shared';
1
+ import { ThemeId, VaultCardThemeColors, FloPayAppearance, ButtonsLayoutStyles } from '@flopay/shared';
2
2
  import React from 'react';
3
3
  import { FloPayCardSetupCompleteEvent, FloPayCardSetupDeclineEvent, FloPayCardSetupCancelEvent, FloPayCardSetupError } from './card-setup-entry.cjs';
4
4
 
@@ -21,11 +21,38 @@ interface FloPayPaymentMethodSetupProps {
21
21
  /**
22
22
  * The same {@link ThemeId} bundle `FloPayCheckout` and `FloPayCardSetup`
23
23
  * resolve, or raw {@link VaultCardThemeColors} for the hosted card widget.
24
- * Defaults to `'modern-light'`.
24
+ * A preset also themes the Stripe wallets, APM tiles and the outcome
25
+ * overlay. Defaults to `'modern-light'`, which an unrecognized preset id
26
+ * also falls back to; pass `'classic'` for the historic FloPay look.
25
27
  */
26
28
  theme?: ThemeId | VaultCardThemeColors;
27
- /** Inline styles for the hosted card-widget container (as `FloPayCardSetup`). */
29
+ /**
30
+ * Inline styles for the hosted card-widget container, with the same
31
+ * precedence over the preset's pane surface (and a stored
32
+ * `buttonsStyles.cardFormContainer`) as `FloPayCardSetup`.
33
+ */
28
34
  containerStyle?: React.CSSProperties;
35
+ /**
36
+ * Appearance override, the same prop and type as `FloPayCheckout`'s and
37
+ * `FloPayCardSetup`'s (for example a client's saved embed theme
38
+ * `appearance`). It replaces the preset's appearance outright, as checkout
39
+ * does: its variables drive the hosted card fields and submit button, the
40
+ * Stripe Elements of every wallet and APM (`appearance`), the method tiles'
41
+ * radius, their save buttons, and the outcome overlay. Ignored with raw
42
+ * {@link VaultCardThemeColors}; an empty `{}` is the same as omitting it.
43
+ */
44
+ appearance?: FloPayAppearance;
45
+ /**
46
+ * Buttons-layout style overrides, the same prop and type as
47
+ * `FloPayCheckout`'s and `FloPayCardSetup`'s (for example a client's saved
48
+ * embed theme `buttonsStyles`), merged over the preset's buttons layout the
49
+ * way checkout merges them. `submitButton` and the `cardInput*` members style
50
+ * the hosted card form; `cardButton`, `cardInputBorder` and `submitButton`
51
+ * the APM tiles and their save buttons; `cardFormContainer` the pane around
52
+ * the card form and the outcome overlay's panel. Ignored with raw
53
+ * {@link VaultCardThemeColors}; an empty `{}` is the same as omitting it.
54
+ */
55
+ buttonsStyles?: ButtonsLayoutStyles;
29
56
  /** Optional content shown while the session and methods are loading. */
30
57
  loading?: React.ReactNode;
31
58
  /** Fired once the hosted card widget has mounted and can accept card input. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/react",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -39,8 +39,8 @@
39
39
  "@paypal/paypal-js": "^10.1.0",
40
40
  "@stripe/react-stripe-js": "^6.12.0",
41
41
  "@stripe/stripe-js": "^9.17.0",
42
- "@flopay/js": "1.12.0",
43
- "@flopay/shared": "1.12.0"
42
+ "@flopay/js": "1.13.0",
43
+ "@flopay/shared": "1.13.0"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": ">=18.0.0",
@@ -1 +0,0 @@
1
- import{a as Be,b as Ae,c as C,d as Te,f as xe,g as Ie,i as w}from"./chunk-XVCGDHF2.mjs";import{PaymentAPI as Ge,PciVaultCardCapture as rt}from"@flopay/js/card-setup";import{FloPayError as F,isCardSetupCheckoutSession as nt,isMountableVaultBlock as at,resolveBillingApiUrl as te,resolveTheme as ot,resolveVaultMountOptions as st}from"@flopay/shared";import it,{Suspense as Ke,useCallback as O,useEffect as re,useMemo as T,useRef as u,useState as b}from"react";import{clearSetupRedirectParams as De,readSetupRedirectReturn as Le}from"@flopay/js/card-setup";import{advertisedMethodKeys as ee,advertisesAnyMethod as Ne,readSetupAdvertisement as We,setupOverlayLabels as Ye,stripeMethodCategory as Y}from"@flopay/shared";import{computeVaultCardThemeColors as qe}from"@flopay/shared";import{Fragment as He,jsx as c,jsxs as ae}from"react/jsx-runtime";var lt=15,ut=2e3;function dt(y){return{userId:y.customer?.id??"",email:y.customer?.email??""}}function ne(y){return new Promise(v=>setTimeout(v,y))}async function ct(y,v,a){if(!v.trim())throw new F("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new F("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let d=await y.getUnifiedCheckoutSession(v,a),f=d.data.session;if(!f||!nt(f))throw new F("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let o=We(d);if(!Ne(o)){let{skippedForMissingCurrency:l}=o,x=l.length>0?`FloPay: this setup session advertises only Stripe methods (${l.join(", ")}), and they need the session's currency, which the setup-session read did not carry.`:"FloPay: this setup session advertises no payment method.";throw new F(x,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:f,advertisement:o}}async function pt(y,v,a,d,f){let o=v.vault??null;at(o)||(o=await y.getVaultCapture(a,d));let l=st(o,{billingApiUrl:f,sessionId:a,nonce:d});if(!l)throw new F("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return l}var q=class extends it.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 Ut({branches:{StripeSetupMethod:y,PayPalSetupMethod:v},sessionId:a,nonce:d,billingApiUrl:f,telemetry:o,theme:l="modern-light",containerStyle:x,loading:ze=null,onReady:oe,onComplete:se,onDecline:ie,onCancel:le,onValidation:ue,onError:de}){let[j]=b(Le),[I,G]=b(null),[$e,K]=b(!1),[S,ce]=b(null),[_,pe]=b(null),[me,ye]=b(null),[D,p]=b(null),[H,z]=b(()=>new Set),M=u(H),$=u(null);$.current=I;let g=u(!1),J=u(!1),V=u(!1),Q=u(!1),X=u(0),L=u(0),E=u(!1),m=T(()=>typeof l=="object"?void 0:ot(l),[l]),Je=T(()=>typeof l=="object"?l:m?qe({appearance:m.appearance,buttonsStyles:m.buttonsLayout,layout:"default"}):null,[m,l]),Qe=T(()=>Be(m?.buttonsLayout.cardFormContainer,x),[m,x]),fe=T(()=>m?Ae(m):void 0,[m]),s=u({sessionId:a,nonce:d,billingApiUrl:f,telemetry:o,onReady:oe,onComplete:se,onDecline:ie,onCancel:le,onValidation:ue,onError:de});s.current={sessionId:a,nonce:d,billingApiUrl:f,telemetry:o,onReady:oe,onComplete:se,onDecline:ie,onCancel:le,onValidation:ue,onError:de},re(()=>{E.current=!0;let e=X.current+1;return X.current=e,()=>{E.current=!1,L.current+=1,queueMicrotask(()=>{X.current===e&&(V.current||Q.current||(Q.current=!0,C(()=>{s.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let U=O((e,t)=>{V.current=!0,g.current=!1,p({status:"success",wording:e,message:null}),(async()=>(await ne(600),!J.current&&(J.current=!0,C(()=>{s.current.onComplete?.({status:"succeeded",sessionId:s.current.sessionId,...t?{paymentMethod:t}:{}})}),E.current&&p(null))))()},[]),k=O((e,t)=>{V.current=!0,g.current=!1,p({status:"error",wording:e,message:t.message??null}),C(()=>{s.current.onDecline?.({status:"declined",sessionId:s.current.sessionId,...t.reason?{reason:t.reason}:{},...t.message?{message:t.message}:{}})}),(async()=>(await ne(400),E.current&&p(null)))()},[]),P=O((e,t)=>{g.current?(g.current=!1,p({status:"error",wording:e,message:t.message}),setTimeout(()=>{E.current&&p(null)},400)):p(null),C(()=>s.current.onError?.(t))},[]),N=O(async e=>{let t=L.current+1;L.current=t;let n=()=>!E.current||t!==L.current;g.current=!0,p({status:"processing",wording:"payment_method",message:null});let i=new Ge(te(s.current.billingApiUrl),{telemetry:s.current.telemetry});try{for(let r=0;r<lt;r+=1){if((r>0||e.waitFirst)&&await ne(ut),n())return;let h=await i.getUnifiedCheckoutSession(s.current.sessionId,s.current.nonce);if(n())return;let R=h.data.session?.status;if(R==="complete"){K(!0),U("payment_method");return}if(R==="expired")throw new F("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new F("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(r){if(n())return;let h=r instanceof F&&r.code==="payment_method_setup_unverified";P("payment_method",w(r,h?{retryable:!0}:{}))}finally{i.destroy()}},[P,U]);re(()=>{let e=!0,t=te(f),n=new Ge(t,{telemetry:o});G(null),K(!1),ce(null),pe(null),ye(null);let i=new Set;return M.current=i,z(i),V.current=!1,Q.current=!1,J.current=!1,(async()=>{try{let{session:r,advertisement:h}=await ct(n,a,d);if(!e)return;let R={advertisement:h,customer:dt(r),...r.futureUse?{futureUse:r.futureUse}:{},...r.futureUseUnsupported?{futureUseUnsupported:r.futureUseUnsupported}:{}};if(j){if(De(),r.status==="complete"){K(!0),G(R),U("payment_method");return}j.failed?k("payment_method",{reason:"redirect_failed"}):N({waitFirst:!0})}let Ve=h.card?await pt(n,r,a,d,t):null;if(!e)return;G(R),Ve&&(pe(Ve),ce(new rt({sessionId:a,operation:"card_setup",telemetry:o})))}catch(r){if(!e)return;let h=w(r);V.current=!0,ye(h),C(()=>s.current.onError?.(h))}})(),()=>{e=!1,n.destroy()}},[f,d,j,k,U,a,o,N]),re(()=>{if(!S)return;g.current=!1;let e=S.on("submitting",()=>{g.current=!0,p({status:"processing",wording:"card",message:null})}),t=S.on("complete",r=>{U("card",r.paymentMethod)}),n=S.on("decline",r=>{k("card",{...r.declineReason?{reason:r.declineReason}:{},...r.message?{message:r.message}:{}})}),i=S.on("challenge_dismissed",()=>{p(null)});return()=>{e(),t(),n(),i()}},[S,k,U]);let he=O((e,t,n)=>{if(n.retryable){P("payment_method",w(t,n));return}if(M.current.has(e))return;let i=new Set(M.current);i.add(e),M.current=i,z(i);let r=$.current?.advertisement,h=r?ee(r).some(R=>!i.has(R)):!1;P("payment_method",w(t,{code:n.code,retryable:h}))},[P]),ve=T(()=>({onSubmitting:()=>{g.current=!0,p({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{N({waitFirst:!1})},onDeclined:e=>k("payment_method",e),onValidation:e=>{C(()=>s.current.onValidation?.(e))},onAbandoned:()=>{g.current=!1,p(null)}}),[k,N]),Se=u(he);Se.current=he;let ge=u(new Map),W=e=>{let t=ge.current.get(e);if(t)return t;let n=(i,r)=>Se.current(e,i,r);return ge.current.set(e,n),n},Ce=O(e=>{if(M.current.has(e))return;let t=new Set(M.current);t.add(e),M.current=t,z(t);let n=$.current?.advertisement;n&&ee(n).some(r=>!t.has(r))||P("payment_method",w(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[P]),Pe=u(Ce);Pe.current=Ce;let be=u(new Map),Fe=e=>{let t=be.current.get(e);if(t)return t;let n=()=>Pe.current(e);return be.current.set(e,n),n},Me=D?c(Te,{status:D.status,errorMessage:D.message,...Ye(D.wording),successNote:null,...fe?{theme:fe}:{}}):null;if(me)return c("div",{role:"alert",children:me.message});if(!I||$e)return ae(He,{children:[Me,I?null:ze]});let{advertisement:B,customer:Xe,futureUse:Re,futureUseUnsupported:we}=I,_e=te(f),Ee=o===void 0?{}:{telemetry:o},Z=B.stripe.filter(({method:e})=>!H.has(e)),A=H.has("paypal")?null:B.paypal,Ue=!!(B.card&&S&&_?.html),ke=({method:e,publishableKey:t,currency:n})=>c("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:c(q,{onFailed:W(e),children:c(Ke,{fallback:null,children:c(y,{method:e,category:Y(e),publishableKey:t,currency:n,...Re?{futureUse:Re}:{},...we?{futureUseUnsupported:we}:{},sessionId:a,nonce:d,billingApiUrl:_e,...Ee,...m?{appearance:m.appearance,buttonsLayout:m.buttonsLayout}:{},...typeof l=="string"?{themeId:l}:{},...ve,onFailed:W(e),onUnavailable:Fe(e)})})})},e),Ze=Z.filter(({method:e})=>Y(e)==="wallet"),et=Z.filter(({method:e})=>Y(e)!=="wallet"),Oe=Z.length>0||A!==null;return ae(He,{children:[Me,Oe?ae("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ze.map(ke),A?c("div",{"data-flopay-payment-method":"paypal",children:c(q,{onFailed:W("paypal"),children:c(Ke,{fallback:null,children:c(v,{clientId:A.clientId,...A.environment?{environment:A.environment}:{},...B.currency?{currency:B.currency}:{},sessionId:a,nonce:d,billingApiUrl:_e,customer:Xe,...Ee,...ve,onFailed:W("paypal"),onUnavailable:Fe("paypal")})})})}):null,et.map(ke)]}):null,Ue&&Oe?c(Ie,{label:"or add a card"}):null,Ue&&S&&_?.html?c("div",{"data-flopay-payment-method":"card",children:c(xe,{capture:S,html:_.html,messageToken:_.messageToken,expectedOrigin:_.expectedOrigin,verificationRequired:_.verificationRequired,theme:Je,containerStyle:Qe,onReady:()=>{C(()=>s.current.onReady?.())},onValidation:e=>{C(()=>s.current.onValidation?.(e))},onError:e=>{e&&P("card",w(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{Ut as a};