@flopay/react 1.14.8 → 1.14.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -216,7 +216,7 @@ The callback is an allowlisted projection with no card data, tokens, provider ob
216
216
 
217
217
  `FloPayCheckout` reports the same closed FloPay-owned lifecycle, error, and performance contract as `@flopay/js`, including render, interactivity, and provider readiness milestones. No endpoint, custom tag, user context, message, stack, or metadata can be configured, and callback exceptions are only logged to your console. Opt out with `telemetry={false}`.
218
218
 
219
- If Stripe.js cannot initialize after the session resolves, a session that can use the hosted card form still shows it, and Direct PayPal still renders when advertised; only Stripe wallets and alternative methods are omitted. One **Retry payment methods** action retries provider initialization alone, never session creation, claims, intents, or payments. When neither the hosted card form nor Direct PayPal can render, `onError` and the `error` render prop receive `CheckoutInitializationFailed` with fixed buyer-safe copy.
219
+ If Stripe.js cannot initialize after the session resolves, a session that can use the hosted card form still shows it, and Direct PayPal still renders when advertised; only Stripe wallets and alternative methods are omitted. One **Retry payment methods** action retries provider initialization alone, never session creation, claims, intents, or payments. When neither the hosted card form nor Direct PayPal can render, `onError` and the `error` render prop receive a `network_error` with code `provider_load_failed` and `provider: 'stripe'` (earlier releases reported `CheckoutInitializationFailed` here), with fixed buyer-safe copy.
220
220
 
221
221
  Hosts with their own Sentry client can use the re-exported filter as `beforeSend`:
222
222
 
@@ -774,7 +774,9 @@ Checkout errors reach `onError` (and the `error` render prop) as `FloPayError` v
774
774
  | `CaptureMethodUnsupportedForSubscription` | `validation_error` | Manual capture was requested for a cart with a subscription. |
775
775
  | `BuyerEmailCollectionRequired` | `validation_error` | A buyer email supplied to the checkout is not a valid email address. |
776
776
  | `UnsupportedBackendVaultCapability` | `api_error` | The session offers no hosted card form or card capability and no other usable payment method. |
777
- | `CheckoutInitializationFailed` | `api_error` | Neither the hosted card form nor Direct PayPal could render after Stripe.js failed to initialize. |
777
+ | `network_request_failed` | `network_error` | Checkout could not start because creating or reading the checkout session never got a response from Flopay, after the SDK's own retries (the buyer is offline, or a network or browser extension blocked the request). `cause` holds the original error, and `sessionId` is set when the session already existed. Ask the buyer to check their connection and try again. |
778
+ | `provider_load_failed` | `network_error` | A payment provider's script did not load, so checkout could not start. `provider` names it (`stripe` or `paypal`); `cause` holds the original error and `sessionId` is set. When the hosted card form or Direct PayPal can still render without Stripe.js, checkout shows them instead and no error is reported. |
779
+ | `CheckoutInitializationFailed` | `api_error` | Checkout could not start for a reason that is neither a network failure nor a provider script failure, with `sessionId` set once the session exists. |
778
780
  | `paypal_init_timeout` | `api_error` | A PayPal-only checkout could not start PayPal after automatic recovery. The **Retry PayPal** button tries again. |
779
781
  | `external_payment_method_failed` | `api_error` | A wallet, PayPal, or alternative method failed technically after the buyer clicked it. The chooser offers a retry. |
780
782
  | `InvalidCardSetupSurface` | `validation_error` | `FloPayCheckout` was given a card-setup session; use `FloPayCardSetup`. |
@@ -18,7 +18,6 @@ export interface CheckoutProviderFailureTelemetry {
18
18
  }
19
19
  /** Resolve the fixed Stripe provider-load tuple without inspecting free-form data. */
20
20
  export declare function resolveCheckoutProviderFailureTelemetry(error: unknown): CheckoutProviderFailureTelemetry;
21
- export declare function checkoutInitializationError(): FloPayError;
22
21
  export { canRecoverHostedCardForm, hasServerSideCardGateway } from '@flopay/shared';
23
22
  export declare function canRenderWithoutStripe(unified: NormalizedCheckoutSession | null, showPayPal: boolean, showStripe: boolean): boolean;
24
23
  /**
@@ -67,6 +66,16 @@ export declare function buildDeclineEvent(method: CheckoutButtonMethod, input: s
67
66
  code?: string;
68
67
  declineCode?: string;
69
68
  }): DeclineEvent;
69
+ /**
70
+ * Mark an error thrown while a created session's provider scripts loaded, so
71
+ * the create path can report it as `provider_load_failed` rather than as a
72
+ * session-create failure. Returns the same error, for rethrowing.
73
+ */
74
+ export declare function markProviderLoadFailure(error: unknown, sessionId?: string | null): unknown;
75
+ /** The session a provider-load failure belongs to, when `error` is one. */
76
+ export declare function readProviderLoadFailure(error: unknown): {
77
+ sessionId?: string;
78
+ } | undefined;
70
79
  /**
71
80
  * Record which checkout session a failure belongs to (sdk#396), so the error
72
81
  * and any decline event built from it carry the id. Returns the same error;
@@ -126,13 +135,13 @@ export declare function retrievePaymentIntentFromProvider(provider: unknown, cli
126
135
  */
127
136
  export declare function resolveWalletElementsMode(amountInMinorUnits: number | undefined, captureMethod?: CaptureMethod, session?: FutureUseSessionFields | null): {
128
137
  mode: 'setup';
129
- paymentMethodTypes: ['card'];
138
+ allowedPaymentMethodTypes: ['card'];
130
139
  setupFutureUsage?: CardSetupFutureUse;
131
140
  } | {
132
141
  mode: 'payment';
133
142
  amount: number;
134
143
  captureMethod: 'automatic_async' | 'manual';
135
- paymentMethodTypes: ['card'];
144
+ allowedPaymentMethodTypes: ['card'];
136
145
  setupFutureUsage?: CardSetupFutureUse;
137
146
  };
138
147
  /** Bounded cause of a wallet confirmation the provider rejected as invalid. */
@@ -0,0 +1 @@
1
+ import{a as T,b as A,j as I}from"./chunk-VK67324N.mjs";import{PaymentAPI as C}from"@flopay/js/card-setup";import{FloPayError as s,isSettledSessionIntent as x,PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as R,settledSessionIntentError as D}from"@flopay/shared";import{loadScript as O}from"@paypal/paypal-js";import{useEffect as F,useRef as B,useState as L}from"react";import{jsx as Y}from"react/jsx-runtime";function N({clientId:d,environment:o,currency:i,sessionId:n,nonce:l,billingApiUrl:y,telemetry:f,customer:{userId:m,email:P},onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:w}){let b=B(null),t=B({onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:w});t.current={onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:w};let[c]=L(()=>I().inAppBrowser);return F(()=>{let a=!0,k,u=new C(y,{telemetry:f}),g={userId:m,email:P};return(async()=>{try{let p=await O({clientId:d,...i?{currency:i.toUpperCase()}:{},components:"buttons",...o==="sandbox"||o==="production"?{environment:o}:{}}),S=b.current;if(!a||!S)return;if(!p?.Buttons)throw new s("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let E=p.Buttons({createVaultSetupToken:async()=>{t.current.onSubmitting();let e=await u.createSessionIntent(n,l,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:R,paymentMethodId:null,intentKind:"setup"});if(x(e))throw D(n);if(e.provider!=="paypal"||e.providerObjectType!=="setup_token")throw new s("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return e.providerObjectId},onApprove:async e=>{let r=e.vaultSetupToken;if(!r)throw new s("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let M=await u.processPayment(g.userId,{sessionId:n,nonce:l,paymentMethodCategory:"paypal",tokenizedData:{id:r,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:R},accountData:g});if(!M.ok)throw new s("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:M.status});a&&t.current.onConfirmed()},onCancel:()=>{a&&t.current.onAbandoned()},onError:e=>{if(!a)return;let{popupBlocked:r}=A(e,{inAppBrowser:c,handoffObserved:!1});t.current.onFailed(r?new Error(T("PayPal",!0,c)):e,{code:r?"popup_blocked":"paypal_setup_failed",retryable:!0})}});k=()=>E.close(),await E.render(S)}catch(p){if(!a)return;t.current.onFailed(p,{code:"paypal_unavailable",retryable:!0})}})(),()=>{a=!1,k?.().catch(()=>{}),u.destroy()}},[y,d,i,P,o,c,l,n,f,m]),Y("div",{ref:b,"data-flopay-paypal-setup":""})}export{N as a};
@@ -1,4 +1,4 @@
1
- import{a as X,b as Y,h as z,j as K,l as W}from"./chunk-VK67324N.mjs";import{PaymentAPI as ve}from"@flopay/js/card-setup";import{FloPayError as Ee,getStripeMethodDisplayName as ke,resolveSetupFutureUsage as xe,toStripeAppearance as Ce}from"@flopay/shared";import{Elements as we,ExpressCheckoutElement as Pe,PaymentElement as Re,useElements as _e,useStripe as Me}from"@stripe/react-stripe-js";import{loadStripe as Te}from"@stripe/stripe-js";import{useCallback as oe,useMemo as Le,useRef as Be,useState as S}from"react";import{getStripeMethodDisplayName as j,hasVendoredStripeMethodLogo as ye,resolveStripeMethodBrandVariant as me,stripeExpressMethodToOptionKey as fe}from"@flopay/shared";import{useState as he}from"react";var $={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 be,jsx as n,jsxs as A}from"react/jsx-runtime";var ge=`
1
+ import{a as X,b as Y,h as z,j as K,l as W}from"./chunk-VK67324N.mjs";import{PaymentAPI as ve}from"@flopay/js/card-setup";import{FloPayError as Ee,getStripeMethodDisplayName as ke,isSettledSessionIntent as xe,resolveSetupFutureUsage as Ce,settledSessionIntentError as we,toStripeAppearance as Pe}from"@flopay/shared";import{Elements as Re,ExpressCheckoutElement as _e,PaymentElement as Me,useElements as Te,useStripe as Le}from"@stripe/react-stripe-js";import{loadStripe as Ie}from"@stripe/stripe-js";import{useCallback as oe,useMemo as Be,useRef as Fe,useState as S}from"react";import{getStripeMethodDisplayName as j,hasVendoredStripeMethodLogo as ye,resolveStripeMethodBrandVariant as me,stripeExpressMethodToOptionKey as fe}from"@flopay/shared";import{useState as he}from"react";var $={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 be,jsx as n,jsxs as A}from"react/jsx-runtime";var ge=`
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,4 +19,4 @@ import{a as X,b as Y,h as z,j as K,l as W}from"./chunk-VK67324N.mjs";import{Paym
19
19
  0% { opacity: 1; transform: translateX(0) scale(1); }
20
20
  100% { opacity: 0; transform: translateX(16px) scale(0.97); }
21
21
  }
22
- `,Se=44;function G(){return n("style",{children:ge})}function V(e,o){let t=e.availablePaymentMethods;return t&&o.some(r=>t[r])?"ready":"unavailable"}function q({state:e,placeholderTestId:o,borderRadius:t=8,children:r}){return e==="unavailable"||e==="load_error"?null:A("div",{style:{position:"relative",minHeight:44},children:[n("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"}}),n("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 ze(e){return e!=="unavailable"&&e!=="load_error"}function J({method:e,themeId:o,submitting:t=!1,disabled:r=!1,highlighted:l=!1,hasNextStep:p=!1,onClick:s,backgroundColor:f,borderColor:d,textColor:h,borderRadius:g,fontFamily:C}){let c=me(e,o),b=$[e],[E,v]=he(!1),y=!!b&&!E,k=c?.backgroundColor??f??"#ffffff",w=c?.borderColor??d??"#d1d5db",P=c?.textColor??h??"#262833";return n("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!r&&s()},disabled:t||r,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:Se,padding:"0 1rem",backgroundColor:k,color:P,border:`1px solid ${w}`,borderRadius:g??8,fontSize:"0.95rem",fontWeight:600,fontFamily:C,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?n("span",{style:{margin:"0 auto"},children:`Connecting to ${j(e)}\u2026`}):A(be,{children:[A("span",{style:{display:"inline-flex",alignItems:"center",gap:ye(e)?8:0},children:[y?n("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&&c?.logoSvg?n("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:c.logoSvg}}):null,n("span",{children:j(e)})]}),p&&n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:P,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:n("path",{d:"M9 18l6-6-6-6"})})]})})}function Q(e){let o=new Set(e.map(fe));return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(t=>[t,o.has(t)?"auto":"never"]))}var Z={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},ee={type:"accordion",defaultCollapsed:!1,radios:"never"};function te({testId:e,attributes:o,disabled:t,onClick:r,color:l,borderRadius:p,style:s,children:f}){return n("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:p,fontSize:"1rem",fontWeight:600,cursor:t?"not-allowed":"pointer",opacity:t?.5:1,transition:"opacity 120ms ease-out",...s??{}},children:f})}import{Fragment as ae,jsx as m,jsxs as U}from"react/jsx-runtime";var ne={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"}},O=new Map;function Fe(e){let o=O.get(e);if(o)return o;let t=Te(e).catch(r=>{throw O.delete(e),r});return O.set(e,t),t}function Ie(e){return e?Ce(e):void 0}function Ae(e){return z(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function re(e){return e==="paypal"?"PayPal":ke(e)}function Oe(){return typeof window>"u"?"":window.location.href}var Ue={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"};function et(e){let{publishableKey:o,method:t,currency:r,futureUse:l,futureUseUnsupported:p,appearance:s}=e,[f]=S(()=>Fe(o)),d=Le(()=>{let h=Ie(s),g=xe({futureUse:l,futureUseUnsupported:p},t,"setup");return{mode:"setup",currency:r.toLowerCase(),paymentMethodTypes:ne[t]?.types??[t],...g?{setupFutureUsage:g}:{},...h?{appearance:h}:{}}},[s,r,l,p,t]);return m(we,{stripe:f,options:d,children:m(Ne,{...e})})}function Ne({method:e,category:o,sessionId:t,nonce:r,billingApiUrl:l,telemetry:p,appearance:s,themeId:f,buttonsLayout:d,onSubmitting:h,onConfirmed:g,onDeclined:C,onFailed:c,onValidation:b,onUnavailable:E}){let v=Me(),y=_e(),[k,w]=S(!1),[P,N]=S("loading"),[se,ie]=S(!1),[R,le]=S(!1),M=Be(!1),[x]=S(()=>K()),[pe,de]=S(!1),T=oe((a,u)=>{if(Y(a,{inAppBrowser:x.inAppBrowser,handoffObserved:!1}).popupBlocked){de(!0),c(new Error(X(re(e),!0,x.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}c(u.message===void 0?a:new Error(u.message),{code:u.code,retryable:!0})},[x.inAppBrowser,e,c]),D=oe(async a=>{let u=!1,B=!1,F=()=>{!a||u||B||(B=!0,a.paymentFailed({reason:"fail"}))};if(!v||!y||M.current){F();return}M.current=!0,w(!0);try{let _=await y.submit();if(_.error){F(),b(_.error.message??null);return}h();let I=await new ve(l,{telemetry:p}).createSessionIntent(t,r,{provider:"stripe",paymentMethodCategory:o,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(I.provider!=="stripe"||I.intentKind!=="setup")throw new Ee("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});u=!0;let i=await v.confirmSetup({elements:y,clientSecret:I.clientSecret,confirmParams:{return_url:Oe()},redirect:"if_required"});if(i.error){Ae(i.error)?C({...i.error.decline_code||i.error.code?{reason:i.error.decline_code??i.error.code}:{},...i.error.message?{message:i.error.message}:{}}):T(i.error,{code:"payment_method_setup_provider_failed",message:i.error.message??"The payment method could not be saved."});return}g()}catch(_){F(),T(_,{code:"payment_method_setup_failed"})}finally{M.current=!1,w(!1)}},[l,o,y,e,r,g,C,h,b,T,t,v,p]),L=ne[e]?.wallet,ce=L==="paypal"&&W(x,"auto",pe?"blocked":x.popupCapability)==="redirect",H=s?.variables?.borderRadius??d?.cardButton?.borderRadius??8;if(o==="wallet"&&L&&!ce)return U(ae,{children:[m(G,{}),m(q,{state:P,borderRadius:H,children:m(Pe,{options:{...Z,paymentMethods:Q([e])},onReady:a=>{let u=V(a,[L]);N(u),u==="unavailable"&&E()},onLoadError:()=>{N("load_error"),E()},onConfirm:a=>{D(a)}})})]});let ue=re(e);return U(ae,{children:[se?m(J,{method:e,themeId:f,hasNextStep:!0,highlighted:R,disabled:k,onClick:()=>le(a=>!a),backgroundColor:d?.cardButton?.backgroundColor,borderColor:d?.cardInputBorder,textColor:d?.cardButton?.color,borderRadius:H}):null,U("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!R,style:R?{display:"flex",flexDirection:"column"}:Ue,children:[m(Re,{options:{layout:ee},onReady:()=>ie(!0),onLoadError:()=>E(),onChange:a=>{a.complete&&b(null)}}),m(te,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!v||!y||k||!R,onClick:()=>{D()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:k?"Saving\u2026":`Save ${ue}`})]})]})}export{Se as a,G as b,V as c,q as d,ze as e,J as f,Q as g,Z as h,ee as i,te as j,et as k};
22
+ `,Se=44;function G(){return n("style",{children:ge})}function V(e,o){let t=e.availablePaymentMethods;return t&&o.some(r=>t[r])?"ready":"unavailable"}function q({state:e,placeholderTestId:o,borderRadius:t=8,children:r}){return e==="unavailable"||e==="load_error"?null:A("div",{style:{position:"relative",minHeight:44},children:[n("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"}}),n("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 We(e){return e!=="unavailable"&&e!=="load_error"}function J({method:e,themeId:o,submitting:t=!1,disabled:r=!1,highlighted:l=!1,hasNextStep:p=!1,onClick:s,backgroundColor:f,borderColor:d,textColor:h,borderRadius:g,fontFamily:C}){let c=me(e,o),b=$[e],[E,v]=he(!1),y=!!b&&!E,k=c?.backgroundColor??f??"#ffffff",w=c?.borderColor??d??"#d1d5db",P=c?.textColor??h??"#262833";return n("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!r&&s()},disabled:t||r,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:Se,padding:"0 1rem",backgroundColor:k,color:P,border:`1px solid ${w}`,borderRadius:g??8,fontSize:"0.95rem",fontWeight:600,fontFamily:C,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?n("span",{style:{margin:"0 auto"},children:`Connecting to ${j(e)}\u2026`}):A(be,{children:[A("span",{style:{display:"inline-flex",alignItems:"center",gap:ye(e)?8:0},children:[y?n("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&&c?.logoSvg?n("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:c.logoSvg}}):null,n("span",{children:j(e)})]}),p&&n("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:P,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:n("path",{d:"M9 18l6-6-6-6"})})]})})}function Q(e){let o=new Set(e.map(fe));return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(t=>[t,o.has(t)?"auto":"never"]))}var Z={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},ee={type:"accordion",defaultCollapsed:!1,radios:"never"};function te({testId:e,attributes:o,disabled:t,onClick:r,color:l,borderRadius:p,style:s,children:f}){return n("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:p,fontSize:"1rem",fontWeight:600,cursor:t?"not-allowed":"pointer",opacity:t?.5:1,transition:"opacity 120ms ease-out",...s??{}},children:f})}import{Fragment as ae,jsx as m,jsxs as U}from"react/jsx-runtime";var ne={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"}},O=new Map;function Ae(e){let o=O.get(e);if(o)return o;let t=Ie(e).catch(r=>{throw O.delete(e),r});return O.set(e,t),t}function Oe(e){return e?Pe(e):void 0}function Ue(e){return z(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function re(e){return e==="paypal"?"PayPal":ke(e)}function Ne(){return typeof window>"u"?"":window.location.href}var De={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"};function ot(e){let{publishableKey:o,method:t,currency:r,futureUse:l,futureUseUnsupported:p,appearance:s}=e,[f]=S(()=>Ae(o)),d=Be(()=>{let h=Oe(s),g=Ce({futureUse:l,futureUseUnsupported:p},t,"setup");return{mode:"setup",currency:r.toLowerCase(),allowedPaymentMethodTypes:ne[t]?.types??[t],...g?{setupFutureUsage:g}:{},...h?{appearance:h}:{}}},[s,r,l,p,t]);return m(Re,{stripe:f,options:d,children:m(He,{...e})})}function He({method:e,category:o,sessionId:t,nonce:r,billingApiUrl:l,telemetry:p,appearance:s,themeId:f,buttonsLayout:d,onSubmitting:h,onConfirmed:g,onDeclined:C,onFailed:c,onValidation:b,onUnavailable:E}){let v=Le(),y=Te(),[k,w]=S(!1),[P,N]=S("loading"),[se,ie]=S(!1),[R,le]=S(!1),T=Fe(!1),[x]=S(()=>K()),[pe,de]=S(!1),L=oe((a,u)=>{if(Y(a,{inAppBrowser:x.inAppBrowser,handoffObserved:!1}).popupBlocked){de(!0),c(new Error(X(re(e),!0,x.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}c(u.message===void 0?a:new Error(u.message),{code:u.code,retryable:!0})},[x.inAppBrowser,e,c]),D=oe(async a=>{let u=!1,B=!1,F=()=>{!a||u||B||(B=!0,a.paymentFailed({reason:"fail"}))};if(!v||!y||T.current){F();return}T.current=!0,w(!0);try{let _=await y.submit();if(_.error){F(),b(_.error.message??null);return}h();let M=await new ve(l,{telemetry:p}).createSessionIntent(t,r,{provider:"stripe",paymentMethodCategory:o,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(xe(M))throw we(t);if(M.provider!=="stripe"||M.intentKind!=="setup")throw new Ee("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});u=!0;let i=await v.confirmSetup({elements:y,clientSecret:M.clientSecret,confirmParams:{return_url:Ne()},redirect:"if_required"});if(i.error){Ue(i.error)?C({...i.error.decline_code||i.error.code?{reason:i.error.decline_code??i.error.code}:{},...i.error.message?{message:i.error.message}:{}}):L(i.error,{code:"payment_method_setup_provider_failed",message:i.error.message??"The payment method could not be saved."});return}g()}catch(_){F(),L(_,{code:"payment_method_setup_failed"})}finally{T.current=!1,w(!1)}},[l,o,y,e,r,g,C,h,b,L,t,v,p]),I=ne[e]?.wallet,ce=I==="paypal"&&W(x,"auto",pe?"blocked":x.popupCapability)==="redirect",H=s?.variables?.borderRadius??d?.cardButton?.borderRadius??8;if(o==="wallet"&&I&&!ce)return U(ae,{children:[m(G,{}),m(q,{state:P,borderRadius:H,children:m(_e,{options:{...Z,paymentMethods:Q([e])},onReady:a=>{let u=V(a,[I]);N(u),u==="unavailable"&&E()},onLoadError:()=>{N("load_error"),E()},onConfirm:a=>{D(a)}})})]});let ue=re(e);return U(ae,{children:[se?m(J,{method:e,themeId:f,hasNextStep:!0,highlighted:R,disabled:k,onClick:()=>le(a=>!a),backgroundColor:d?.cardButton?.backgroundColor,borderColor:d?.cardInputBorder,textColor:d?.cardButton?.color,borderRadius:H}):null,U("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!R,style:R?{display:"flex",flexDirection:"column"}:De,children:[m(Me,{options:{layout:ee},onReady:()=>ie(!0),onLoadError:()=>E(),onChange:a=>{a.complete&&b(null)}}),m(te,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!v||!y||k||!R,onClick:()=>{D()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:k?"Saving\u2026":`Save ${ue}`})]})]})}export{Se as a,G as b,V as c,q as d,We as e,J as f,Q as g,Z as h,ee as i,te as j,ot as k};