@flopay/react 1.10.6 → 1.11.1

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 pr=Object.create;var Ee=Object.defineProperty;var fr=Object.getOwnPropertyDescriptor;var mr=Object.getOwnPropertyNames;var yr=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var fe=(e,t)=>()=>(e&&(t=e(e=0)),t);var De=(e,t)=>{for(var r in t)Ee(e,r,{get:t[r],enumerable:!0})},it=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of mr(t))!gr.call(e,o)&&o!==r&&Ee(e,o,{get:()=>t[o],enumerable:!(n=fr(t,o))||n.enumerable});return e};var hr=(e,t,r)=>(r=e!=null?pr(yr(e)):{},it(t||!e||!e.__esModule?Ee(r,"default",{value:e,enumerable:!0}):r,e)),Sr=e=>it(Ee({},"__esModule",{value:!0}),e);function Ae(e,t,r){let n=`We couldn't open ${e}. Try again or choose another payment method.`;return t?r?`${n} Open this page in your system browser, then try again.`:`${n} Allow pop-ups for this site, then try again.`:n}function Lt(e){if(e instanceof Error)return e.message;if(typeof e=="object"&&e!==null){let t=e.message;return typeof t=="string"?t:void 0}return typeof e=="string"?e:void 0}function Pe(e){if(typeof e!="string")return;let t=e.trim();return/^[a-z0-9_.-]{1,64}$/i.test(t)?t:void 0}function Bt(e){if(typeof e!="object"||e===null)return;let t=e;return Pe(t.code)??Pe(t.type)??Pe(t.name)}function Qr(e){if(!(typeof e!="object"||e===null))return Pe(e.decline_code)}function He(e){return typeof e!="object"||e===null?!1:Pe(e.type)?.toLowerCase()==="card_error"||Qr(e)!==void 0}function en(e){let t=Lt(e)?.toLowerCase()??"",r=Bt(e)?.toLowerCase()??"";return Zr.has(r)?!0:/(?:popup|pop-up).{0,40}(?:block|denied|prevent)/i.test(t)||/(?:block|denied|prevent).{0,40}(?:popup|pop-up)/i.test(t)}function tn(e){if(Bt(e)?.toLowerCase()==="paypal_init_timeout")return!0;let r=Lt(e)??"";return r.includes("No ack for postMessage init()")&&Jr.some(n=>r.includes(n))&&r.includes("10000ms")}function Le(e,t){if(He(e))return{errorCode:"PROVIDER_RUNTIME_FAILED",popupBlocked:!1,providerDeclined:!0,terminalReason:"provider_declined"};let n=en(e)||t.inAppBrowser&&!t.handoffObserved&&tn(e);return{errorCode:n?"POPUP_BLOCKED":"PROVIDER_RUNTIME_FAILED",popupBlocked:n,providerDeclined:!1,terminalReason:n?"popup_blocked":"provider_error"}}var Zr,Jr,We=fe(()=>{"use strict";Zr=new Set(["err_blocked_by_client","notallowederror","popup_blocked","popupblocked"]),Jr=["https://www.paypal.com","https://www.sandbox.paypal.com"]});function Be(e){let t=e??(typeof navigator>"u"?"":navigator.userAgent),r=n=>({inAppBrowser:n!=="none",appFamily:n,popupCapability:"unknown"});return t?/FBAN|FBAV|FB_IAB|FBIOS/i.test(t)?r("facebook"):/Instagram/i.test(t)?r("instagram"):/musical_ly|BytedanceWebview|TikTok/i.test(t)?r("tiktok"):/Twitter|Snapchat|Pinterest|LinkedInApp|Line\/|MicroMessenger|GSA\//i.test(t)?r("other_in_app"):/Android.*;\s?wv\)/.test(t)||/(iPhone|iPad|iPod).*AppleWebKit(?!.*Safari)/.test(t)?r("generic_webview"):r("none"):r("none")}function Ot(e,t,r=e.popupCapability){return e.inAppBrowser||r==="blocked"||t==="prefer_redirect"?"redirect":"popup"}var Ye=fe(()=>{"use strict"});var It,Dt=fe(()=>{"use strict";It={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 Nt(){return(0,x.jsx)("style",{children:rn})}function Ut(e,t){let r=e.availablePaymentMethods;return r&&t.some(n=>r[n])?"ready":"unavailable"}function Ht({state:e,placeholderTestId:t,borderRadius:r=8,children:n}){return e==="unavailable"||e==="load_error"?null:(0,x.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,x.jsx)("div",{"data-testid":t,"aria-hidden":e==="ready",style:{position:"absolute",inset:0,height:44,borderRadius:r,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,x.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:n})]})}function Wt({method:e,themeId:t,submitting:r=!1,disabled:n=!1,highlighted:o=!1,hasNextStep:a=!1,onClick:s,backgroundColor:l,borderColor:d,textColor:p,borderRadius:f,fontFamily:S}){let g=(0,Z.resolveStripeMethodBrandVariant)(e,t),w=It[e],[C,k]=(0,Vt.useState)(!1),m=!!w&&!C,_=g?.backgroundColor??l??"#ffffff",D=g?.borderColor??d??"#d1d5db",M=g?.textColor??p??"#262833";return(0,x.jsx)("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!r&&!n&&s()},disabled:r||n,"aria-busy":r||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:nn,padding:"0 1rem",backgroundColor:_,color:M,border:`1px solid ${D}`,borderRadius:f??8,fontSize:"0.95rem",fontWeight:600,fontFamily:S,cursor:r||n?"not-allowed":"pointer",opacity:n&&!r?.55:1,animation:r?"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:o?"0 0 0 2px rgba(74, 73, 255, 0.15)":void 0},children:r?(0,x.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,Z.getStripeMethodDisplayName)(e)}\u2026`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,Z.hasVendoredStripeMethodLogo)(e)?8:0},children:[m?(0,x.jsx)("img",{src:w,alt:"","aria-hidden":"true",onError:()=>k(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!m&&g?.logoSvg?(0,x.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:g.logoSvg}}):null,(0,x.jsx)("span",{children:(0,Z.getStripeMethodDisplayName)(e)})]}),a&&(0,x.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:M,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,x.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function Yt(e){let t=new Set(e.map(Z.stripeExpressMethodToOptionKey)),r=n=>n==="applePay"||n==="googlePay"?"always":"auto";return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(n=>[n,t.has(n)?r(n):"never"]))}function Gt({testId:e,attributes:t,disabled:r,onClick:n,color:o,borderRadius:a,style:s,children:l}){return(0,x.jsx)("button",{type:"button","data-testid":e,...t,onClick:n,disabled:r,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:o,color:"white",border:"none",borderRadius:a,fontSize:"1rem",fontWeight:600,cursor:r?"not-allowed":"pointer",opacity:r?.5:1,transition:"opacity 120ms ease-out",...s??{}},children:l})}var Z,Vt,x,rn,nn,zt,$t,jt=fe(()=>{"use strict";Z=require("@flopay/shared"),Vt=require("react");Dt();x=require("react/jsx-runtime"),rn=`
1
+ "use strict";var mr=Object.create;var Re=Object.defineProperty;var yr=Object.getOwnPropertyDescriptor;var gr=Object.getOwnPropertyNames;var hr=Object.getPrototypeOf,Sr=Object.prototype.hasOwnProperty;var fe=(e,t)=>()=>(e&&(t=e(e=0)),t);var De=(e,t)=>{for(var r in t)Re(e,r,{get:t[r],enumerable:!0})},ut=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of gr(t))!Sr.call(e,o)&&o!==r&&Re(e,o,{get:()=>t[o],enumerable:!(n=yr(t,o))||n.enumerable});return e};var br=(e,t,r)=>(r=e!=null?mr(hr(e)):{},ut(t||!e||!e.__esModule?Re(r,"default",{value:e,enumerable:!0}):r,e)),vr=e=>ut(Re({},"__esModule",{value:!0}),e);function Le(e,t,r){let n=`We couldn't open ${e}. Try again or choose another payment method.`;return t?r?`${n} Open this page in your system browser, then try again.`:`${n} Allow pop-ups for this site, then try again.`:n}function Ot(e){if(e instanceof Error)return e.message;if(typeof e=="object"&&e!==null){let t=e.message;return typeof t=="string"?t:void 0}return typeof e=="string"?e:void 0}function we(e){if(typeof e!="string")return;let t=e.trim();return/^[a-z0-9_.-]{1,64}$/i.test(t)?t:void 0}function It(e){if(typeof e!="object"||e===null)return;let t=e;return we(t.code)??we(t.type)??we(t.name)}function tn(e){if(!(typeof e!="object"||e===null))return we(e.decline_code)}function He(e){return typeof e!="object"||e===null?!1:we(e.type)?.toLowerCase()==="card_error"||tn(e)!==void 0}function rn(e){let t=Ot(e)?.toLowerCase()??"",r=It(e)?.toLowerCase()??"";return Qr.has(r)?!0:/(?:popup|pop-up).{0,40}(?:block|denied|prevent)/i.test(t)||/(?:block|denied|prevent).{0,40}(?:popup|pop-up)/i.test(t)}function nn(e){if(It(e)?.toLowerCase()==="paypal_init_timeout")return!0;let r=Ot(e)??"";return r.includes("No ack for postMessage init()")&&en.some(n=>r.includes(n))&&r.includes("10000ms")}function Be(e,t){if(He(e))return{errorCode:"PROVIDER_RUNTIME_FAILED",popupBlocked:!1,providerDeclined:!0,terminalReason:"provider_declined"};let n=rn(e)||t.inAppBrowser&&!t.handoffObserved&&nn(e);return{errorCode:n?"POPUP_BLOCKED":"PROVIDER_RUNTIME_FAILED",popupBlocked:n,providerDeclined:!1,terminalReason:n?"popup_blocked":"provider_error"}}var Qr,en,We=fe(()=>{"use strict";Qr=new Set(["err_blocked_by_client","notallowederror","popup_blocked","popupblocked"]),en=["https://www.paypal.com","https://www.sandbox.paypal.com"]});function Oe(e){let t=e??(typeof navigator>"u"?"":navigator.userAgent),r=n=>({inAppBrowser:n!=="none",appFamily:n,popupCapability:"unknown"});return t?/FBAN|FBAV|FB_IAB|FBIOS/i.test(t)?r("facebook"):/Instagram/i.test(t)?r("instagram"):/musical_ly|BytedanceWebview|TikTok/i.test(t)?r("tiktok"):/Twitter|Snapchat|Pinterest|LinkedInApp|Line\/|MicroMessenger|GSA\//i.test(t)?r("other_in_app"):/Android.*;\s?wv\)/.test(t)||/(iPhone|iPad|iPod).*AppleWebKit(?!.*Safari)/.test(t)?r("generic_webview"):r("none"):r("none")}function Dt(e,t,r=e.popupCapability){return e.inAppBrowser||r==="blocked"||t==="prefer_redirect"?"redirect":"popup"}var Ye=fe(()=>{"use strict"});var Vt,Nt=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 Ht(){return(0,x.jsx)("style",{children:on})}function Wt(e,t){let r=e.availablePaymentMethods;return r&&t.some(n=>r[n])?"ready":"unavailable"}function Yt({state:e,placeholderTestId:t,borderRadius:r=8,children:n}){return e==="unavailable"||e==="load_error"?null:(0,x.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,x.jsx)("div",{"data-testid":t,"aria-hidden":e==="ready",style:{position:"absolute",inset:0,height:44,borderRadius:r,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,x.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:n})]})}function zt({method:e,themeId:t,submitting:r=!1,disabled:n=!1,highlighted:o=!1,hasNextStep:a=!1,onClick:s,backgroundColor:l,borderColor:d,textColor:p,borderRadius:f,fontFamily:S}){let g=(0,Z.resolveStripeMethodBrandVariant)(e,t),k=Vt[e],[P,E]=(0,Ut.useState)(!1),m=!!k&&!P,_=g?.backgroundColor??l??"#ffffff",D=g?.borderColor??d??"#d1d5db",M=g?.textColor??p??"#262833";return(0,x.jsx)("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!r&&!n&&s()},disabled:r||n,"aria-busy":r||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:an,padding:"0 1rem",backgroundColor:_,color:M,border:`1px solid ${D}`,borderRadius:f??8,fontSize:"0.95rem",fontWeight:600,fontFamily:S,cursor:r||n?"not-allowed":"pointer",opacity:n&&!r?.55:1,animation:r?"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:o?"0 0 0 2px rgba(74, 73, 255, 0.15)":void 0},children:r?(0,x.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,Z.getStripeMethodDisplayName)(e)}\u2026`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,Z.hasVendoredStripeMethodLogo)(e)?8:0},children:[m?(0,x.jsx)("img",{src:k,alt:"","aria-hidden":"true",onError:()=>E(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!m&&g?.logoSvg?(0,x.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:g.logoSvg}}):null,(0,x.jsx)("span",{children:(0,Z.getStripeMethodDisplayName)(e)})]}),a&&(0,x.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:M,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,x.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function $t(e){let t=new Set(e.map(Z.stripeExpressMethodToOptionKey)),r=n=>n==="applePay"||n==="googlePay"?"always":"auto";return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(n=>[n,t.has(n)?r(n):"never"]))}function Kt({testId:e,attributes:t,disabled:r,onClick:n,color:o,borderRadius:a,style:s,children:l}){return(0,x.jsx)("button",{type:"button","data-testid":e,...t,onClick:n,disabled:r,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:o,color:"white",border:"none",borderRadius:a,fontSize:"1rem",fontWeight:600,cursor:r?"not-allowed":"pointer",opacity:r?.5:1,transition:"opacity 120ms ease-out",...s??{}},children:l})}var Z,Ut,x,on,an,Gt,jt,Xt=fe(()=>{"use strict";Z=require("@flopay/shared"),Ut=require("react");Nt();x=require("react/jsx-runtime"),on=`
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
- `,nn=44;zt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},$t={type:"accordion",defaultCollapsed:!1,radios:"never"}});var Jt={};De(Jt,{StripeSetupMethod:()=>cn});function on(e){let t=ze.get(e);if(t)return t;let r=(0,qt.loadStripe)(e).catch(n=>{throw ze.delete(e),n});return ze.set(e,r),r}function sn(e){return e?{theme:an[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function ln(e){return He(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Kt(e){return e==="paypal"?"PayPal":(0,Oe.getStripeMethodDisplayName)(e)}function un(){return typeof window>"u"?"":window.location.href}function cn(e){let{publishableKey:t,method:r,currency:n,appearance:o}=e,[a]=(0,I.useState)(()=>on(t)),s=(0,I.useMemo)(()=>{let l=sn(o);return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:Zt[r]?.types??[r],...l?{appearance:l}:{}}},[o,n,r]);return(0,B.jsx)(X.Elements,{stripe:a,options:s,children:(0,B.jsx)(pn,{...e})})}function pn({method:e,category:t,sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,appearance:s,themeId:l,buttonsLayout:d,onSubmitting:p,onConfirmed:f,onDeclined:S,onFailed:g,onValidation:w,onUnavailable:C}){let k=(0,X.useStripe)(),m=(0,X.useElements)(),[_,D]=(0,I.useState)(!1),[M,b]=(0,I.useState)("loading"),[j,N]=(0,I.useState)(!1),[E,W]=(0,I.useState)(!1),$=(0,I.useRef)(!1),[U]=(0,I.useState)(()=>Be()),[A,Y]=(0,I.useState)(!1),te=(0,I.useCallback)((T,V)=>{if(Le(T,{inAppBrowser:U.inAppBrowser,handoffObserved:!1}).popupBlocked){Y(!0),g(new Error(Ae(Kt(e),!0,U.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}g(V.message===void 0?T:new Error(V.message),{code:V.code,retryable:!0})},[U.inAppBrowser,e,g]),K=(0,I.useCallback)(async()=>{if(!(!k||!m||$.current)){$.current=!0,D(!0);try{let T=await m.submit();if(T.error){w(T.error.message??null);return}p();let V=await new Xt.PaymentAPI(o,{telemetry:a}).createSessionIntent(r,n,{provider:"stripe",paymentMethodCategory:t,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(V.provider!=="stripe"||V.intentKind!=="setup")throw new Oe.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let L=await k.confirmSetup({elements:m,clientSecret:V.clientSecret,confirmParams:{return_url:un()},redirect:"if_required"});if(L.error){ln(L.error)?S({...L.error.decline_code||L.error.code?{reason:L.error.decline_code??L.error.code}:{},...L.error.message?{message:L.error.message}:{}}):te(L.error,{code:"payment_method_setup_provider_failed",message:L.error.message??"The payment method could not be saved."});return}f()}catch(T){te(T,{code:"payment_method_setup_failed"})}finally{$.current=!1,D(!1)}}},[o,t,m,e,n,f,S,p,w,te,r,k,a]),re=Zt[e]?.wallet,G=re==="paypal"&&Ot(U,"auto",A?"blocked":U.popupCapability)==="redirect",ue=s?.variables?.borderRadius??d?.cardButton?.borderRadius??8;if(t==="wallet"&&re&&!G)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Nt,{}),(0,B.jsx)(Ht,{state:M,borderRadius:ue,children:(0,B.jsx)(X.ExpressCheckoutElement,{options:{...zt,paymentMethods:Yt([e])},onReady:T=>{let V=Ut(T,[re]);b(V),V==="unavailable"&&C()},onLoadError:()=>{b("load_error"),C()},onConfirm:()=>{K()}})})]});let ne=Kt(e);return(0,B.jsxs)(B.Fragment,{children:[j?(0,B.jsx)(Wt,{method:e,themeId:l,hasNextStep:!0,highlighted:E,disabled:_,onClick:()=>W(T=>!T),backgroundColor:d?.cardButton?.backgroundColor,borderColor:d?.cardInputBorder,textColor:d?.cardButton?.color,borderRadius:ue}):null,(0,B.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!E,style:E?{display:"flex",flexDirection:"column"}:dn,children:[(0,B.jsx)(X.PaymentElement,{options:{layout:$t},onReady:()=>N(!0),onLoadError:()=>C(),onChange:T=>{T.complete&&w(null)}}),(0,B.jsx)(Gt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!k||!m||_||!E,onClick:()=>{K()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:_?"Saving\u2026":`Save ${ne}`})]})]})}var Xt,Oe,X,qt,I,B,Zt,ze,an,dn,Qt=fe(()=>{"use strict";Xt=require("@flopay/js/card-setup"),Oe=require("@flopay/shared"),X=require("@stripe/react-stripe-js"),qt=require("@stripe/stripe-js"),I=require("react");We();Ye();jt();B=require("react/jsx-runtime"),Zt={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"}},ze=new Map;an={night:"night",flat:"flat"};dn={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var rr={};De(rr,{PayPalSetupMethod:()=>fn});function fn({clientId:e,environment:t,currency:r,sessionId:n,nonce:o,billingApiUrl:a,telemetry:s,customer:{userId:l,email:d},onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g}){let w=(0,le.useRef)(null),C=(0,le.useRef)({onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g});C.current={onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g};let[k]=(0,le.useState)(()=>Be().inAppBrowser);return(0,le.useEffect)(()=>{let m=!0,_,D=new er.PaymentAPI(a,{telemetry:s}),M={userId:l,email:d};return(async()=>{try{let b=await(0,tr.loadScript)({clientId:e,...r?{currency:r.toUpperCase()}:{},components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),j=w.current;if(!m||!j)return;if(!b?.Buttons)throw new ee.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=b.Buttons({createVaultSetupToken:async()=>{C.current.onSubmitting();let E=await D.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(E.provider!=="paypal"||E.providerObjectType!=="setup_token")throw new ee.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return E.providerObjectId},onApprove:async E=>{let W=E.vaultSetupToken;if(!W)throw new ee.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let $=await D.processPayment(M.userId,{sessionId:n,nonce:o,paymentMethodCategory:"paypal",tokenizedData:{id:W,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:M});if(!$.ok)throw new ee.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:$.status});m&&C.current.onConfirmed()},onCancel:()=>{m&&C.current.onAbandoned()},onError:E=>{if(!m)return;let{popupBlocked:W}=Le(E,{inAppBrowser:k,handoffObserved:!1});C.current.onFailed(W?new Error(Ae("PayPal",!0,k)):E,{code:W?"popup_blocked":"paypal_setup_failed",retryable:!0})}});_=()=>N.close(),await N.render(j)}catch(b){if(!m)return;C.current.onFailed(b,{code:"paypal_unavailable",retryable:!0})}})(),()=>{m=!1,_?.().catch(()=>{}),D.destroy()}},[a,e,r,d,t,k,o,n,s,l]),(0,nr.jsx)("div",{ref:w,"data-flopay-paypal-setup":""})}var er,ee,tr,le,nr,or=fe(()=>{"use strict";er=require("@flopay/js/card-setup"),ee=require("@flopay/shared"),tr=require("@paypal/paypal-js"),le=require("react");We();Ye();nr=require("react/jsx-runtime")});var yn={};De(yn,{FloPayCardSetupError:()=>ve,FloPayPaymentMethodSetup:()=>ar});module.exports=Sr(yn);var kt=require("@flopay/js/card-setup"),me=require("@flopay/shared"),_e=require("react");function lt(e,t){if(!e)return t;let r=t??{},n=Object.keys(r),o=n.some(s=>s.startsWith("background")),a={};for(let[s,l]of Object.entries(e))s in r||o&&s.startsWith("background")||(a[s]=l);for(let s of n)a[s]=r[s];return a}var br=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 vr(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return br.has(t.charAt(0).toLowerCase()+t.slice(1))}function Cr(e,t){return typeof t=="number"&&t!==0&&!vr(e)?`${t}px`:String(t).trim()}function ut(e,t){if(e.style.cssText="",!!t){for(let[r,n]of Object.entries(t))if(!(n==null||n==="")){if(r.startsWith("--")){e.style.setProperty(r,String(n));continue}e.style[r]=Cr(r,n)}}}var dt={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ct(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?dt.dark:dt.light,a=t.colorText??(n?"#F1F5F9":"#262833"),s=e.appearance.rules?.[".Label"];return{panel:{...r.background===void 0?{}:{background:r.background},...r.backgroundColor===void 0?{}:{backgroundColor:r.backgroundColor},...r.border===void 0?{}:{border:r.border},...r.borderRadius===void 0?{}:{borderRadius:r.borderRadius},...r.boxShadow===void 0?{}:{boxShadow:r.boxShadow},color:a,...t.fontFamily?{fontFamily:t.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:t.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:s?.color??a}}function q(e){if(!e)return;let t=r=>{console.error("[FloPay] Merchant callback failed; checkout continued.",r)};try{Promise.resolve(e()).catch(t)}catch(r){t(r)}}var P=require("react/jsx-runtime");var Pr={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function pt({status:e,errorMessage:t,authorized:r=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:s="You will be automatically redirected, do not close or navigate away from this window.",theme:l=Pr}){let d={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,P.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,P.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,P.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,P.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,P.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,P.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,P.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,P.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,P.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,P.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,P.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,P.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,P.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,P.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,P.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(r?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&s!==null&&(0,P.jsx)("p",{style:d,children:s}),e==="error"&&t&&(0,P.jsx)("p",{style:d,children:t}),(0,P.jsx)("style",{children:`
22
+ `,an=44;Gt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},jt={type:"accordion",defaultCollapsed:!1,radios:"never"}});var er={};De(er,{StripeSetupMethod:()=>fn});function sn(e){let t=ze.get(e);if(t)return t;let r=(0,Jt.loadStripe)(e).catch(n=>{throw ze.delete(e),n});return ze.set(e,r),r}function un(e){return e?{theme:ln[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function dn(e){return He(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function qt(e){return e==="paypal"?"PayPal":(0,ge.getStripeMethodDisplayName)(e)}function cn(){return typeof window>"u"?"":window.location.href}function fn(e){let{publishableKey:t,method:r,currency:n,futureUse:o,futureUseUnsupported:a,appearance:s}=e,[l]=(0,I.useState)(()=>sn(t)),d=(0,I.useMemo)(()=>{let p=un(s),f=(0,ge.resolveSetupFutureUsage)({futureUse:o,futureUseUnsupported:a},r,"setup");return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:Qt[r]?.types??[r],...f?{setupFutureUsage:f}:{},...p?{appearance:p}:{}}},[s,n,o,a,r]);return(0,B.jsx)(X.Elements,{stripe:l,options:d,children:(0,B.jsx)(mn,{...e})})}function mn({method:e,category:t,sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,appearance:s,themeId:l,buttonsLayout:d,onSubmitting:p,onConfirmed:f,onDeclined:S,onFailed:g,onValidation:k,onUnavailable:P}){let E=(0,X.useStripe)(),m=(0,X.useElements)(),[_,D]=(0,I.useState)(!1),[M,v]=(0,I.useState)("loading"),[j,N]=(0,I.useState)(!1),[R,W]=(0,I.useState)(!1),$=(0,I.useRef)(!1),[U]=(0,I.useState)(()=>Oe()),[A,Y]=(0,I.useState)(!1),te=(0,I.useCallback)((F,V)=>{if(Be(F,{inAppBrowser:U.inAppBrowser,handoffObserved:!1}).popupBlocked){Y(!0),g(new Error(Le(qt(e),!0,U.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}g(V.message===void 0?F:new Error(V.message),{code:V.code,retryable:!0})},[U.inAppBrowser,e,g]),K=(0,I.useCallback)(async()=>{if(!(!E||!m||$.current)){$.current=!0,D(!0);try{let F=await m.submit();if(F.error){k(F.error.message??null);return}p();let V=await new Zt.PaymentAPI(o,{telemetry:a}).createSessionIntent(r,n,{provider:"stripe",paymentMethodCategory:t,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(V.provider!=="stripe"||V.intentKind!=="setup")throw new ge.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let L=await E.confirmSetup({elements:m,clientSecret:V.clientSecret,confirmParams:{return_url:cn()},redirect:"if_required"});if(L.error){dn(L.error)?S({...L.error.decline_code||L.error.code?{reason:L.error.decline_code??L.error.code}:{},...L.error.message?{message:L.error.message}:{}}):te(L.error,{code:"payment_method_setup_provider_failed",message:L.error.message??"The payment method could not be saved."});return}f()}catch(F){te(F,{code:"payment_method_setup_failed"})}finally{$.current=!1,D(!1)}}},[o,t,m,e,n,f,S,p,k,te,r,E,a]),re=Qt[e]?.wallet,G=re==="paypal"&&Dt(U,"auto",A?"blocked":U.popupCapability)==="redirect",ue=s?.variables?.borderRadius??d?.cardButton?.borderRadius??8;if(t==="wallet"&&re&&!G)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Ht,{}),(0,B.jsx)(Yt,{state:M,borderRadius:ue,children:(0,B.jsx)(X.ExpressCheckoutElement,{options:{...Gt,paymentMethods:$t([e])},onReady:F=>{let V=Wt(F,[re]);v(V),V==="unavailable"&&P()},onLoadError:()=>{v("load_error"),P()},onConfirm:()=>{K()}})})]});let ne=qt(e);return(0,B.jsxs)(B.Fragment,{children:[j?(0,B.jsx)(zt,{method:e,themeId:l,hasNextStep:!0,highlighted:R,disabled:_,onClick:()=>W(F=>!F),backgroundColor:d?.cardButton?.backgroundColor,borderColor:d?.cardInputBorder,textColor:d?.cardButton?.color,borderRadius:ue}):null,(0,B.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!R,style:R?{display:"flex",flexDirection:"column"}:pn,children:[(0,B.jsx)(X.PaymentElement,{options:{layout:jt},onReady:()=>N(!0),onLoadError:()=>P(),onChange:F=>{F.complete&&k(null)}}),(0,B.jsx)(Kt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!E||!m||_||!R,onClick:()=>{K()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:_?"Saving\u2026":`Save ${ne}`})]})]})}var Zt,ge,X,Jt,I,B,Qt,ze,ln,pn,tr=fe(()=>{"use strict";Zt=require("@flopay/js/card-setup"),ge=require("@flopay/shared"),X=require("@stripe/react-stripe-js"),Jt=require("@stripe/stripe-js"),I=require("react");We();Ye();Xt();B=require("react/jsx-runtime"),Qt={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"}},ze=new Map;ln={night:"night",flat:"flat"};pn={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var or={};De(or,{PayPalSetupMethod:()=>yn});function yn({clientId:e,environment:t,currency:r,sessionId:n,nonce:o,billingApiUrl:a,telemetry:s,customer:{userId:l,email:d},onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g}){let k=(0,le.useRef)(null),P=(0,le.useRef)({onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g});P.current={onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g};let[E]=(0,le.useState)(()=>Oe().inAppBrowser);return(0,le.useEffect)(()=>{let m=!0,_,D=new rr.PaymentAPI(a,{telemetry:s}),M={userId:l,email:d};return(async()=>{try{let v=await(0,nr.loadScript)({clientId:e,...r?{currency:r.toUpperCase()}:{},components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),j=k.current;if(!m||!j)return;if(!v?.Buttons)throw new ee.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=v.Buttons({createVaultSetupToken:async()=>{P.current.onSubmitting();let R=await D.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(R.provider!=="paypal"||R.providerObjectType!=="setup_token")throw new ee.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return R.providerObjectId},onApprove:async R=>{let W=R.vaultSetupToken;if(!W)throw new ee.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let $=await D.processPayment(M.userId,{sessionId:n,nonce:o,paymentMethodCategory:"paypal",tokenizedData:{id:W,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:M});if(!$.ok)throw new ee.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:$.status});m&&P.current.onConfirmed()},onCancel:()=>{m&&P.current.onAbandoned()},onError:R=>{if(!m)return;let{popupBlocked:W}=Be(R,{inAppBrowser:E,handoffObserved:!1});P.current.onFailed(W?new Error(Le("PayPal",!0,E)):R,{code:W?"popup_blocked":"paypal_setup_failed",retryable:!0})}});_=()=>N.close(),await N.render(j)}catch(v){if(!m)return;P.current.onFailed(v,{code:"paypal_unavailable",retryable:!0})}})(),()=>{m=!1,_?.().catch(()=>{}),D.destroy()}},[a,e,r,d,t,E,o,n,s,l]),(0,ar.jsx)("div",{ref:k,"data-flopay-paypal-setup":""})}var rr,ee,nr,le,ar,sr=fe(()=>{"use strict";rr=require("@flopay/js/card-setup"),ee=require("@flopay/shared"),nr=require("@paypal/paypal-js"),le=require("react");We();Ye();ar=require("react/jsx-runtime")});var hn={};De(hn,{FloPayCardSetupError:()=>Ce,FloPayPaymentMethodSetup:()=>ir});module.exports=vr(hn);var Rt=require("@flopay/js/card-setup"),me=require("@flopay/shared"),Me=require("react");function dt(e,t){if(!e)return t;let r=t??{},n=Object.keys(r),o=n.some(s=>s.startsWith("background")),a={};for(let[s,l]of Object.entries(e))s in r||o&&s.startsWith("background")||(a[s]=l);for(let s of n)a[s]=r[s];return a}var Cr=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 Pr(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Cr.has(t.charAt(0).toLowerCase()+t.slice(1))}function wr(e,t){return typeof t=="number"&&t!==0&&!Pr(e)?`${t}px`:String(t).trim()}function ct(e,t){if(e.style.cssText="",!!t){for(let[r,n]of Object.entries(t))if(!(n==null||n==="")){if(r.startsWith("--")){e.style.setProperty(r,String(n));continue}e.style[r]=wr(r,n)}}}var pt={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ft(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?pt.dark:pt.light,a=t.colorText??(n?"#F1F5F9":"#262833"),s=e.appearance.rules?.[".Label"];return{panel:{...r.background===void 0?{}:{background:r.background},...r.backgroundColor===void 0?{}:{backgroundColor:r.backgroundColor},...r.border===void 0?{}:{border:r.border},...r.borderRadius===void 0?{}:{borderRadius:r.borderRadius},...r.boxShadow===void 0?{}:{boxShadow:r.boxShadow},color:a,...t.fontFamily?{fontFamily:t.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:t.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:s?.color??a}}function q(e){if(!e)return;let t=r=>{console.error("[FloPay] Merchant callback failed; checkout continued.",r)};try{Promise.resolve(e()).catch(t)}catch(r){t(r)}}var w=require("react/jsx-runtime");var kr={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function mt({status:e,errorMessage:t,authorized:r=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:s="You will be automatically redirected, do not close or navigate away from this window.",theme:l=kr}){let d={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,w.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,w.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,w.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,w.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,w.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,w.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,w.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,w.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,w.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(r?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&s!==null&&(0,w.jsx)("p",{style:d,children:s}),e==="error"&&t&&(0,w.jsx)("p",{style:d,children:t}),(0,w.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 H=require("react");var Re=require("react"),ft=typeof window>"u"?Re.useEffect:Re.useLayoutEffect;var ae=require("react/jsx-runtime"),Ve=new WeakSet;function mt({capture:e,html:t,messageToken:r,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:s,onReady:l,onError:d,onValidation:p}){let f=(0,H.useRef)(null),S=(0,H.useRef)(l),g=(0,H.useRef)(d),w=(0,H.useRef)(p);S.current=l,g.current=d,w.current=p;let C=(0,H.useRef)(o);C.current=o;let k=(0,H.useRef)(null),m=a??void 0,_=(0,H.useRef)(m);_.current=m;let D=(0,H.useRef)(void 0);return(0,H.useEffect)(()=>{let M=f.current;if(!M)return;let b=!0,j=!1,N=()=>{!b||j||(j=!0,S.current?.())},E=e.on("ready",()=>{N()}),W=e.on("error",Y=>{g.current?.(Y.message??"There was a problem loading the secure card form.")}),$=e.on("validation",Y=>{w.current?.(Y.message??null)}),U=_.current??(Ve.has(e)?null:void 0),A={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...C.current?{theme:C.current}:{},...U===void 0?{}:{submitLabel:U}};return k.current=C.current??null,D.current=_.current,_.current!==void 0&&Ve.add(e),e.mount(M,A).then(()=>{N()}).catch(Y=>{b&&g.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{b=!1,E(),W(),$(),e.unmount()}},[e,t,r,n]),ft(()=>{let M=f.current;M&&ut(M,s)},[s]),(0,H.useEffect)(()=>{o!==void 0&&(o===null&&k.current===null||(k.current=o,e.applyTheme?.(o)))},[e,o]),(0,H.useEffect)(()=>{m!==D.current&&(D.current=m,m!==void 0&&Ve.add(e),e.setSubmitLabel?.(m??null))},[e,m]),(0,ae.jsx)("div",{ref:f,"data-testid":"flopay-vault-card-fields"})}function yt({label:e}){return(0,ae.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,ae.jsx)("span",{children:e}),(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var ht=/^#([0-9a-f]{6})$/i,wr=/^#([0-9a-f]{3})$/i,St=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,bt=/^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,kr=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Er=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Rr=/^(-?\d+(?:\.\d+)?)em$/,xr=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,_r=/^[a-z][a-z0-9 -]{0,31}$/i,Mr=new Set(["none","uppercase","lowercase","capitalize"]);function vt(e){if(typeof e!="string")return null;let t=e.trim(),r=ht.exec(t);if(r){let f=Number.parseInt(r[1],16);return{r:f>>16&255,g:f>>8&255,b:f&255,a:null}}let n=wr.exec(t);if(n){let[f,S,g]=n[1].split("").map(w=>Number.parseInt(w+w,16));return{r:f,g:S,b:g,a:null}}let o=St.exec(t),a=o?null:bt.exec(t),s=o??a;if(!s)return null;let l=Number(s[1]),d=Number(s[2]),p=Number(s[3]);return l>255||d>255||p>255?null:{r:l,g:d,b:p,a:a?Number(a[4]):null}}function Ct({r:e,g:t,b:r,a:n}){return n===null?`#${(1<<24|e<<16|t<<8|r).toString(16).slice(1)}`:`rgba(${e},${t},${r},${n})`}function Se(e){if(typeof e!="string")return;let t=e.trim();if(ht.test(t)||St.test(t))return t;let r=bt.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=vt(t);return n?Ct(n):void 0}function xe(e,t=.12){let r=vt(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return Ct({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function be(e,t){let r=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===t&&n===0){o.trim()&&r.push(o.trim()),o="";continue}o+=a}return o.trim()&&r.push(o.trim()),r}function se(e,t,r){if(typeof e!="number"&&typeof e!="string")return;let n=Er.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Tr(e,t,r){if(typeof e!="string")return;let n=Rr.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Fr(e){let t=be(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=be(o," "),s=Se(a[0]);if(!s)return;let l=n/(t.length-1)*100,d=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),p=r[r.length-1]?.position??-1;if(!Number.isFinite(d)||d<0||d>100||d<p)return;r.push({color:s,position:d})}return{type:"linearGradient",angle:0,stops:r}}function Ar(e){if(typeof e!="string")return;let t=e.trim(),r=Se(t);if(r)return{type:"solid",color:r};let n=kr.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Fr(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Lr(e){return e.type==="solid"?{type:"solid",color:xe(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:xe(t.color)}))}}function Br(e){let t=!1,r,n=[];for(let d of be(e," ")){if(d.toLowerCase()==="inset"){t=!0;continue}let p=Se(d);if(p){r=p;continue}let f=se(d,-128,128);if(f===void 0)return;n.push(f)}if(!r||n.length<2||n.length>4)return;let[o,a,s=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||s>128||Math.abs(l)>32))return{color:r,inset:t,offsetX:o,offsetY:a,blur:s,spread:l}}function Or(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=be(t,",").map(Br);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function gt(e){if(typeof e!="string")return;let t=be(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>_r.test(r)).slice(0,4);return t.length>0?t:void 0}function Ir(e){let t=typeof e=="string"?e.trim().split(/\s+/):[e],r=se(t[0],0,64),n=se(t[1]??t[0],0,64);if(!(r===void 0||n===void 0))return{paddingBlock:r,paddingInline:n}}function Dr(e){if(e==="bold")return 700;if(e==="normal")return 400;let t=Number(e);return Number.isInteger(t)&&t>=100&&t<=900?t:void 0}function Pt({appearance:e,buttonsStyles:t,fontFamily:r}){let n=t.submitButton;if(!n)return;let o=e?.variables,a=Ar(n.background??n.backgroundColor),s=Se(o?.colorPrimaryHover),l=s?{type:"solid",color:s}:a&&Lr(a),d={fontFamilies:gt(n.fontFamily)??gt(r),fontSize:se(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:Dr(n.fontWeight)??600,letterSpacing:Tr(n.letterSpacing,-.1,.5)??.01,lineHeight:se(n.lineHeight,.8,2)??1,textTransform:Mr.has(String(n.textTransform))?n.textTransform:"uppercase"},p=Ir(n.padding),f=Or(n.boxShadow),S=se(n.borderRadius,0,9999),g=typeof n.backdropFilter=="string"?se(xr.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:Se(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:d,...p?{spacing:p}:{},...f?{shadow:f}:{},...S===void 0?{}:{borderRadius:S},disabledOpacity:e?.theme==="night"?.8:.6,...g===void 0?{}:{backdropBlur:g}}}function Vr(e,t=.12){let r=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(r)?`#${r}`:r;return/^#[0-9a-fA-F]{6}$/.test(n)?xe(n,t):e}function Nr(e){if(typeof e=="number"||typeof e=="string")return e}function wt({appearance:e,buttonsStyles:t,layout:r="default"}){let n=e?.variables,o=S=>typeof S=="string"&&S?S:void 0,a=t.submitButton,s=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=r==="buttons",d=t.nameInput,p=o(d?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",f=Pt({appearance:e,buttonsStyles:t,fontFamily:p});return{primaryColor:s,primaryHoverColor:o(n?.colorPrimaryHover)??Vr(s,.12),inputBackgroundColor:o(t.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(t.cardInputColor)??o(d?.color)??o(n?.colorText)??"#262833",borderColor:o(t.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(t.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:p,fontSize:o(t.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Nr(d?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...f?{submitButton:f}:{}}}var Ne=require("react/jsx-runtime"),ve=class extends me.FloPayError{constructor(t,r,n){super(t,r,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ie(e,t={}){let r=e instanceof me.FloPayError?e:void 0,n=r?.statusCode,o=t.retryable??(r?.type==="network_error"||r?.type==="rate_limit_error"||typeof n=="number"&&n>=500||r?.code==="vault_capture_timeout"||!r);return new ve(r?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),r?.type??"api_error",{code:t.code??r?.code??"card_setup_load_failed",retryable:o,...r?.param?{param:r.param}:{},...n===void 0?{}:{statusCode:n}})}var $e=require("react");var Ce=require("@flopay/js/card-setup"),F=require("@flopay/shared"),u=hr(require("react"),1);var Et=require("@flopay/shared"),Ur=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),Hr=new Set(["wallet","apm"]);function ye(e){return typeof e=="string"&&e.trim().length>0}function Wr(e){if(typeof e!="object"||e===null)return!1;let t=e;return ye(t.family)&&ye(t.paymentMethodType)}function Yr(e){let r=e.raw?.data?.currency;return ye(r)?r.trim().toUpperCase():null}function Rt(e){let t=Yr(e),r=e.data.session?.advertisedPaymentMethods;if(!Array.isArray(r))return{card:!0,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]};let n={card:!1,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]},o=new Set;for(let a of r){if(!Wr(a)||o.has(a.paymentMethodType))continue;let{family:s,paymentMethodType:l,providerType:d,publishableKey:p}=a;if(s==="card"){if(l!=="card")continue;n.card=!0}else if(Hr.has(s)){if(d!=="stripe"||l==="card"||!ye(p))continue;if(t===null){n.skippedForMissingCurrency.includes(l)||n.skippedForMissingCurrency.push(l);continue}n.stripe.push({method:l,publishableKey:p,currency:t})}else if(s==="paypal"){if(l!==Et.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE||d!=="paypal"||!ye(p))continue;n.paypal={clientId:p,...ye(a.environment)?{environment:a.environment}:{}}}else continue;o.add(l)}return n.paypal&&(n.stripe=n.stripe.filter(a=>a.method!=="paypal")),n}function Me(e){return[...e.card?["card"]:[],...e.stripe.map(t=>t.method),...e.paypal?["paypal"]:[]]}function xt(e){return Me(e).length>0}function Te(e){return Ur.has(e)?"wallet":"apm"}var zr=["setup_intent","setup_intent_client_secret","redirect_status"];function _t(){if(typeof window>"u")return null;let e=new URLSearchParams(window.location.search);return!e.has("setup_intent")||!e.has("redirect_status")?null:{failed:e.get("redirect_status")==="failed"}}function Mt(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of zr)e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0);t&&window.history.replaceState(window.history.state,"",e.toString())}function Tt(e){return e==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}var v=require("react/jsx-runtime"),Gr=15,jr=2e3;function Kr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(t=>setTimeout(t,e))}async function Xr(e,t,r){if(!t.trim())throw new F.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new F.FloPayError("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let n=await e.getUnifiedCheckoutSession(t,r),o=n.data.session;if(!o||!(0,F.isCardSetupCheckoutSession)(o))throw new F.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=Rt(n);if(!xt(a)){let{skippedForMissingCurrency:s}=a,l=s.length>0?`FloPay: this setup session advertises only Stripe methods (${s.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.FloPayError(l,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:o,advertisement:a}}async function qr(e,t,r,n){let o=t.vault??null;if(o?.html?.trim()||(o=await e.getVaultCapture(r,n)),!o.html?.trim())throw new F.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var Fe=class extends u.default.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(r){this.props.onFailed(r,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function At({branches:{StripeSetupMethod:e,PayPalSetupMethod:t},sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,theme:s="modern-light",containerStyle:l,loading:d=null,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:w,onError:C}){let[k]=(0,u.useState)(_t),[m,_]=(0,u.useState)(null),[D,M]=(0,u.useState)(!1),[b,j]=(0,u.useState)(null),[N,E]=(0,u.useState)(null),[W,$]=(0,u.useState)(null),[U,A]=(0,u.useState)(null),[Y,te]=(0,u.useState)(()=>new Set),K=(0,u.useRef)(Y),re=(0,u.useRef)(null);re.current=m;let G=(0,u.useRef)(!1),ue=(0,u.useRef)(!1),ne=(0,u.useRef)(!1),T=(0,u.useRef)(!1),V=(0,u.useRef)(0),L=(0,u.useRef)(0),de=(0,u.useRef)(!1),z=(0,u.useMemo)(()=>typeof s=="object"?void 0:(0,F.resolveTheme)(s),[s]),ir=(0,u.useMemo)(()=>typeof s=="object"?s:z?wt({appearance:z.appearance,buttonsStyles:z.buttonsLayout,layout:"default"}):null,[z,s]),lr=(0,u.useMemo)(()=>lt(z?.buttonsLayout.cardFormContainer,l),[z,l]),Ge=(0,u.useMemo)(()=>z?ct(z):void 0,[z]),O=(0,u.useRef)({sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:w,onError:C});O.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:w,onError:C},(0,u.useEffect)(()=>{de.current=!0;let i=V.current+1;return V.current=i,()=>{de.current=!1,L.current+=1,queueMicrotask(()=>{V.current===i&&(ne.current||T.current||(T.current=!0,q(()=>{O.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let ce=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"success",wording:i,message:null}),(async()=>(await Ue(600),!ue.current&&(ue.current=!0,q(()=>{O.current.onComplete?.({status:"succeeded",sessionId:O.current.sessionId,...c?{paymentMethod:c}:{}})}),de.current&&A(null))))()},[]),pe=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"error",wording:i,message:c.message??null}),q(()=>{O.current.onDecline?.({status:"declined",sessionId:O.current.sessionId,...c.reason?{reason:c.reason}:{},...c.message?{message:c.message}:{}})}),(async()=>(await Ue(400),de.current&&A(null)))()},[]),J=(0,u.useCallback)((i,c)=>{G.current?(G.current=!1,A({status:"error",wording:i,message:c.message}),setTimeout(()=>{de.current&&A(null)},400)):A(null),q(()=>O.current.onError?.(c))},[]),we=(0,u.useCallback)(async i=>{let c=L.current+1;L.current=c;let h=()=>!de.current||c!==L.current;G.current=!0,A({status:"processing",wording:"payment_method",message:null});let R=new Ce.PaymentAPI((0,F.resolveBillingApiUrl)(O.current.billingApiUrl),{telemetry:O.current.telemetry});try{for(let y=0;y<Gr;y+=1){if((y>0||i.waitFirst)&&await Ue(jr),h())return;let Q=await R.getUnifiedCheckoutSession(O.current.sessionId,O.current.nonce);if(h())return;let oe=Q.data.session?.status;if(oe==="complete"){M(!0),ce("payment_method");return}if(oe==="expired")throw new F.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new F.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(y){if(h())return;let Q=y instanceof F.FloPayError&&y.code==="payment_method_setup_unverified";J("payment_method",ie(y,Q?{retryable:!0}:{}))}finally{R.destroy()}},[J,ce]);(0,u.useEffect)(()=>{let i=!0,c=new Ce.PaymentAPI((0,F.resolveBillingApiUrl)(o),{telemetry:a});_(null),M(!1),j(null),E(null),$(null);let h=new Set;return K.current=h,te(h),ne.current=!1,T.current=!1,ue.current=!1,(async()=>{try{let{session:R,advertisement:y}=await Xr(c,r,n);if(!i)return;let Q={advertisement:y,customer:Kr(R)};if(k){if(Mt(),R.status==="complete"){M(!0),_(Q),ce("payment_method");return}k.failed?pe("payment_method",{reason:"redirect_failed"}):we({waitFirst:!0})}let oe=y.card?await qr(c,R,r,n):null;if(!i)return;_(Q),oe&&(E(oe),j(new Ce.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(R){if(!i)return;let y=ie(R);ne.current=!0,$(y),q(()=>O.current.onError?.(y))}})(),()=>{i=!1,c.destroy()}},[o,n,k,pe,ce,r,a,we]),(0,u.useEffect)(()=>{if(!b)return;G.current=!1;let i=b.on("submitting",()=>{G.current=!0,A({status:"processing",wording:"card",message:null})}),c=b.on("complete",y=>{ce("card",y.paymentMethod)}),h=b.on("decline",y=>{pe("card",{...y.declineReason?{reason:y.declineReason}:{},...y.message?{message:y.message}:{}})}),R=b.on("challenge_dismissed",()=>{A(null)});return()=>{i(),c(),h(),R()}},[b,pe,ce]);let je=(0,u.useCallback)((i,c,h)=>{if(h.retryable){J("payment_method",ie(c,h));return}if(K.current.has(i))return;let R=new Set(K.current);R.add(i),K.current=R,te(R);let y=re.current?.advertisement,Q=y?Me(y).some(oe=>!R.has(oe)):!1;J("payment_method",ie(c,{code:h.code,retryable:Q}))},[J]),Ke=(0,u.useMemo)(()=>({onSubmitting:()=>{G.current=!0,A({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{we({waitFirst:!1})},onDeclined:i=>pe("payment_method",i),onValidation:i=>{q(()=>O.current.onValidation?.(i))},onAbandoned:()=>{G.current=!1,A(null)}}),[pe,we]),Xe=(0,u.useRef)(je);Xe.current=je;let qe=(0,u.useRef)(new Map),ke=i=>{let c=qe.current.get(i);if(c)return c;let h=(R,y)=>Xe.current(i,R,y);return qe.current.set(i,h),h},Ze=(0,u.useCallback)(i=>{if(K.current.has(i))return;let c=new Set(K.current);c.add(i),K.current=c,te(c);let h=re.current?.advertisement;h&&Me(h).some(y=>!c.has(y))||J("payment_method",ie(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[J]),Je=(0,u.useRef)(Ze);Je.current=Ze;let Qe=(0,u.useRef)(new Map),et=i=>{let c=Qe.current.get(i);if(c)return c;let h=()=>Je.current(i);return Qe.current.set(i,h),h},tt=U?(0,v.jsx)(pt,{status:U.status,errorMessage:U.message,...Tt(U.wording),successNote:null,...Ge?{theme:Ge}:{}}):null;if(W)return(0,v.jsx)("div",{role:"alert",children:W.message});if(!m||D)return(0,v.jsxs)(v.Fragment,{children:[tt,m?null:d]});let{advertisement:ge,customer:ur}=m,rt=(0,F.resolveBillingApiUrl)(o),nt=a===void 0?{}:{telemetry:a},Ie=ge.stripe.filter(({method:i})=>!Y.has(i)),he=Y.has("paypal")?null:ge.paypal,ot=!!(ge.card&&b&&N?.html),at=({method:i,publishableKey:c,currency:h})=>(0,v.jsx)("div",{"data-flopay-payment-method":i,style:{display:"contents"},children:(0,v.jsx)(Fe,{onFailed:ke(i),children:(0,v.jsx)(u.Suspense,{fallback:null,children:(0,v.jsx)(e,{method:i,category:Te(i),publishableKey:c,currency:h,sessionId:r,nonce:n,billingApiUrl:rt,...nt,...z?{appearance:z.appearance,buttonsLayout:z.buttonsLayout}:{},...typeof s=="string"?{themeId:s}:{},...Ke,onFailed:ke(i),onUnavailable:et(i)})})})},i),dr=Ie.filter(({method:i})=>Te(i)==="wallet"),cr=Ie.filter(({method:i})=>Te(i)!=="wallet"),st=Ie.length>0||he!==null;return(0,v.jsxs)(v.Fragment,{children:[tt,st?(0,v.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[dr.map(at),he?(0,v.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,v.jsx)(Fe,{onFailed:ke("paypal"),children:(0,v.jsx)(u.Suspense,{fallback:null,children:(0,v.jsx)(t,{clientId:he.clientId,...he.environment?{environment:he.environment}:{},...ge.currency?{currency:ge.currency}:{},sessionId:r,nonce:n,billingApiUrl:rt,customer:ur,...nt,...Ke,onFailed:ke("paypal"),onUnavailable:et("paypal")})})})}):null,cr.map(at)]}):null,ot&&st?(0,v.jsx)(yt,{label:"or add a card"}):null,ot&&b&&N?.html?(0,v.jsx)("div",{"data-flopay-payment-method":"card",children:(0,v.jsx)(mt,{capture:b,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,theme:ir,containerStyle:lr,onReady:()=>{q(()=>O.current.onReady?.())},onValidation:i=>{q(()=>O.current.onValidation?.(i))},onError:i=>{i&&J("card",ie(new Error(i),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var sr=require("react/jsx-runtime"),mn={StripeSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(Qt(),Jt)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(or(),rr)).then(e=>({default:e.PayPalSetupMethod})))};function ar(e){return(0,sr.jsx)(At,{...e,branches:mn})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
27
+ `})]})})}var H=require("react");var xe=require("react"),yt=typeof window>"u"?xe.useEffect:xe.useLayoutEffect;var ae=require("react/jsx-runtime"),Ve=new WeakSet;function gt({capture:e,html:t,messageToken:r,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:s,onReady:l,onError:d,onValidation:p}){let f=(0,H.useRef)(null),S=(0,H.useRef)(l),g=(0,H.useRef)(d),k=(0,H.useRef)(p);S.current=l,g.current=d,k.current=p;let P=(0,H.useRef)(o);P.current=o;let E=(0,H.useRef)(null),m=a??void 0,_=(0,H.useRef)(m);_.current=m;let D=(0,H.useRef)(void 0);return(0,H.useEffect)(()=>{let M=f.current;if(!M)return;let v=!0,j=!1,N=()=>{!v||j||(j=!0,S.current?.())},R=e.on("ready",()=>{N()}),W=e.on("error",Y=>{g.current?.(Y.message??"There was a problem loading the secure card form.")}),$=e.on("validation",Y=>{k.current?.(Y.message??null)}),U=_.current??(Ve.has(e)?null:void 0),A={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...P.current?{theme:P.current}:{},...U===void 0?{}:{submitLabel:U}};return E.current=P.current??null,D.current=_.current,_.current!==void 0&&Ve.add(e),e.mount(M,A).then(()=>{N()}).catch(Y=>{v&&g.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{v=!1,R(),W(),$(),e.unmount()}},[e,t,r,n]),yt(()=>{let M=f.current;M&&ct(M,s)},[s]),(0,H.useEffect)(()=>{o!==void 0&&(o===null&&E.current===null||(E.current=o,e.applyTheme?.(o)))},[e,o]),(0,H.useEffect)(()=>{m!==D.current&&(D.current=m,m!==void 0&&Ve.add(e),e.setSubmitLabel?.(m??null))},[e,m]),(0,ae.jsx)("div",{ref:f,"data-testid":"flopay-vault-card-fields"})}function ht({label:e}){return(0,ae.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,ae.jsx)("span",{children:e}),(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var bt=/^#([0-9a-f]{6})$/i,Er=/^#([0-9a-f]{3})$/i,vt=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ct=/^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,Rr=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,xr=/^(-?\d+(?:\.\d+)?)(?:px)?$/,_r=/^(-?\d+(?:\.\d+)?)em$/,Mr=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Fr=/^[a-z][a-z0-9 -]{0,31}$/i,Tr=new Set(["none","uppercase","lowercase","capitalize"]);function Pt(e){if(typeof e!="string")return null;let t=e.trim(),r=bt.exec(t);if(r){let f=Number.parseInt(r[1],16);return{r:f>>16&255,g:f>>8&255,b:f&255,a:null}}let n=Er.exec(t);if(n){let[f,S,g]=n[1].split("").map(k=>Number.parseInt(k+k,16));return{r:f,g:S,b:g,a:null}}let o=vt.exec(t),a=o?null:Ct.exec(t),s=o??a;if(!s)return null;let l=Number(s[1]),d=Number(s[2]),p=Number(s[3]);return l>255||d>255||p>255?null:{r:l,g:d,b:p,a:a?Number(a[4]):null}}function wt({r:e,g:t,b:r,a:n}){return n===null?`#${(1<<24|e<<16|t<<8|r).toString(16).slice(1)}`:`rgba(${e},${t},${r},${n})`}function be(e){if(typeof e!="string")return;let t=e.trim();if(bt.test(t)||vt.test(t))return t;let r=Ct.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=Pt(t);return n?wt(n):void 0}function _e(e,t=.12){let r=Pt(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return wt({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function ve(e,t){let r=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===t&&n===0){o.trim()&&r.push(o.trim()),o="";continue}o+=a}return o.trim()&&r.push(o.trim()),r}function se(e,t,r){if(typeof e!="number"&&typeof e!="string")return;let n=xr.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Ar(e,t,r){if(typeof e!="string")return;let n=_r.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Lr(e){let t=ve(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=ve(o," "),s=be(a[0]);if(!s)return;let l=n/(t.length-1)*100,d=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),p=r[r.length-1]?.position??-1;if(!Number.isFinite(d)||d<0||d>100||d<p)return;r.push({color:s,position:d})}return{type:"linearGradient",angle:0,stops:r}}function Br(e){if(typeof e!="string")return;let t=e.trim(),r=be(t);if(r)return{type:"solid",color:r};let n=Rr.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Lr(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Or(e){return e.type==="solid"?{type:"solid",color:_e(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:_e(t.color)}))}}function Ir(e){let t=!1,r,n=[];for(let d of ve(e," ")){if(d.toLowerCase()==="inset"){t=!0;continue}let p=be(d);if(p){r=p;continue}let f=se(d,-128,128);if(f===void 0)return;n.push(f)}if(!r||n.length<2||n.length>4)return;let[o,a,s=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||s>128||Math.abs(l)>32))return{color:r,inset:t,offsetX:o,offsetY:a,blur:s,spread:l}}function Dr(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=ve(t,",").map(Ir);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function St(e){if(typeof e!="string")return;let t=ve(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>Fr.test(r)).slice(0,4);return t.length>0?t:void 0}function Vr(e){let t=typeof e=="string"?e.trim().split(/\s+/):[e],r=se(t[0],0,64),n=se(t[1]??t[0],0,64);if(!(r===void 0||n===void 0))return{paddingBlock:r,paddingInline:n}}function Nr(e){if(e==="bold")return 700;if(e==="normal")return 400;let t=Number(e);return Number.isInteger(t)&&t>=100&&t<=900?t:void 0}function kt({appearance:e,buttonsStyles:t,fontFamily:r}){let n=t.submitButton;if(!n)return;let o=e?.variables,a=Br(n.background??n.backgroundColor),s=be(o?.colorPrimaryHover),l=s?{type:"solid",color:s}:a&&Or(a),d={fontFamilies:St(n.fontFamily)??St(r),fontSize:se(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:Nr(n.fontWeight)??600,letterSpacing:Ar(n.letterSpacing,-.1,.5)??.01,lineHeight:se(n.lineHeight,.8,2)??1,textTransform:Tr.has(String(n.textTransform))?n.textTransform:"uppercase"},p=Vr(n.padding),f=Dr(n.boxShadow),S=se(n.borderRadius,0,9999),g=typeof n.backdropFilter=="string"?se(Mr.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:be(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:d,...p?{spacing:p}:{},...f?{shadow:f}:{},...S===void 0?{}:{borderRadius:S},disabledOpacity:e?.theme==="night"?.8:.6,...g===void 0?{}:{backdropBlur:g}}}function Ur(e,t=.12){let r=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(r)?`#${r}`:r;return/^#[0-9a-fA-F]{6}$/.test(n)?_e(n,t):e}function Hr(e){if(typeof e=="number"||typeof e=="string")return e}function Et({appearance:e,buttonsStyles:t,layout:r="default"}){let n=e?.variables,o=S=>typeof S=="string"&&S?S:void 0,a=t.submitButton,s=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=r==="buttons",d=t.nameInput,p=o(d?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",f=kt({appearance:e,buttonsStyles:t,fontFamily:p});return{primaryColor:s,primaryHoverColor:o(n?.colorPrimaryHover)??Ur(s,.12),inputBackgroundColor:o(t.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(t.cardInputColor)??o(d?.color)??o(n?.colorText)??"#262833",borderColor:o(t.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(t.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:p,fontSize:o(t.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Hr(d?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...f?{submitButton:f}:{}}}var Ne=require("react/jsx-runtime"),Ce=class extends me.FloPayError{constructor(t,r,n){super(t,r,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ie(e,t={}){let r=e instanceof me.FloPayError?e:void 0,n=r?.statusCode,o=t.retryable??(r?.type==="network_error"||r?.type==="rate_limit_error"||typeof n=="number"&&n>=500||r?.code==="vault_capture_timeout"||!r);return new Ce(r?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),r?.type??"api_error",{code:t.code??r?.code??"card_setup_load_failed",retryable:o,...r?.param?{param:r.param}:{},...n===void 0?{}:{statusCode:n}})}var $e=require("react");var Pe=require("@flopay/js/card-setup"),T=require("@flopay/shared"),u=br(require("react"),1);var xt=require("@flopay/shared"),Wr=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),Yr=new Set(["wallet","apm"]);function ye(e){return typeof e=="string"&&e.trim().length>0}function zr(e){if(typeof e!="object"||e===null)return!1;let t=e;return ye(t.family)&&ye(t.paymentMethodType)}function $r(e){let r=e.raw?.data?.currency;return ye(r)?r.trim().toUpperCase():null}function _t(e){let t=$r(e),r=e.data.session?.advertisedPaymentMethods;if(!Array.isArray(r))return{card:!0,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]};let n={card:!1,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]},o=new Set;for(let a of r){if(!zr(a)||o.has(a.paymentMethodType))continue;let{family:s,paymentMethodType:l,providerType:d,publishableKey:p}=a;if(s==="card"){if(l!=="card")continue;n.card=!0}else if(Yr.has(s)){if(d!=="stripe"||l==="card"||!ye(p))continue;if(t===null){n.skippedForMissingCurrency.includes(l)||n.skippedForMissingCurrency.push(l);continue}n.stripe.push({method:l,publishableKey:p,currency:t})}else if(s==="paypal"){if(l!==xt.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE||d!=="paypal"||!ye(p))continue;n.paypal={clientId:p,...ye(a.environment)?{environment:a.environment}:{}}}else continue;o.add(l)}return n.paypal&&(n.stripe=n.stripe.filter(a=>a.method!=="paypal")),n}function Fe(e){return[...e.card?["card"]:[],...e.stripe.map(t=>t.method),...e.paypal?["paypal"]:[]]}function Mt(e){return Fe(e).length>0}function Te(e){return Wr.has(e)?"wallet":"apm"}var Gr=["setup_intent","setup_intent_client_secret","redirect_status"];function Ft(){if(typeof window>"u")return null;let e=new URLSearchParams(window.location.search);return!e.has("setup_intent")||!e.has("redirect_status")?null:{failed:e.get("redirect_status")==="failed"}}function Tt(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of Gr)e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0);t&&window.history.replaceState(window.history.state,"",e.toString())}function At(e){return e==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}var C=require("react/jsx-runtime"),Kr=15,Xr=2e3;function qr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(t=>setTimeout(t,e))}async function Zr(e,t,r){if(!t.trim())throw new T.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new T.FloPayError("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let n=await e.getUnifiedCheckoutSession(t,r),o=n.data.session;if(!o||!(0,T.isCardSetupCheckoutSession)(o))throw new T.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=_t(n);if(!Mt(a)){let{skippedForMissingCurrency:s}=a,l=s.length>0?`FloPay: this setup session advertises only Stripe methods (${s.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 T.FloPayError(l,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:o,advertisement:a}}async function Jr(e,t,r,n){let o=t.vault??null;if(o?.html?.trim()||(o=await e.getVaultCapture(r,n)),!o.html?.trim())throw new T.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var Ae=class extends u.default.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(r){this.props.onFailed(r,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function Bt({branches:{StripeSetupMethod:e,PayPalSetupMethod:t},sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,theme:s="modern-light",containerStyle:l,loading:d=null,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P}){let[E]=(0,u.useState)(Ft),[m,_]=(0,u.useState)(null),[D,M]=(0,u.useState)(!1),[v,j]=(0,u.useState)(null),[N,R]=(0,u.useState)(null),[W,$]=(0,u.useState)(null),[U,A]=(0,u.useState)(null),[Y,te]=(0,u.useState)(()=>new Set),K=(0,u.useRef)(Y),re=(0,u.useRef)(null);re.current=m;let G=(0,u.useRef)(!1),ue=(0,u.useRef)(!1),ne=(0,u.useRef)(!1),F=(0,u.useRef)(!1),V=(0,u.useRef)(0),L=(0,u.useRef)(0),de=(0,u.useRef)(!1),z=(0,u.useMemo)(()=>typeof s=="object"?void 0:(0,T.resolveTheme)(s),[s]),ur=(0,u.useMemo)(()=>typeof s=="object"?s:z?Et({appearance:z.appearance,buttonsStyles:z.buttonsLayout,layout:"default"}):null,[z,s]),dr=(0,u.useMemo)(()=>dt(z?.buttonsLayout.cardFormContainer,l),[z,l]),Ge=(0,u.useMemo)(()=>z?ft(z):void 0,[z]),O=(0,u.useRef)({sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P});O.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P},(0,u.useEffect)(()=>{de.current=!0;let i=V.current+1;return V.current=i,()=>{de.current=!1,L.current+=1,queueMicrotask(()=>{V.current===i&&(ne.current||F.current||(F.current=!0,q(()=>{O.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let ce=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"success",wording:i,message:null}),(async()=>(await Ue(600),!ue.current&&(ue.current=!0,q(()=>{O.current.onComplete?.({status:"succeeded",sessionId:O.current.sessionId,...c?{paymentMethod:c}:{}})}),de.current&&A(null))))()},[]),pe=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"error",wording:i,message:c.message??null}),q(()=>{O.current.onDecline?.({status:"declined",sessionId:O.current.sessionId,...c.reason?{reason:c.reason}:{},...c.message?{message:c.message}:{}})}),(async()=>(await Ue(400),de.current&&A(null)))()},[]),J=(0,u.useCallback)((i,c)=>{G.current?(G.current=!1,A({status:"error",wording:i,message:c.message}),setTimeout(()=>{de.current&&A(null)},400)):A(null),q(()=>O.current.onError?.(c))},[]),ke=(0,u.useCallback)(async i=>{let c=L.current+1;L.current=c;let h=()=>!de.current||c!==L.current;G.current=!0,A({status:"processing",wording:"payment_method",message:null});let b=new Pe.PaymentAPI((0,T.resolveBillingApiUrl)(O.current.billingApiUrl),{telemetry:O.current.telemetry});try{for(let y=0;y<Kr;y+=1){if((y>0||i.waitFirst)&&await Ue(Xr),h())return;let Q=await b.getUnifiedCheckoutSession(O.current.sessionId,O.current.nonce);if(h())return;let oe=Q.data.session?.status;if(oe==="complete"){M(!0),ce("payment_method");return}if(oe==="expired")throw new T.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new T.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(y){if(h())return;let Q=y instanceof T.FloPayError&&y.code==="payment_method_setup_unverified";J("payment_method",ie(y,Q?{retryable:!0}:{}))}finally{b.destroy()}},[J,ce]);(0,u.useEffect)(()=>{let i=!0,c=new Pe.PaymentAPI((0,T.resolveBillingApiUrl)(o),{telemetry:a});_(null),M(!1),j(null),R(null),$(null);let h=new Set;return K.current=h,te(h),ne.current=!1,F.current=!1,ue.current=!1,(async()=>{try{let{session:b,advertisement:y}=await Zr(c,r,n);if(!i)return;let Q={advertisement:y,customer:qr(b),...b.futureUse?{futureUse:b.futureUse}:{},...b.futureUseUnsupported?{futureUseUnsupported:b.futureUseUnsupported}:{}};if(E){if(Tt(),b.status==="complete"){M(!0),_(Q),ce("payment_method");return}E.failed?pe("payment_method",{reason:"redirect_failed"}):ke({waitFirst:!0})}let oe=y.card?await Jr(c,b,r,n):null;if(!i)return;_(Q),oe&&(R(oe),j(new Pe.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(b){if(!i)return;let y=ie(b);ne.current=!0,$(y),q(()=>O.current.onError?.(y))}})(),()=>{i=!1,c.destroy()}},[o,n,E,pe,ce,r,a,ke]),(0,u.useEffect)(()=>{if(!v)return;G.current=!1;let i=v.on("submitting",()=>{G.current=!0,A({status:"processing",wording:"card",message:null})}),c=v.on("complete",y=>{ce("card",y.paymentMethod)}),h=v.on("decline",y=>{pe("card",{...y.declineReason?{reason:y.declineReason}:{},...y.message?{message:y.message}:{}})}),b=v.on("challenge_dismissed",()=>{A(null)});return()=>{i(),c(),h(),b()}},[v,pe,ce]);let je=(0,u.useCallback)((i,c,h)=>{if(h.retryable){J("payment_method",ie(c,h));return}if(K.current.has(i))return;let b=new Set(K.current);b.add(i),K.current=b,te(b);let y=re.current?.advertisement,Q=y?Fe(y).some(oe=>!b.has(oe)):!1;J("payment_method",ie(c,{code:h.code,retryable:Q}))},[J]),Ke=(0,u.useMemo)(()=>({onSubmitting:()=>{G.current=!0,A({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{ke({waitFirst:!1})},onDeclined:i=>pe("payment_method",i),onValidation:i=>{q(()=>O.current.onValidation?.(i))},onAbandoned:()=>{G.current=!1,A(null)}}),[pe,ke]),Xe=(0,u.useRef)(je);Xe.current=je;let qe=(0,u.useRef)(new Map),Ee=i=>{let c=qe.current.get(i);if(c)return c;let h=(b,y)=>Xe.current(i,b,y);return qe.current.set(i,h),h},Ze=(0,u.useCallback)(i=>{if(K.current.has(i))return;let c=new Set(K.current);c.add(i),K.current=c,te(c);let h=re.current?.advertisement;h&&Fe(h).some(y=>!c.has(y))||J("payment_method",ie(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[J]),Je=(0,u.useRef)(Ze);Je.current=Ze;let Qe=(0,u.useRef)(new Map),et=i=>{let c=Qe.current.get(i);if(c)return c;let h=()=>Je.current(i);return Qe.current.set(i,h),h},tt=U?(0,C.jsx)(mt,{status:U.status,errorMessage:U.message,...At(U.wording),successNote:null,...Ge?{theme:Ge}:{}}):null;if(W)return(0,C.jsx)("div",{role:"alert",children:W.message});if(!m||D)return(0,C.jsxs)(C.Fragment,{children:[tt,m?null:d]});let{advertisement:he,customer:cr,futureUse:rt,futureUseUnsupported:nt}=m,ot=(0,T.resolveBillingApiUrl)(o),at=a===void 0?{}:{telemetry:a},Ie=he.stripe.filter(({method:i})=>!Y.has(i)),Se=Y.has("paypal")?null:he.paypal,st=!!(he.card&&v&&N?.html),it=({method:i,publishableKey:c,currency:h})=>(0,C.jsx)("div",{"data-flopay-payment-method":i,style:{display:"contents"},children:(0,C.jsx)(Ae,{onFailed:Ee(i),children:(0,C.jsx)(u.Suspense,{fallback:null,children:(0,C.jsx)(e,{method:i,category:Te(i),publishableKey:c,currency:h,...rt?{futureUse:rt}:{},...nt?{futureUseUnsupported:nt}:{},sessionId:r,nonce:n,billingApiUrl:ot,...at,...z?{appearance:z.appearance,buttonsLayout:z.buttonsLayout}:{},...typeof s=="string"?{themeId:s}:{},...Ke,onFailed:Ee(i),onUnavailable:et(i)})})})},i),pr=Ie.filter(({method:i})=>Te(i)==="wallet"),fr=Ie.filter(({method:i})=>Te(i)!=="wallet"),lt=Ie.length>0||Se!==null;return(0,C.jsxs)(C.Fragment,{children:[tt,lt?(0,C.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[pr.map(it),Se?(0,C.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,C.jsx)(Ae,{onFailed:Ee("paypal"),children:(0,C.jsx)(u.Suspense,{fallback:null,children:(0,C.jsx)(t,{clientId:Se.clientId,...Se.environment?{environment:Se.environment}:{},...he.currency?{currency:he.currency}:{},sessionId:r,nonce:n,billingApiUrl:ot,customer:cr,...at,...Ke,onFailed:Ee("paypal"),onUnavailable:et("paypal")})})})}):null,fr.map(it)]}):null,st&&lt?(0,C.jsx)(ht,{label:"or add a card"}):null,st&&v&&N?.html?(0,C.jsx)("div",{"data-flopay-payment-method":"card",children:(0,C.jsx)(gt,{capture:v,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,theme:ur,containerStyle:dr,onReady:()=>{q(()=>O.current.onReady?.())},onValidation:i=>{q(()=>O.current.onValidation?.(i))},onError:i=>{i&&J("card",ie(new Error(i),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var lr=require("react/jsx-runtime"),gn={StripeSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(tr(),er)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(sr(),or)).then(e=>({default:e.PayPalSetupMethod})))};function ir(e){return(0,lr.jsx)(Bt,{...e,branches:gn})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
@@ -1 +1 @@
1
- import{a as t}from"./chunk-TGSZFVTH.mjs";import{k as a}from"./chunk-AZRGKPW7.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-VJZMWIHC.mjs").then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:o(()=>import("./payment-method-setup-paypal-FRRQW56L.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-LIYRDFMO.mjs";import{k as a}from"./chunk-AZRGKPW7.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-TI2A5JPE.mjs").then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:o(()=>import("./payment-method-setup-paypal-FRRQW56L.mjs").then(e=>({default:e.PayPalSetupMethod})))};function y(e){return P(t,{...e,branches:p})}export{a as FloPayCardSetupError,y as FloPayPaymentMethodSetup};
@@ -0,0 +1 @@
1
+ import{k as a}from"./chunk-UFFPBTKU.mjs";import"./chunk-M7R46EDF.mjs";export{a as StripeSetupMethod};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/react",
3
- "version": "1.10.6",
3
+ "version": "1.11.1",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -39,8 +39,8 @@
39
39
  "@paypal/paypal-js": "^10.0.0",
40
40
  "@stripe/react-stripe-js": "^6.6.0",
41
41
  "@stripe/stripe-js": "^9.8.0",
42
- "@flopay/js": "1.10.6",
43
- "@flopay/shared": "1.10.6"
42
+ "@flopay/js": "1.11.1",
43
+ "@flopay/shared": "1.11.1"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": ">=18.0.0",
@@ -1 +0,0 @@
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};
@@ -1,22 +0,0 @@
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};
@@ -1 +0,0 @@
1
- import{k as a}from"./chunk-X3EOIUVN.mjs";import"./chunk-M7R46EDF.mjs";export{a as StripeSetupMethod};