@flopay/react 1.14.2 → 1.14.4

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