@flopay/react 1.12.1 → 1.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/card-setup-entry.cjs +2 -2
- package/dist/card-setup-entry.mjs +1 -1
- package/dist/chunk-D4CVZRT4.mjs +1 -0
- package/dist/{chunk-XVCGDHF2.mjs → chunk-YR36EYW2.mjs} +2 -2
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/payment-method-setup-entry.cjs +3 -3
- package/dist/payment-method-setup-entry.d.cts +2 -2
- package/dist/payment-method-setup-entry.d.ts +2 -2
- package/dist/payment-method-setup-entry.mjs +1 -1
- package/dist/{payment-method-setup-surface-Zf-DUxA0.d.ts → payment-method-setup-surface-B9TI-00C.d.ts} +30 -3
- package/dist/{payment-method-setup-surface-BQltFPXs.d.cts → payment-method-setup-surface-DWGNLM0I.d.cts} +30 -3
- package/package.json +3 -3
- package/dist/chunk-4DGIEZ4S.mjs +0 -1
package/README.md
CHANGED
|
@@ -237,7 +237,7 @@ export function AddBrandedCard(props: { sessionId: string; nonce: string; theme:
|
|
|
237
237
|
|
|
238
238
|
### FloPayPaymentMethodSetup
|
|
239
239
|
|
|
240
|
-
`FloPayPaymentMethodSetup` lets a customer save any payment method the setup session offers, not only a card, without a purchase or charge. It takes the same `sessionId` and `nonce` as `FloPayCardSetup`, and the same callbacks, `theme` and `
|
|
240
|
+
`FloPayPaymentMethodSetup` lets a customer save any payment method the setup session offers, not only a card, without a purchase or charge. It takes the same `sessionId` and `nonce` as `FloPayCardSetup`, and the same callbacks, `theme`, `containerStyle`, `appearance` and `buttonsStyles`.
|
|
241
241
|
|
|
242
242
|
- **The session decides what renders.** The component renders exactly the methods the setup session lists in `advertisedPaymentMethods`, and nothing else. It never reads the purchase-checkout `gateways` block, which lists nothing on a setup session. A `card` entry mounts the hosted card form. A `wallet` or `apm` entry from Stripe renders that method with Stripe Elements in setup mode, using that entry's own `publishableKey`. A `paypal` entry (`paypal_vaulted`) renders the PayPal vault flow, with the entry's key as the client id and its `environment`. An unknown family or type is skipped without an error, and the first entry for a method wins. A session without the field (an older backend) renders the card form only, exactly like `FloPayCardSetup`. An empty list reports `NoAdvertisedPaymentMethods`. The SDK does no gateway selection, filtering or inference. Each rendered method's wrapper carries `data-flopay-payment-method="<method>"`.
|
|
243
243
|
- **Laid out like checkout.** Wallets come first, then PayPal, then one tile per alternative method, then an `or add a card` rule and the hosted card form. The wallet buttons, the method tiles, the inline form a tile opens and its `Save …` button are the components `FloPayCheckout` draws, so a buyer sees the same thing whether paying or saving a method. A tile appears only once Stripe has confirmed it can render that method, and its form opens when the tile is pressed.
|
|
@@ -247,6 +247,7 @@ export function AddBrandedCard(props: { sessionId: string; nonce: string; theme:
|
|
|
247
247
|
- **Card-only sessions behave exactly like `FloPayCardSetup`.** They use the same hosted form, overlay wording (`SAVING CARD...`, `CARD SAVED`, `CARD NOT SAVED`) and callbacks, and never request Stripe.js. Stripe.js loads lazily, only when the session advertises a Stripe wallet or alternative method. A PayPal-only session never loads Stripe either.
|
|
248
248
|
- **Success is the backend's call.** `onComplete` fires once, only after the billing API reports the setup verified. For a wallet, alternative method or PayPal, provider approval alone is not success: the component re-reads the session until it completes. A decline, cancel or failure leaves previously saved methods unchanged; the component never lists, replaces or deletes saved methods.
|
|
249
249
|
- **Redirect methods return to the same page.** When the buyer comes back from a bank or wallet redirect (Stripe's `setup_intent` and `redirect_status` query parameters), the component re-reads the session. A completed session reports `onComplete`, and `redirect_status=failed` reports `onDecline`. Anything else waits for verification. The query parameters are removed once read. The hosted card path never posts `/3ds/complete`.
|
|
250
|
+
- **Stored themes style every method.** `theme`, `appearance` and `buttonsStyles` resolve exactly as in the stored themes of `FloPayCardSetup`: `appearance` replaces the preset's, `buttonsStyles` merges over the preset's buttons layout, and empty `{}` groups count as absent. The result styles the hosted card form, its container and the outcome overlay as on `FloPayCardSetup`, and also the other methods: the Stripe Elements of every wallet and alternative method receive the effective `appearance`, and the method tiles and their `Save …` buttons take their colors, border and radius from the effective `buttonsStyles` (`cardButton`, `cardInputBorder`, `submitButton`) and `appearance` (`colorPrimary`, `borderRadius`), as checkout draws them; a method with its own brand colors keeps them, as in checkout. Pass a client's saved embed theme the same way as to `FloPayCardSetup`. With raw `VaultCardThemeColors` the overrides are ignored and only the hosted card form is themed; with `classic` and no overrides, the other methods keep their unthemed look. The PayPal vault button is drawn by PayPal in its own brand style, as in checkout.
|
|
250
251
|
- **Wording.** Outcomes for non-card methods read `SAVING PAYMENT METHOD...`, `PAYMENT METHOD SAVED` and `PAYMENT METHOD NOT SAVED`.
|
|
251
252
|
- Import it from `@flopay/react/payment-method-setup` to keep Stripe off card-only and PayPal-only pages. The main entry re-exports it, but its module graph eagerly loads Stripe.js.
|
|
252
253
|
|
|
@@ -606,7 +607,7 @@ export function ComposedCheckout({ session, nonce }: { session: CheckoutSession;
|
|
|
606
607
|
|
|
607
608
|
### FloPayPaymentMethodSetupProps
|
|
608
609
|
|
|
609
|
-
The same props as `FloPayCardSetupProps`,
|
|
610
|
+
The same props as `FloPayCardSetupProps`. `theme`, `appearance`, `buttonsStyles`, `containerStyle`, `onReady` and `onValidation` apply to the hosted card form as they do there; `theme`, `appearance` and `buttonsStyles` also style the Stripe Elements, wallet buttons and method tiles of advertised wallets and alternative methods.
|
|
610
611
|
|
|
611
612
|
| Prop | Type | Description |
|
|
612
613
|
|------|------|-------------|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var $=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var
|
|
1
|
+
"use strict";var $=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var Se=(e,r)=>{for(var t in r)$(e,t,{get:r[t],enumerable:!0})},he=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of ge(r))!Ce.call(e,i)&&i!==t&&$(e,i,{get:()=>r[i],enumerable:!(o=ye(r,i))||o.enumerable});return e};var ve=e=>he($({},"__esModule",{value:!0}),e);var Te={};Se(Te,{FloPayCardSetup:()=>fe,FloPayCardSetupError:()=>z});module.exports=ve(Te);var q=require("@flopay/js/card-setup"),l=require("@flopay/shared"),n=require("react");var J=require("@flopay/shared"),Re=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 be(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Re.has(r.charAt(0).toLowerCase()+r.slice(1))}function Ee(e,r){return typeof r=="number"&&r!==0&&!be(e)?`${r}px`:String(r).trim()}function se(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]=Ee(t,o)}}}var K=require("@flopay/shared"),we=require("@flopay/shared");function ie(e){let r=(0,K.resolveCardSetupTheme)(e);return{...r,surface:r.surface,overlayTheme:r.overlayTheme}}var S=require("@flopay/shared");var a=require("react/jsx-runtime");var Pe={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function le({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:i,errorLabel:p="PAYMENT FAILED",successNote:b="You will be automatically redirected, do not close or navigate away from this window.",theme:m=Pe}){let E={fontSize:13,color:m.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,a.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,a.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...m.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,a.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,a.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,a.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:m.spinnerTrackColor,strokeWidth:"3"}),(0,a.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:m.spinnerAccentColor})]}),e==="success"&&(0,a.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,a.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,a.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,a.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,a.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,a.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,a.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,a.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,a.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:m.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(i??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&p]}),e==="success"&&b!==null&&(0,a.jsx)("p",{style:E,children:b}),e==="error"&&r&&(0,a.jsx)("p",{style:E,children:r}),(0,a.jsx)("style",{children:`
|
|
2
2
|
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
3
|
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
4
|
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
5
|
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}var d=require("react");var H=require("react"),ue=typeof window>"u"?H.useEffect:H.useLayoutEffect;var ee=require("react/jsx-runtime"),Q=new WeakSet;function ce({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:i,theme:p,submitLabel:b,containerStyle:m,onReady:E,onError:L,onValidation:_}){let
|
|
6
|
+
`})]})})}var d=require("react");var H=require("react"),ue=typeof window>"u"?H.useEffect:H.useLayoutEffect;var ee=require("react/jsx-runtime"),Q=new WeakSet;function ce({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:i,theme:p,submitLabel:b,containerStyle:m,onReady:E,onError:L,onValidation:_}){let P=(0,d.useRef)(null),M=(0,d.useRef)(E),x=(0,d.useRef)(L),V=(0,d.useRef)(_);M.current=E,x.current=L,V.current=_;let u=(0,d.useRef)(p);u.current=p;let T=(0,d.useRef)(null),c=b??void 0,w=(0,d.useRef)(c);w.current=c;let k=(0,d.useRef)(void 0);return(0,d.useEffect)(()=>{let h=P.current;if(!h)return;let O=!0,y=!1,B=()=>{!O||y||(y=!0,M.current?.())},D=e.on("ready",()=>{B()}),v=e.on("error",C=>{x.current?.(C.message??"There was a problem loading the secure card form.")}),I=e.on("validation",C=>{V.current?.(C.message??null)}),Y=w.current??(Q.has(e)?null:void 0),G={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...i?{verificationRequired:!0}:{},...u.current?{theme:u.current}:{},...Y===void 0?{}:{submitLabel:Y}};return T.current=u.current??null,k.current=w.current,w.current!==void 0&&Q.add(e),e.mount(h,G).then(()=>{B()}).catch(C=>{O&&x.current?.(C instanceof Error?C.message:"Failed to load the secure card form.")}),()=>{O=!1,D(),v(),I(),e.unmount()}},[e,r,t,o,i]),ue(()=>{let h=P.current;h&&se(h,m)},[m]),(0,d.useEffect)(()=>{p!==void 0&&(p===null&&T.current===null||(T.current=p,e.applyTheme?.(p)))},[e,p]),(0,d.useEffect)(()=>{c!==k.current&&(k.current=c,c!==void 0&&Q.add(e),e.setSubmitLabel?.(c??null))},[e,c]),(0,ee.jsx)("div",{ref:P,"data-testid":"flopay-vault-card-fields"})}var g=require("react/jsx-runtime"),z=class extends l.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function pe(e,r={}){let t=e instanceof l.FloPayError?e:void 0,o=t?.statusCode,i=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof o=="number"&&o>=500||t?.code==="vault_capture_timeout"||!t);return new z(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:i,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}function fe({sessionId:e,nonce:r,billingApiUrl:t,telemetry:o,theme:i="modern-light",containerStyle:p,appearance:b,buttonsStyles:m,loading:E=null,onReady:L,onComplete:_,onDecline:P,onCancel:M,onValidation:x,onError:V}){let[u,T]=(0,n.useState)(null),[c,w]=(0,n.useState)(null),[k,h]=(0,n.useState)(null),[O,y]=(0,n.useState)(null),[B,D]=(0,n.useState)(null),v=(0,n.useRef)(!1),I=(0,n.useRef)(!1),{vaultTheme:Y,surface:G,overlayTheme:C}=(0,n.useMemo)(()=>ie({theme:i,appearance:b,buttonsStyles:m}),[i,b,m]),me=(0,n.useMemo)(()=>(0,J.mergeCardSetupSurface)(G,p),[G,p]),re=(0,n.useRef)(L),X=(0,n.useRef)(V),te=(0,n.useRef)(_),oe=(0,n.useRef)(P),ne=(0,n.useRef)(M),ae=(0,n.useRef)(x),N=(0,n.useRef)(!1),j=(0,n.useRef)(!1),Z=(0,n.useRef)(0);return re.current=L,X.current=V,te.current=_,oe.current=P,ne.current=M,ae.current=x,(0,n.useEffect)(()=>{let s=Z.current+1;return Z.current=s,()=>{queueMicrotask(()=>{Z.current===s&&(N.current||j.current||(j.current=!0,(0,S.invokeMerchantCallback)(()=>{ne.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,n.useEffect)(()=>{let s=!0,F=(0,l.resolveBillingApiUrl)(t),U=new q.PaymentAPI(F,{telemetry:o});return T(null),w(null),h(null),N.current=!1,j.current=!1,(async()=>{try{if(!e.trim())throw new l.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new l.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let W=await U.getUnifiedCheckoutSession(e,r);if(!s)return;let R=W.data.session;if(!R||!(0,l.isCardSetupCheckoutSession)(R))throw new l.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let f=R.vault;(0,l.isMountableVaultBlock)(f)||(f=await U.getVaultCapture(e,r));let A=(0,l.resolveVaultMountOptions)(f,{billingApiUrl:F,sessionId:e,nonce:r});if(!A)throw new l.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!s)return;w(A),T(new q.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:o}))}catch(W){if(!s)return;let R=pe(W);N.current=!0,h(R),(0,S.invokeMerchantCallback)(()=>X.current?.(R))}})(),()=>{s=!1,U.destroy()}},[t,r,e,o]),(0,n.useEffect)(()=>{if(!u)return;let s=!1;I.current=!1,v.current=!1;let F=u.on("submitting",()=>{v.current=!0,D(null),y("processing")}),U=u.on("complete",f=>{N.current=!0,v.current=!1,y("success"),(async()=>(await new Promise(A=>setTimeout(A,600)),!I.current&&(I.current=!0,(0,S.invokeMerchantCallback)(()=>{te.current?.({status:"succeeded",sessionId:e,...f.paymentMethod?{paymentMethod:f.paymentMethod}:{}})}),s||y(null))))()}),W=u.on("decline",f=>{N.current=!0,v.current=!1,D(f.message??null),y("error"),(0,S.invokeMerchantCallback)(()=>{oe.current?.({status:"declined",sessionId:e,...f.declineReason?{reason:f.declineReason}:{},...f.message?{message:f.message}:{}})}),(async()=>(await new Promise(A=>setTimeout(A,400)),s||y(null)))()}),R=u.on("challenge_dismissed",()=>{y(null)});return()=>{s=!0,F(),U(),W(),R()}},[u,e]),k?(0,g.jsx)("div",{role:"alert",children:k.message}):!u||!c?.html?(0,g.jsx)(g.Fragment,{children:E}):(0,g.jsxs)(g.Fragment,{children:[O&&(0,g.jsx)(le,{status:O,errorMessage:B,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...C?{theme:C}:{}}),(0,g.jsx)(ce,{capture:u,html:c.html,messageToken:c.messageToken,expectedOrigin:c.expectedOrigin,verificationRequired:c.verificationRequired,theme:Y,containerStyle:me,onReady:()=>{(0,S.invokeMerchantCallback)(()=>re.current?.())},onValidation:s=>{(0,S.invokeMerchantCallback)(()=>ae.current?.(s))},onError:s=>{if(!s)return;v.current&&(v.current=!1,D(s),y("error"),setTimeout(()=>y(null),400));let F=pe(new Error(s),{code:"card_setup_widget_failed",retryable:!0});(0,S.invokeMerchantCallback)(()=>X.current?.(F))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as e,j as t}from"./chunk-
|
|
1
|
+
import{h as e,j as t}from"./chunk-YR36EYW2.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as xe,b as De,c as g,d as Le,f as Ne,g as We,i as R}from"./chunk-YR36EYW2.mjs";import{PaymentAPI as ze,PciVaultCardCapture as ot}from"@flopay/js/card-setup";import{FloPayError as b,isCardSetupCheckoutSession as st,isMountableVaultBlock as it,resolveBillingApiUrl as Z,resolveVaultMountOptions as lt}from"@flopay/shared";import ut,{Suspense as $e,useCallback as k,useEffect as ee,useMemo as te,useRef as l,useState as P}from"react";import{clearSetupRedirectParams as Ye,readSetupRedirectReturn as qe}from"@flopay/js/card-setup";import{advertisedMethodKeys as X,advertisesAnyMethod as Ge,readSetupAdvertisement as Ke,setupOverlayLabels as je,stripeMethodCategory as N}from"@flopay/shared";import{Fragment as Je,jsx as d,jsxs as ne}from"react/jsx-runtime";var dt=15,ct=2e3;function pt(p){return{userId:p.customer?.id??"",email:p.customer?.email??""}}function re(p){return new Promise(h=>setTimeout(h,p))}async function mt(p,h,a){if(!h.trim())throw new b("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new b("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let u=await p.getUnifiedCheckoutSession(h,a),m=u.data.session;if(!m||!st(m))throw new b("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let o=Ke(u);if(!Ge(o)){let{skippedForMissingCurrency:f}=o,V=f.length>0?`FloPay: this setup session advertises only Stripe methods (${f.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 b(V,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:m,advertisement:o}}async function yt(p,h,a,u,m){let o=h.vault??null;it(o)||(o=await p.getVaultCapture(a,u));let f=lt(o,{billingApiUrl:m,sessionId:a,nonce:u});if(!f)throw new b("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return f}var W=class extends ut.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(a){this.props.onFailed(a,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function Et({branches:{StripeSetupMethod:p,PayPalSetupMethod:h},sessionId:a,nonce:u,billingApiUrl:m,telemetry:o,theme:f="modern-light",containerStyle:V,appearance:ae,buttonsStyles:oe,loading:Qe=null,onReady:se,onComplete:ie,onDecline:le,onCancel:ue,onValidation:de,onError:ce}){let[Y]=P(qe),[I,q]=P(null),[Xe,G]=P(!1),[v,pe]=P(null),[w,me]=P(null),[ye,fe]=P(null),[T,c]=P(null),[K,j]=P(()=>new Set),F=l(K),H=l(null);H.current=I;let S=l(!1),z=l(!1),A=l(!1),$=l(!1),J=l(0),x=l(0),_=l(!1),{vaultTheme:Ze,surface:he,overlayTheme:ve,appearance:Se,buttonsLayout:ge}=te(()=>De({theme:f,appearance:ae,buttonsStyles:oe}),[f,ae,oe]),et=te(()=>xe(he,V),[he,V]),s=l({sessionId:a,nonce:u,billingApiUrl:m,telemetry:o,onReady:se,onComplete:ie,onDecline:le,onCancel:ue,onValidation:de,onError:ce});s.current={sessionId:a,nonce:u,billingApiUrl:m,telemetry:o,onReady:se,onComplete:ie,onDecline:le,onCancel:ue,onValidation:de,onError:ce},ee(()=>{_.current=!0;let e=J.current+1;return J.current=e,()=>{_.current=!1,x.current+=1,queueMicrotask(()=>{J.current===e&&(A.current||$.current||($.current=!0,g(()=>{s.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let E=k((e,t)=>{A.current=!0,S.current=!1,c({status:"success",wording:e,message:null}),(async()=>(await re(600),!z.current&&(z.current=!0,g(()=>{s.current.onComplete?.({status:"succeeded",sessionId:s.current.sessionId,...t?{paymentMethod:t}:{}})}),_.current&&c(null))))()},[]),U=k((e,t)=>{A.current=!0,S.current=!1,c({status:"error",wording:e,message:t.message??null}),g(()=>{s.current.onDecline?.({status:"declined",sessionId:s.current.sessionId,...t.reason?{reason:t.reason}:{},...t.message?{message:t.message}:{}})}),(async()=>(await re(400),_.current&&c(null)))()},[]),C=k((e,t)=>{S.current?(S.current=!1,c({status:"error",wording:e,message:t.message}),setTimeout(()=>{_.current&&c(null)},400)):c(null),g(()=>s.current.onError?.(t))},[]),D=k(async e=>{let t=x.current+1;x.current=t;let n=()=>!_.current||t!==x.current;S.current=!0,c({status:"processing",wording:"payment_method",message:null});let i=new ze(Z(s.current.billingApiUrl),{telemetry:s.current.telemetry});try{for(let r=0;r<dt;r+=1){if((r>0||e.waitFirst)&&await re(ct),n())return;let y=await i.getUnifiedCheckoutSession(s.current.sessionId,s.current.nonce);if(n())return;let M=y.data.session?.status;if(M==="complete"){G(!0),E("payment_method");return}if(M==="expired")throw new b("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new b("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(r){if(n())return;let y=r instanceof b&&r.code==="payment_method_setup_unverified";C("payment_method",R(r,y?{retryable:!0}:{}))}finally{i.destroy()}},[C,E]);ee(()=>{let e=!0,t=Z(m),n=new ze(t,{telemetry:o});q(null),G(!1),pe(null),me(null),fe(null);let i=new Set;return F.current=i,j(i),A.current=!1,$.current=!1,z.current=!1,(async()=>{try{let{session:r,advertisement:y}=await mt(n,a,u);if(!e)return;let M={advertisement:y,customer:pt(r),...r.futureUse?{futureUse:r.futureUse}:{},...r.futureUseUnsupported?{futureUseUnsupported:r.futureUseUnsupported}:{}};if(Y){if(Ye(),r.status==="complete"){G(!0),q(M),E("payment_method");return}Y.failed?U("payment_method",{reason:"redirect_failed"}):D({waitFirst:!0})}let Te=y.card?await yt(n,r,a,u,t):null;if(!e)return;q(M),Te&&(me(Te),pe(new ot({sessionId:a,operation:"card_setup",telemetry:o})))}catch(r){if(!e)return;let y=R(r);A.current=!0,fe(y),g(()=>s.current.onError?.(y))}})(),()=>{e=!1,n.destroy()}},[m,u,Y,U,E,a,o,D]),ee(()=>{if(!v)return;S.current=!1;let e=v.on("submitting",()=>{S.current=!0,c({status:"processing",wording:"card",message:null})}),t=v.on("complete",r=>{E("card",r.paymentMethod)}),n=v.on("decline",r=>{U("card",{...r.declineReason?{reason:r.declineReason}:{},...r.message?{message:r.message}:{}})}),i=v.on("challenge_dismissed",()=>{c(null)});return()=>{e(),t(),n(),i()}},[v,U,E]);let Ce=k((e,t,n)=>{if(n.retryable){C("payment_method",R(t,n));return}if(F.current.has(e))return;let i=new Set(F.current);i.add(e),F.current=i,j(i);let r=H.current?.advertisement,y=r?X(r).some(M=>!i.has(M)):!1;C("payment_method",R(t,{code:n.code,retryable:y}))},[C]),Pe=te(()=>({onSubmitting:()=>{S.current=!0,c({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{D({waitFirst:!1})},onDeclined:e=>U("payment_method",e),onValidation:e=>{g(()=>s.current.onValidation?.(e))},onAbandoned:()=>{S.current=!1,c(null)}}),[U,D]),be=l(Ce);be.current=Ce;let Fe=l(new Map),L=e=>{let t=Fe.current.get(e);if(t)return t;let n=(i,r)=>be.current(e,i,r);return Fe.current.set(e,n),n},Me=k(e=>{if(F.current.has(e))return;let t=new Set(F.current);t.add(e),F.current=t,j(t);let n=H.current?.advertisement;n&&X(n).some(r=>!t.has(r))||C("payment_method",R(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[C]),Re=l(Me);Re.current=Me;let we=l(new Map),_e=e=>{let t=we.current.get(e);if(t)return t;let n=()=>Re.current(e);return we.current.set(e,n),n},Ee=T?d(Le,{status:T.status,errorMessage:T.message,...je(T.wording),successNote:null,...ve?{theme:ve}:{}}):null;if(ye)return d("div",{role:"alert",children:ye.message});if(!I||Xe)return ne(Je,{children:[Ee,I?null:Qe]});let{advertisement:B,customer:tt,futureUse:Ue,futureUseUnsupported:ke}=I,Ae=Z(m),Be=o===void 0?{}:{telemetry:o},Q=B.stripe.filter(({method:e})=>!K.has(e)),O=K.has("paypal")?null:B.paypal,Oe=!!(B.card&&v&&w?.html),Ve=({method:e,publishableKey:t,currency:n})=>d("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:d(W,{onFailed:L(e),children:d($e,{fallback:null,children:d(p,{method:e,category:N(e),publishableKey:t,currency:n,...Ue?{futureUse:Ue}:{},...ke?{futureUseUnsupported:ke}:{},sessionId:a,nonce:u,billingApiUrl:Ae,...Be,...Se?{appearance:Se}:{},...ge?{buttonsLayout:ge}:{},...typeof f=="string"?{themeId:f}:{},...Pe,onFailed:L(e),onUnavailable:_e(e)})})})},e),rt=Q.filter(({method:e})=>N(e)==="wallet"),nt=Q.filter(({method:e})=>N(e)!=="wallet"),Ie=Q.length>0||O!==null;return ne(Je,{children:[Ee,Ie?ne("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[rt.map(Ve),O?d("div",{"data-flopay-payment-method":"paypal",children:d(W,{onFailed:L("paypal"),children:d($e,{fallback:null,children:d(h,{clientId:O.clientId,...O.environment?{environment:O.environment}:{},...B.currency?{currency:B.currency}:{},sessionId:a,nonce:u,billingApiUrl:Ae,customer:tt,...Be,...Pe,onFailed:L("paypal"),onUnavailable:_e("paypal")})})})}):null,nt.map(Ve)]}):null,Oe&&Ie?d(We,{label:"or add a card"}):null,Oe&&v&&w?.html?d("div",{"data-flopay-payment-method":"card",children:d(Ne,{capture:v,html:w.html,messageToken:w.messageToken,expectedOrigin:w.expectedOrigin,verificationRequired:w.verificationRequired,theme:Ze,containerStyle:et,onReady:()=>{g(()=>s.current.onReady?.())},onValidation:e=>{g(()=>s.current.onValidation?.(e))},onError:e=>{e&&C("card",R(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{Et as a};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{useEffect as $,useRef as h}from"react";import{mergeCardSetupSurface as se}from"@flopay/shared";var ge=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 Ce(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return ge.has(r.charAt(0).toLowerCase()+r.slice(1))}function he(e,r){return typeof r=="number"&&r!==0&&!Ce(e)?`${r}px`:String(r).trim()}function ae(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]=he(t,o)}}}import{useEffect as Se,useLayoutEffect as ve}from"react";var ie=typeof window>"u"?Se:ve;import{jsx as H,jsxs as Re}from"react/jsx-runtime";var J=new WeakSet;function le({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:f,theme:i,submitLabel:v,containerStyle:c,onReady:R,onError:F,onValidation:_}){let E=h(null),M=h(R),w=h(F),V=h(_);M.current=R,w.current=F,V.current=_;let a=h(i);a.current=i;let x=h(null),s=v??void 0,b=h(s);b.current=s;let
|
|
1
|
+
import{useEffect as $,useRef as h}from"react";import{mergeCardSetupSurface as se}from"@flopay/shared";var ge=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 Ce(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return ge.has(r.charAt(0).toLowerCase()+r.slice(1))}function he(e,r){return typeof r=="number"&&r!==0&&!Ce(e)?`${r}px`:String(r).trim()}function ae(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]=he(t,o)}}}import{useEffect as Se,useLayoutEffect as ve}from"react";var ie=typeof window>"u"?Se:ve;import{jsx as H,jsxs as Re}from"react/jsx-runtime";var J=new WeakSet;function le({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:f,theme:i,submitLabel:v,containerStyle:c,onReady:R,onError:F,onValidation:_}){let E=h(null),M=h(R),w=h(F),V=h(_);M.current=R,w.current=F,V.current=_;let a=h(i);a.current=i;let x=h(null),s=v??void 0,b=h(s);b.current=s;let P=h(void 0);return $(()=>{let y=E.current;if(!y)return;let T=!0,d=!1,B=()=>{!T||d||(d=!0,M.current?.())},D=e.on("ready",()=>{B()}),g=e.on("error",m=>{w.current?.(m.message??"There was a problem loading the secure card form.")}),I=e.on("validation",m=>{V.current?.(m.message??null)}),Y=b.current??(J.has(e)?null:void 0),G={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...f?{verificationRequired:!0}:{},...a.current?{theme:a.current}:{},...Y===void 0?{}:{submitLabel:Y}};return x.current=a.current??null,P.current=b.current,b.current!==void 0&&J.add(e),e.mount(y,G).then(()=>{B()}).catch(m=>{T&&w.current?.(m instanceof Error?m.message:"Failed to load the secure card form.")}),()=>{T=!1,D(),g(),I(),e.unmount()}},[e,r,t,o,f]),ie(()=>{let y=E.current;y&&ae(y,c)},[c]),$(()=>{i!==void 0&&(i===null&&x.current===null||(x.current=i,e.applyTheme?.(i)))},[e,i]),$(()=>{s!==P.current&&(P.current=s,s!==void 0&&J.add(e),e.setSubmitLabel?.(s??null))},[e,s]),H("div",{ref:E,"data-testid":"flopay-vault-card-fields"})}function Ue({label:e}){return Re("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[H("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),H("span",{children:e}),H("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}import{PaymentAPI as xe,PciVaultCardCapture as Pe}from"@flopay/js/card-setup";import{FloPayError as L,isCardSetupCheckoutSession as Te,isMountableVaultBlock as ke,resolveBillingApiUrl as Oe,resolveVaultMountOptions as Ae}from"@flopay/shared";import{useEffect as K,useMemo as pe,useRef as p,useState as z}from"react";import{computeCardSetupOverlayTheme as Ye,resolveCardSetupTheme as be}from"@flopay/shared";import{mergeButtonsStyles as qe}from"@flopay/shared";function ue(e){let r=be(e);return{...r,surface:r.surface,overlayTheme:r.overlayTheme}}import{invokeMerchantCallback as S}from"@flopay/shared";import{jsx as u,jsxs as A}from"react/jsx-runtime";var Ee={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ce({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:f,errorLabel:i="PAYMENT FAILED",successNote:v="You will be automatically redirected, do not close or navigate away from this window.",theme:c=Ee}){let R={fontSize:13,color:c.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return u("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:A("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...c.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[A("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&A("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:[u("circle",{cx:"12",cy:"12",r:"10",stroke:c.spinnerTrackColor,strokeWidth:"3"}),u("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:c.spinnerAccentColor})]}),e==="success"&&u("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:A("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[u("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),u("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"&&u("div",{style:{animation:"flopay-shake 0.4s ease"},children:A("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[u("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),u("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"}})]})})]}),A("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:c.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(f??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&v!==null&&u("p",{style:R,children:v}),e==="error"&&r&&u("p",{style:R,children:r}),u("style",{children:`
|
|
2
2
|
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
3
|
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
4
|
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
5
|
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}import{Fragment as me,jsx as q,jsxs as
|
|
6
|
+
`})]})})}import{Fragment as me,jsx as q,jsxs as Le}from"react/jsx-runtime";var Q=class extends L{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function fe(e,r={}){let t=e instanceof L?e:void 0,o=t?.statusCode,f=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof o=="number"&&o>=500||t?.code==="vault_capture_timeout"||!t);return new Q(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:f,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}function ar({sessionId:e,nonce:r,billingApiUrl:t,telemetry:o,theme:f="modern-light",containerStyle:i,appearance:v,buttonsStyles:c,loading:R=null,onReady:F,onComplete:_,onDecline:E,onCancel:M,onValidation:w,onError:V}){let[a,x]=z(null),[s,b]=z(null),[P,y]=z(null),[T,d]=z(null),[B,D]=z(null),g=p(!1),I=p(!1),{vaultTheme:Y,surface:G,overlayTheme:m}=pe(()=>ue({theme:f,appearance:v,buttonsStyles:c}),[f,v,c]),ye=pe(()=>se(G,i),[G,i]),ee=p(F),X=p(V),re=p(_),te=p(E),oe=p(M),ne=p(w),N=p(!1),j=p(!1),Z=p(0);return ee.current=F,X.current=V,re.current=_,te.current=E,oe.current=M,ne.current=w,K(()=>{let n=Z.current+1;return Z.current=n,()=>{queueMicrotask(()=>{Z.current===n&&(N.current||j.current||(j.current=!0,S(()=>{oe.current?.({status:"cancelled",sessionId:e})})))})}},[e]),K(()=>{let n=!0,k=Oe(t),U=new xe(k,{telemetry:o});return x(null),b(null),y(null),N.current=!1,j.current=!1,(async()=>{try{if(!e.trim())throw new L("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new L("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let W=await U.getUnifiedCheckoutSession(e,r);if(!n)return;let C=W.data.session;if(!C||!Te(C))throw new L("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let l=C.vault;ke(l)||(l=await U.getVaultCapture(e,r));let O=Ae(l,{billingApiUrl:k,sessionId:e,nonce:r});if(!O)throw new L("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!n)return;b(O),x(new Pe({sessionId:e,operation:"card_setup",telemetry:o}))}catch(W){if(!n)return;let C=fe(W);N.current=!0,y(C),S(()=>X.current?.(C))}})(),()=>{n=!1,U.destroy()}},[t,r,e,o]),K(()=>{if(!a)return;let n=!1;I.current=!1,g.current=!1;let k=a.on("submitting",()=>{g.current=!0,D(null),d("processing")}),U=a.on("complete",l=>{N.current=!0,g.current=!1,d("success"),(async()=>(await new Promise(O=>setTimeout(O,600)),!I.current&&(I.current=!0,S(()=>{re.current?.({status:"succeeded",sessionId:e,...l.paymentMethod?{paymentMethod:l.paymentMethod}:{}})}),n||d(null))))()}),W=a.on("decline",l=>{N.current=!0,g.current=!1,D(l.message??null),d("error"),S(()=>{te.current?.({status:"declined",sessionId:e,...l.declineReason?{reason:l.declineReason}:{},...l.message?{message:l.message}:{}})}),(async()=>(await new Promise(O=>setTimeout(O,400)),n||d(null)))()}),C=a.on("challenge_dismissed",()=>{d(null)});return()=>{n=!0,k(),U(),W(),C()}},[a,e]),P?q("div",{role:"alert",children:P.message}):!a||!s?.html?q(me,{children:R}):Le(me,{children:[T&&q(ce,{status:T,errorMessage:B,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...m?{theme:m}:{}}),q(le,{capture:a,html:s.html,messageToken:s.messageToken,expectedOrigin:s.expectedOrigin,verificationRequired:s.verificationRequired,theme:Y,containerStyle:ye,onReady:()=>{S(()=>ee.current?.())},onValidation:n=>{S(()=>ne.current?.(n))},onError:n=>{if(!n)return;g.current&&(g.current=!1,D(n),d("error"),setTimeout(()=>d(null),400));let k=fe(new Error(n),{code:"card_setup_widget_failed",retryable:!0});S(()=>X.current?.(k))}})]})}export{se as a,ue as b,S as c,ce as d,ie as e,le as f,Ue as g,Q as h,fe as i,ar as j};
|