@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.
@@ -0,0 +1 @@
1
+ import{a as De,b as Le,c as P,d as Oe,f as Ie,g as Be,j as xe,l as F}from"./chunk-AZRGKPW7.mjs";import{PaymentAPI as Ke,PciVaultCardCapture as lt}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as ut,resolveBillingApiUrl as ae,resolveTheme as ct}from"@flopay/shared";import dt,{Suspense as ze,useCallback as V,useEffect as oe,useMemo as B,useRef as m,useState as w}from"react";import{PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as tt}from"@flopay/shared";var rt=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),nt=new Set(["wallet","apm"]);function U(t){return typeof t=="string"&&t.trim().length>0}function at(t){if(typeof t!="object"||t===null)return!1;let o=t;return U(o.family)&&U(o.paymentMethodType)}function ot(t){let a=t.raw?.data?.currency;return U(a)?a.trim().toUpperCase():null}function Ne(t){let o=ot(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 u of a){if(!at(u)||c.has(u.paymentMethodType))continue;let{family:d,paymentMethodType:f,providerType:x,publishableKey:_}=u;if(d==="card"){if(f!=="card")continue;i.card=!0}else if(nt.has(d)){if(x!=="stripe"||f==="card"||!U(_))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!==tt||x!=="paypal"||!U(_))continue;i.paypal={clientId:_,...U(u.environment)?{environment:u.environment}:{}}}else continue;c.add(f)}return i.paypal&&(i.stripe=i.stripe.filter(u=>u.method!=="paypal")),i}function j(t){return[...t.card?["card"]:[],...t.stripe.map(o=>o.method),...t.paypal?["paypal"]:[]]}function Ye(t){return j(t).length>0}function K(t){return rt.has(t)?"wallet":"apm"}var st=["setup_intent","setup_intent_client_secret","redirect_status"];function We(){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 He(){if(typeof window>"u")return;let t=new URL(window.location.href),o=!1;for(let a of st)t.searchParams.has(a)&&(t.searchParams.delete(a),o=!0);o&&window.history.replaceState(window.history.state,"",t.toString())}function Ge(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 qe,jsx as y,jsxs as ie}from"react/jsx-runtime";var pt=15,mt=2e3;function yt(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function se(t){return new Promise(o=>setTimeout(o,t))}async function ft(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||!ut(c))throw new M("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let u=Ne(i);if(!Ye(u)){let{skippedForMissingCurrency:d}=u,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:u}}async function ht(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 dt.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 kt({branches:{StripeSetupMethod:t,PayPalSetupMethod:o},sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,theme:d="modern-light",containerStyle:f,loading:x=null,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe}){let[q]=w(We),[N,$]=w(null),[$e,J]=w(!1),[g,me]=w(null),[D,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),L=m(!1),te=m(!1),re=m(0),W=m(0),A=m(!1),S=B(()=>typeof d=="object"?void 0:ct(d),[d]),Je=B(()=>typeof d=="object"?d:S?xe({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,d]),Qe=B(()=>De(S?.buttonsLayout.cardFormContainer,f),[S,f]),Se=B(()=>S?Le(S):void 0,[S]),p=m({sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe});p.current={sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,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&&(L.current||te.current||(te.current=!0,P(()=>{p.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let k=V((e,r)=>{L.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=V((e,r)=>{L.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=V((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=V(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 l=new Ke(ae(p.current.billingApiUrl),{telemetry:p.current.telemetry});try{for(let n=0;n<pt;n+=1){if((n>0||e.waitFirst)&&await se(mt),s())return;let b=await l.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{l.destroy()}},[C,k]);oe(()=>{let e=!0,r=new Ke(ae(c),{telemetry:u});$(null),J(!1),me(null),ye(null),he(null);let s=new Set;return R.current=s,X(s),L.current=!1,te.current=!1,ee.current=!1,(async()=>{try{let{session:l,advertisement:n}=await ft(r,a,i);if(!e)return;let b={advertisement:n,customer:yt(l),...l.futureUse?{futureUse:l.futureUse}:{},...l.futureUseUnsupported?{futureUseUnsupported:l.futureUseUnsupported}:{}};if(q){if(He(),l.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 ht(r,l,a,i):null;if(!e)return;$(b),E&&(ye(E),me(new lt({sessionId:a,operation:"card_setup",telemetry:u})))}catch(l){if(!e)return;let n=F(l);L.current=!0,he(n),P(()=>p.current.onError?.(n))}})(),()=>{e=!1,r.destroy()}},[c,i,q,T,k,a,u,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}:{}})}),l=g.on("challenge_dismissed",()=>{h(null)});return()=>{e(),r(),s(),l()}},[g,T,k]);let ge=V((e,r,s)=>{if(s.retryable){C("payment_method",F(r,s));return}if(R.current.has(e))return;let l=new Set(R.current);l.add(e),R.current=l,X(l);let n=Z.current?.advertisement,b=n?j(n).some(E=>!l.has(E)):!1;C("payment_method",F(r,{code:s.code,retryable:b}))},[C]),ve=B(()=>({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=(l,n)=>Pe.current(e,l,n);return Ce.current.set(e,s),s},be=V(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(Oe,{status:Y.status,errorMessage:Y.message,...Ge(Y.wording),successNote:null,...Se?{theme:Se}:{}}):null;if(fe)return y("div",{role:"alert",children:fe.message});if(!N||$e)return ie(qe,{children:[Re,N?null:x]});let{advertisement:O,customer:Xe,futureUse:Ee,futureUseUnsupported:Fe}=N,Ae=ae(c),ke=u===void 0?{}:{telemetry:u},ne=O.stripe.filter(({method:e})=>!Q.has(e)),I=Q.has("paypal")?null:O.paypal,Te=!!(O.card&&g&&D?.html),Ue=({method:e,publishableKey:r,currency:s})=>y("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:y(z,{onFailed:G(e),children:y(ze,{fallback:null,children:y(t,{method:e,category:K(e),publishableKey:r,currency:s,...Ee?{futureUse:Ee}:{},...Fe?{futureUseUnsupported:Fe}:{},sessionId:a,nonce:i,billingApiUrl:Ae,...ke,...S?{appearance:S.appearance,buttonsLayout:S.buttonsLayout}:{},...typeof d=="string"?{themeId:d}:{},...ve,onFailed:G(e),onUnavailable:_e(e)})})})},e),Ze=ne.filter(({method:e})=>K(e)==="wallet"),et=ne.filter(({method:e})=>K(e)!=="wallet"),Ve=ne.length>0||I!==null;return ie(qe,{children:[Re,Ve?ie("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ze.map(Ue),I?y("div",{"data-flopay-payment-method":"paypal",children:y(z,{onFailed:G("paypal"),children:y(ze,{fallback:null,children:y(o,{clientId:I.clientId,...I.environment?{environment:I.environment}:{},...O.currency?{currency:O.currency}:{},sessionId:a,nonce:i,billingApiUrl:Ae,customer:Xe,...ke,...ve,onFailed:G("paypal"),onUnavailable:_e("paypal")})})})}):null,et.map(Ue)]}):null,Te&&Ve?y(Be,{label:"or add a card"}):null,Te&&g&&D?.html?y("div",{"data-flopay-payment-method":"card",children:y(Ie,{capture:g,html:D.html,messageToken:D.messageToken,expectedOrigin:D.expectedOrigin,theme:Je,containerStyle:Qe,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{kt as a};
@@ -0,0 +1,22 @@
1
+ import{a as U,e as N,g as D,i as H,j as X}from"./chunk-M7R46EDF.mjs";import{PaymentAPI as he}from"@flopay/js/card-setup";import{FloPayError as ge,getStripeMethodDisplayName as be,resolveSetupFutureUsage as Se}from"@flopay/shared";import{Elements as ve,ExpressCheckoutElement as Ee,PaymentElement as ke,useElements as xe,useStripe as we}from"@stripe/react-stripe-js";import{loadStripe as Pe}from"@stripe/stripe-js";import{useCallback as Q,useMemo as Re,useRef as _e,useState as b}from"react";import{getStripeMethodDisplayName as z,hasVendoredStripeMethodLogo as pe,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,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:p=!1,hasNextStep:d=!1,onClick:i,backgroundColor:f,borderColor:c,textColor:h,borderRadius:g,fontFamily:w}){let u=de(e,r),S=Y[e],[E,v]=ue(!1),y=!!S&&!E,k=u?.backgroundColor??f??"#ffffff",P=u?.borderColor??c??"#d1d5db",R=u?.textColor??h??"#262833";return s("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!o&&i()},disabled:t||o,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:me,padding:"0 1rem",backgroundColor:k,color:R,border:`1px solid ${P}`,borderRadius:g??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:p?"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:pe(e)?8:0},children:[y?s("img",{src:S,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: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:p,borderRadius:d,style:i,children:f}){return s("button",{type:"button","data-testid":e,...r,onClick:o,disabled:t,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:p,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 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 Ce(e){let r=I.get(e);if(r)return r;let t=Pe(e).catch(o=>{throw I.delete(e),o});return I.set(e,t),t}var Me={night:"night",flat:"flat"};function Te(e){return e?{theme:Me[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function Le(e){return N(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Z(e){return e==="paypal"?"PayPal":be(e)}function Ie(){return typeof window>"u"?"":window.location.href}var Be={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"};function qe(e){let{publishableKey:r,method:t,currency:o,futureUse:p,futureUseUnsupported:d,appearance:i}=e,[f]=b(()=>Ce(r)),c=Re(()=>{let h=Te(i),g=Se({futureUse:p,futureUseUnsupported:d},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:te[t]?.types??[t],...g?{setupFutureUsage:g}:{},...h?{appearance:h}:{}}},[i,o,p,d,t]);return m(ve,{stripe:f,options:c,children:m(Fe,{...e})})}function Fe({method:e,category:r,sessionId:t,nonce:o,billingApiUrl:p,telemetry:d,appearance:i,themeId:f,buttonsLayout:c,onSubmitting:h,onConfirmed:g,onDeclined:w,onFailed:u,onValidation:S,onUnavailable:E}){let v=we(),y=xe(),[k,P]=b(!1),[R,F]=b("loading"),[oe,re]=b(!1),[_,ae]=b(!1),C=_e(!1),[x]=b(()=>H()),[ne,se]=b(!1),M=Q((a,l)=>{if(D(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(l.message===void 0?a:new Error(l.message),{code:l.code,retryable:!0})},[x.inAppBrowser,e,u]),A=Q(async()=>{if(!(!v||!y||C.current)){C.current=!0,P(!0);try{let a=await y.submit();if(a.error){S(a.error.message??null);return}h();let l=await new he(p,{telemetry:d}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(l.provider!=="stripe"||l.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:l.clientSecret,confirmParams:{return_url:Ie()},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,P(!1)}}},[p,r,y,e,o,g,w,h,S,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(r==="wallet"&&T&&!ie)return B(ee,{children:[m(K,{}),m($,{state:R,borderRadius:O,children:m(Ee,{options:{...V,paymentMethods:G([e])},onReady:a=>{let l=W(a,[T]);F(l),l==="unavailable"&&E()},onLoadError:()=>{F("load_error"),E()},onConfirm:()=>{A()}})})]});let le=Z(e);return B(ee,{children:[oe?m(j,{method:e,themeId:f,hasNextStep:!0,highlighted:_,disabled:k,onClick:()=>ae(a=>!a),backgroundColor:c?.cardButton?.backgroundColor,borderColor:c?.cardInputBorder,textColor:c?.cardButton?.color,borderRadius:O}):null,B("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!_,style:_?{display:"flex",flexDirection:"column"}:Be,children:[m(ke,{options:{layout:q},onReady:()=>re(!0),onLoadError:()=>E(),onChange:a=>{a.complete&&S(null)}}),m(J,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!v||!y||k||!_,onClick:()=>{A()},color:i?.variables?.colorPrimary??"#4A49FF",borderRadius:i?.variables?.borderRadius??"8px",style:c?.submitButton,children:k?"Saving\u2026":`Save ${le}`})]})]})}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};