@flopay/react 1.11.6 → 1.12.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.
- package/README.md +35 -2
- package/dist/card-setup-entry.cjs +2 -2
- package/dist/card-setup-entry.d.cts +31 -8
- package/dist/card-setup-entry.d.ts +31 -8
- package/dist/card-setup-entry.mjs +1 -1
- package/dist/chunk-4DGIEZ4S.mjs +1 -0
- package/dist/chunk-XVCGDHF2.mjs +6 -0
- package/dist/index.cjs +9 -9
- package/dist/index.mjs +6 -6
- package/dist/payment-method-setup-entry.cjs +3 -3
- package/dist/payment-method-setup-entry.mjs +1 -1
- package/package.json +3 -3
- package/dist/chunk-KKA5TF5P.mjs +0 -6
- package/dist/chunk-Q5RE4G4O.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var Kt=Object.create;var
|
|
1
|
+
"use strict";var Kt=Object.create;var we=Object.defineProperty;var Xt=Object.getOwnPropertyDescriptor;var jt=Object.getOwnPropertyNames;var qt=Object.getPrototypeOf,$t=Object.prototype.hasOwnProperty;var he=(e,r)=>()=>(e&&(r=e(e=0)),r);var Te=(e,r)=>{for(var t in r)we(e,t,{get:r[t],enumerable:!0})},st=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of jt(r))!$t.call(e,s)&&s!==t&&we(e,s,{get:()=>r[s],enumerable:!(o=Xt(r,s))||o.enumerable});return e};var Zt=(e,r,t)=>(t=e!=null?Kt(qt(e)):{},st(r||!e||!e.__esModule?we(t,"default",{value:e,enumerable:!0}):t,e)),Jt=e=>st(we({},"__esModule",{value:!0}),e);var b,De=he(()=>{"use strict";b=require("@flopay/shared")});var dr,be,_e,Ve=he(()=>{"use strict";dr=require("@flopay/shared"),be=require("@flopay/shared"),_e=require("@flopay/shared")});var ht,gt=he(()=>{"use strict";ht={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 vt(){return(0,k.jsx)("style",{children:pr})}function Ct(e,r){let t=e.availablePaymentMethods;return t&&r.some(o=>t[o])?"ready":"unavailable"}function Pt({state:e,placeholderTestId:r,borderRadius:t=8,children:o}){return e==="unavailable"||e==="load_error"?null:(0,k.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,k.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,k.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 bt({method:e,themeId:r,submitting:t=!1,disabled:o=!1,highlighted:s=!1,hasNextStep:i=!1,onClick:u,backgroundColor:p,borderColor:g,textColor:_,borderRadius:F,fontFamily:V}){let E=(0,ee.resolveStripeMethodBrandVariant)(e,r),T=ht[e],[R,C]=(0,St.useState)(!1),c=!!T&&!R,S=E?.backgroundColor??p??"#ffffff",L=E?.borderColor??g??"#d1d5db",I=E?.textColor??_??"#262833";return(0,k.jsx)("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!o&&u()},disabled:t||o,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:cr,padding:"0 1rem",backgroundColor:S,color:I,border:`1px solid ${L}`,borderRadius:F??8,fontSize:"0.95rem",fontWeight:600,fontFamily:V,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,k.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,ee.getStripeMethodDisplayName)(e)}\u2026`}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,ee.hasVendoredStripeMethodLogo)(e)?8:0},children:[c?(0,k.jsx)("img",{src:T,alt:"","aria-hidden":"true",onError:()=>C(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!c&&E?.logoSvg?(0,k.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:E.logoSvg}}):null,(0,k.jsx)("span",{children:(0,ee.getStripeMethodDisplayName)(e)})]}),i&&(0,k.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,k.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function Et(e){let r=new Set(e.map(ee.stripeExpressMethodToOptionKey)),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"]))}function kt({testId:e,attributes:r,disabled:t,onClick:o,color:s,borderRadius:i,style:u,children:p}){return(0,k.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",...u??{}},children:p})}var ee,St,k,pr,cr,Rt,wt,Mt=he(()=>{"use strict";ee=require("@flopay/shared"),St=require("react");gt();k=require("react/jsx-runtime"),pr=`
|
|
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
|
-
`,pr=44;wt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},Rt={type:"accordion",defaultCollapsed:!1,radios:"never"}});var At={};Ae(At,{StripeSetupMethod:()=>gr});function cr(e){let r=Ve.get(e);if(r)return r;let t=(0,Ft.loadStripe)(e).catch(o=>{throw Ve.delete(e),o});return Ve.set(e,t),t}function mr(e){return e?(0,oe.toStripeAppearance)(e):void 0}function yr(e){return(0,P.isProviderDecline)(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function _t(e){return e==="paypal"?"PayPal":(0,oe.getStripeMethodDisplayName)(e)}function fr(){return typeof window>"u"?"":window.location.href}function gr(e){let{publishableKey:r,method:t,currency:o,futureUse:s,futureUseUnsupported:i,appearance:u}=e,[p]=(0,D.useState)(()=>cr(r)),g=(0,D.useMemo)(()=>{let x=mr(u),F=(0,oe.resolveSetupFutureUsage)({futureUse:s,futureUseUnsupported:i},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:Tt[t]?.types??[t],...F?{setupFutureUsage:F}:{},...x?{appearance:x}:{}}},[u,o,s,i,t]);return(0,O.jsx)(Q.Elements,{stripe:p,options:g,children:(0,O.jsx)(Sr,{...e})})}function Sr({method:e,category:r,sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,appearance:u,themeId:p,buttonsLayout:g,onSubmitting:x,onConfirmed:F,onDeclined:V,onFailed:E,onValidation:T,onUnavailable:w}){let C=(0,Q.useStripe)(),c=(0,Q.useElements)(),[S,L]=(0,D.useState)(!1),[I,y]=(0,D.useState)("loading"),[X,N]=(0,D.useState)(!1),[b,H]=(0,D.useState)(!1),j=(0,D.useRef)(!1),[G]=(0,D.useState)(()=>(0,Ee.detectPayPalEnvironment)()),[M,ae]=(0,D.useState)(!1),Y=(0,D.useCallback)((_,W)=>{if((0,P.classifyExternalMethodFailure)(_,{inAppBrowser:G.inAppBrowser,handoffObserved:!1}).popupBlocked){ae(!0),E(new Error((0,P.buildExternalMethodRecoveryMessage)(_t(e),!0,G.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}E(W.message===void 0?_:new Error(W.message),{code:W.code,retryable:!0})},[G.inAppBrowser,e,E]),Z=(0,D.useCallback)(async()=>{if(!(!C||!c||j.current)){j.current=!0,L(!0);try{let _=await c.submit();if(_.error){T(_.error.message??null);return}x();let W=await new xt.PaymentAPI(s,{telemetry:i}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(W.provider!=="stripe"||W.intentKind!=="setup")throw new oe.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let A=await C.confirmSetup({elements:c,clientSecret:W.clientSecret,confirmParams:{return_url:fr()},redirect:"if_required"});if(A.error){yr(A.error)?V({...A.error.decline_code||A.error.code?{reason:A.error.decline_code??A.error.code}:{},...A.error.message?{message:A.error.message}:{}}):Y(A.error,{code:"payment_method_setup_provider_failed",message:A.error.message??"The payment method could not be saved."});return}F()}catch(_){Y(_,{code:"payment_method_setup_failed"})}finally{j.current=!1,L(!1)}}},[s,r,c,e,o,F,V,x,T,Y,t,C,i]),se=Tt[e]?.wallet,q=se==="paypal"&&(0,Fe.resolveStripePayPalPresentation)(G,"auto",M?"blocked":G.popupCapability)==="redirect",ce=u?.variables?.borderRadius??g?.cardButton?.borderRadius??8;if(r==="wallet"&&se&&!q)return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(vt,{}),(0,O.jsx)(bt,{state:I,borderRadius:ce,children:(0,O.jsx)(Q.ExpressCheckoutElement,{options:{...wt,paymentMethods:Et([e])},onReady:_=>{let W=Ct(_,[se]);y(W),W==="unavailable"&&w()},onLoadError:()=>{y("load_error"),w()},onConfirm:()=>{Z()}})})]});let ie=_t(e);return(0,O.jsxs)(O.Fragment,{children:[X?(0,O.jsx)(Pt,{method:e,themeId:p,hasNextStep:!0,highlighted:b,disabled:S,onClick:()=>H(_=>!_),backgroundColor:g?.cardButton?.backgroundColor,borderColor:g?.cardInputBorder,textColor:g?.cardButton?.color,borderRadius:ce}):null,(0,O.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!b,style:b?{display:"flex",flexDirection:"column"}:hr,children:[(0,O.jsx)(Q.PaymentElement,{options:{layout:Rt},onReady:()=>N(!0),onLoadError:()=>w(),onChange:_=>{_.complete&&T(null)}}),(0,O.jsx)(kt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!C||!c||S||!b,onClick:()=>{Z()},color:u?.variables?.colorPrimary??"#4A49FF",borderRadius:u?.variables?.borderRadius??"8px",style:g?.submitButton,children:S?"Saving\u2026":`Save ${ie}`})]})]})}var xt,oe,Q,Ft,D,O,Tt,Ve,hr,Ot=he(()=>{"use strict";xt=require("@flopay/js/card-setup"),oe=require("@flopay/shared"),Q=require("@stripe/react-stripe-js"),Ft=require("@stripe/stripe-js"),D=require("react");Ue();De();Mt();O=require("react/jsx-runtime"),Tt={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"}},Ve=new Map;hr={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var Bt={};Ae(Bt,{PayPalSetupMethod:()=>vr});function vr({clientId:e,environment:r,currency:t,sessionId:o,nonce:s,billingApiUrl:i,telemetry:u,customer:{userId:p,email:g},onSubmitting:x,onConfirmed:F,onFailed:V,onAbandoned:E}){let T=(0,pe.useRef)(null),w=(0,pe.useRef)({onSubmitting:x,onConfirmed:F,onFailed:V,onAbandoned:E});w.current={onSubmitting:x,onConfirmed:F,onFailed:V,onAbandoned:E};let[C]=(0,pe.useState)(()=>(0,Ee.detectPayPalEnvironment)().inAppBrowser);return(0,pe.useEffect)(()=>{let c=!0,S,L=new Lt.PaymentAPI(i,{telemetry:u}),I={userId:p,email:g};return(async()=>{try{let y=await(0,It.loadScript)({clientId:e,...t?{currency:t.toUpperCase()}:{},components:"buttons",...r==="sandbox"||r==="production"?{environment:r}:{}}),X=T.current;if(!c||!X)return;if(!y?.Buttons)throw new ne.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=y.Buttons({createVaultSetupToken:async()=>{w.current.onSubmitting();let b=await L.createSessionIntent(o,s,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:ne.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(b.provider!=="paypal"||b.providerObjectType!=="setup_token")throw new ne.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return b.providerObjectId},onApprove:async b=>{let H=b.vaultSetupToken;if(!H)throw new ne.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let j=await L.processPayment(I.userId,{sessionId:o,nonce:s,paymentMethodCategory:"paypal",tokenizedData:{id:H,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:ne.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:I});if(!j.ok)throw new ne.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:j.status});c&&w.current.onConfirmed()},onCancel:()=>{c&&w.current.onAbandoned()},onError:b=>{if(!c)return;let{popupBlocked:H}=(0,P.classifyExternalMethodFailure)(b,{inAppBrowser:C,handoffObserved:!1});w.current.onFailed(H?new Error((0,P.buildExternalMethodRecoveryMessage)("PayPal",!0,C)):b,{code:H?"popup_blocked":"paypal_setup_failed",retryable:!0})}});S=()=>N.close(),await N.render(X)}catch(y){if(!c)return;w.current.onFailed(y,{code:"paypal_unavailable",retryable:!0})}})(),()=>{c=!1,S?.().catch(()=>{}),L.destroy()}},[i,e,t,g,r,C,s,o,u,p]),(0,Ut.jsx)("div",{ref:T,"data-flopay-paypal-setup":""})}var Lt,ne,It,pe,Ut,Dt=he(()=>{"use strict";Lt=require("@flopay/js/card-setup"),ne=require("@flopay/shared"),It=require("@paypal/paypal-js"),pe=require("react");Ue();De();Ut=require("react/jsx-runtime")});var br={};Ae(br,{FloPayCardSetupError:()=>be,FloPayPaymentMethodSetup:()=>Vt});module.exports=Jt(br);var mt=require("@flopay/js/card-setup"),re=require("@flopay/shared"),_e=require("react");var Oe=require("@flopay/shared"),Qt=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 er(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Qt.has(r.charAt(0).toLowerCase()+r.slice(1))}function tr(e,r){return typeof r=="number"&&r!==0&&!er(e)?`${r}px`:String(r).trim()}function st(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]=tr(t,o)}}}var it=require("@flopay/shared");function lt(e){return(0,it.computeCardSetupOverlayTheme)(e)}var J=require("@flopay/shared");var v=require("react/jsx-runtime");var rr={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ut({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:s,errorLabel:i="PAYMENT FAILED",successNote:u="You will be automatically redirected, do not close or navigate away from this window.",theme:p=rr}){let g={fontSize:13,color:p.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,v.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,v.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,v.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:p.spinnerTrackColor,strokeWidth:"3"}),(0,v.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:p.spinnerAccentColor})]}),e==="success"&&(0,v.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,v.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,v.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,v.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,v.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"&&u!==null&&(0,v.jsx)("p",{style:g,children:u}),e==="error"&&r&&(0,v.jsx)("p",{style:g,children:r}),(0,v.jsx)("style",{children:`
|
|
22
|
+
`,cr=44;Rt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},wt={type:"accordion",defaultCollapsed:!1,radios:"never"}});var At={};Te(At,{StripeSetupMethod:()=>Sr});function mr(e){let r=Ne.get(e);if(r)return r;let t=(0,Ft.loadStripe)(e).catch(o=>{throw Ne.delete(e),o});return Ne.set(e,t),t}function yr(e){return e?(0,re.toStripeAppearance)(e):void 0}function fr(e){return(0,b.isProviderDecline)(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function xt(e){return e==="paypal"?"PayPal":(0,re.getStripeMethodDisplayName)(e)}function hr(){return typeof window>"u"?"":window.location.href}function Sr(e){let{publishableKey:r,method:t,currency:o,futureUse:s,futureUseUnsupported:i,appearance:u}=e,[p]=(0,D.useState)(()=>mr(r)),g=(0,D.useMemo)(()=>{let _=yr(u),F=(0,re.resolveSetupFutureUsage)({futureUse:s,futureUseUnsupported:i},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:Tt[t]?.types??[t],...F?{setupFutureUsage:F}:{},..._?{appearance:_}:{}}},[u,o,s,i,t]);return(0,O.jsx)(Q.Elements,{stripe:p,options:g,children:(0,O.jsx)(vr,{...e})})}function vr({method:e,category:r,sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,appearance:u,themeId:p,buttonsLayout:g,onSubmitting:_,onConfirmed:F,onDeclined:V,onFailed:E,onValidation:T,onUnavailable:R}){let C=(0,Q.useStripe)(),c=(0,Q.useElements)(),[S,L]=(0,D.useState)(!1),[I,y]=(0,D.useState)("loading"),[X,N]=(0,D.useState)(!1),[P,H]=(0,D.useState)(!1),j=(0,D.useRef)(!1),[G]=(0,D.useState)(()=>(0,be.detectPayPalEnvironment)()),[M,ne]=(0,D.useState)(!1),Y=(0,D.useCallback)((x,W)=>{if((0,b.classifyExternalMethodFailure)(x,{inAppBrowser:G.inAppBrowser,handoffObserved:!1}).popupBlocked){ne(!0),E(new Error((0,b.buildExternalMethodRecoveryMessage)(xt(e),!0,G.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}E(W.message===void 0?x:new Error(W.message),{code:W.code,retryable:!0})},[G.inAppBrowser,e,E]),Z=(0,D.useCallback)(async()=>{if(!(!C||!c||j.current)){j.current=!0,L(!0);try{let x=await c.submit();if(x.error){T(x.error.message??null);return}_();let W=await new _t.PaymentAPI(s,{telemetry:i}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(W.provider!=="stripe"||W.intentKind!=="setup")throw new re.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let A=await C.confirmSetup({elements:c,clientSecret:W.clientSecret,confirmParams:{return_url:hr()},redirect:"if_required"});if(A.error){fr(A.error)?V({...A.error.decline_code||A.error.code?{reason:A.error.decline_code??A.error.code}:{},...A.error.message?{message:A.error.message}:{}}):Y(A.error,{code:"payment_method_setup_provider_failed",message:A.error.message??"The payment method could not be saved."});return}F()}catch(x){Y(x,{code:"payment_method_setup_failed"})}finally{j.current=!1,L(!1)}}},[s,r,c,e,o,F,V,_,T,Y,t,C,i]),ae=Tt[e]?.wallet,q=ae==="paypal"&&(0,_e.resolveStripePayPalPresentation)(G,"auto",M?"blocked":G.popupCapability)==="redirect",ce=u?.variables?.borderRadius??g?.cardButton?.borderRadius??8;if(r==="wallet"&&ae&&!q)return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(vt,{}),(0,O.jsx)(Pt,{state:I,borderRadius:ce,children:(0,O.jsx)(Q.ExpressCheckoutElement,{options:{...Rt,paymentMethods:Et([e])},onReady:x=>{let W=Ct(x,[ae]);y(W),W==="unavailable"&&R()},onLoadError:()=>{y("load_error"),R()},onConfirm:()=>{Z()}})})]});let se=xt(e);return(0,O.jsxs)(O.Fragment,{children:[X?(0,O.jsx)(bt,{method:e,themeId:p,hasNextStep:!0,highlighted:P,disabled:S,onClick:()=>H(x=>!x),backgroundColor:g?.cardButton?.backgroundColor,borderColor:g?.cardInputBorder,textColor:g?.cardButton?.color,borderRadius:ce}):null,(0,O.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!P,style:P?{display:"flex",flexDirection:"column"}:gr,children:[(0,O.jsx)(Q.PaymentElement,{options:{layout:wt},onReady:()=>N(!0),onLoadError:()=>R(),onChange:x=>{x.complete&&T(null)}}),(0,O.jsx)(kt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!C||!c||S||!P,onClick:()=>{Z()},color:u?.variables?.colorPrimary??"#4A49FF",borderRadius:u?.variables?.borderRadius??"8px",style:g?.submitButton,children:S?"Saving\u2026":`Save ${se}`})]})]})}var _t,re,Q,Ft,D,O,Tt,Ne,gr,Ot=he(()=>{"use strict";_t=require("@flopay/js/card-setup"),re=require("@flopay/shared"),Q=require("@stripe/react-stripe-js"),Ft=require("@stripe/stripe-js"),D=require("react");De();Ve();Mt();O=require("react/jsx-runtime"),Tt={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;gr={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var Bt={};Te(Bt,{PayPalSetupMethod:()=>Cr});function Cr({clientId:e,environment:r,currency:t,sessionId:o,nonce:s,billingApiUrl:i,telemetry:u,customer:{userId:p,email:g},onSubmitting:_,onConfirmed:F,onFailed:V,onAbandoned:E}){let T=(0,pe.useRef)(null),R=(0,pe.useRef)({onSubmitting:_,onConfirmed:F,onFailed:V,onAbandoned:E});R.current={onSubmitting:_,onConfirmed:F,onFailed:V,onAbandoned:E};let[C]=(0,pe.useState)(()=>(0,be.detectPayPalEnvironment)().inAppBrowser);return(0,pe.useEffect)(()=>{let c=!0,S,L=new Lt.PaymentAPI(i,{telemetry:u}),I={userId:p,email:g};return(async()=>{try{let y=await(0,It.loadScript)({clientId:e,...t?{currency:t.toUpperCase()}:{},components:"buttons",...r==="sandbox"||r==="production"?{environment:r}:{}}),X=T.current;if(!c||!X)return;if(!y?.Buttons)throw new oe.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=y.Buttons({createVaultSetupToken:async()=>{R.current.onSubmitting();let P=await L.createSessionIntent(o,s,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:oe.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(P.provider!=="paypal"||P.providerObjectType!=="setup_token")throw new oe.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return P.providerObjectId},onApprove:async P=>{let H=P.vaultSetupToken;if(!H)throw new oe.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let j=await L.processPayment(I.userId,{sessionId:o,nonce:s,paymentMethodCategory:"paypal",tokenizedData:{id:H,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:oe.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:I});if(!j.ok)throw new oe.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:j.status});c&&R.current.onConfirmed()},onCancel:()=>{c&&R.current.onAbandoned()},onError:P=>{if(!c)return;let{popupBlocked:H}=(0,b.classifyExternalMethodFailure)(P,{inAppBrowser:C,handoffObserved:!1});R.current.onFailed(H?new Error((0,b.buildExternalMethodRecoveryMessage)("PayPal",!0,C)):P,{code:H?"popup_blocked":"paypal_setup_failed",retryable:!0})}});S=()=>N.close(),await N.render(X)}catch(y){if(!c)return;R.current.onFailed(y,{code:"paypal_unavailable",retryable:!0})}})(),()=>{c=!1,S?.().catch(()=>{}),L.destroy()}},[i,e,t,g,r,C,s,o,u,p]),(0,Ut.jsx)("div",{ref:T,"data-flopay-paypal-setup":""})}var Lt,oe,It,pe,Ut,Dt=he(()=>{"use strict";Lt=require("@flopay/js/card-setup"),oe=require("@flopay/shared"),It=require("@paypal/paypal-js"),pe=require("react");De();Ve();Ut=require("react/jsx-runtime")});var br={};Te(br,{FloPayCardSetupError:()=>Ce,FloPayPaymentMethodSetup:()=>Vt});module.exports=Jt(br);var mt=require("@flopay/js/card-setup"),ue=require("@flopay/shared"),Me=require("react");var Ae=require("@flopay/shared"),Qt=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 er(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Qt.has(r.charAt(0).toLowerCase()+r.slice(1))}function tr(e,r){return typeof r=="number"&&r!==0&&!er(e)?`${r}px`:String(r).trim()}function it(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]=tr(t,o)}}}var Oe=require("@flopay/shared"),rr=require("@flopay/shared");function lt(e){return(0,Oe.computeCardSetupOverlayTheme)(e)}var J=require("@flopay/shared");var v=require("react/jsx-runtime");var or={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ut({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:s,errorLabel:i="PAYMENT FAILED",successNote:u="You will be automatically redirected, do not close or navigate away from this window.",theme:p=or}){let g={fontSize:13,color:p.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,v.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,v.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,v.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:p.spinnerTrackColor,strokeWidth:"3"}),(0,v.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:p.spinnerAccentColor})]}),e==="success"&&(0,v.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,v.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,v.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,v.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,v.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,v.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,v.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"&&u!==null&&(0,v.jsx)("p",{style:g,children:u}),e==="error"&&r&&(0,v.jsx)("p",{style:g,children:r}),(0,v.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 Me=require("react"),dt=typeof window>"u"?Me.useEffect:Me.useLayoutEffect;var ue=require("react/jsx-runtime"),Le=new WeakSet;function pt({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:s,theme:i,submitLabel:u,containerStyle:p,onReady:g,onError:x,onValidation:F}){let V=(0,z.useRef)(null),E=(0,z.useRef)(g),T=(0,z.useRef)(x),w=(0,z.useRef)(F);E.current=g,T.current=x,w.current=F;let C=(0,z.useRef)(i);C.current=i;let c=(0,z.useRef)(null),S=u??void 0,L=(0,z.useRef)(S);L.current=S;let I=(0,z.useRef)(void 0);return(0,z.useEffect)(()=>{let y=V.current;if(!y)return;let X=!0,N=!1,b=()=>{!X||N||(N=!0,E.current?.())},H=e.on("ready",()=>{b()}),j=e.on("error",Y=>{T.current?.(Y.message??"There was a problem loading the secure card form.")}),G=e.on("validation",Y=>{w.current?.(Y.message??null)}),M=L.current??(Le.has(e)?null:void 0),ae={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...C.current?{theme:C.current}:{},...M===void 0?{}:{submitLabel:M}};return c.current=C.current??null,I.current=L.current,L.current!==void 0&&Le.add(e),e.mount(y,ae).then(()=>{b()}).catch(Y=>{X&&T.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{X=!1,H(),j(),G(),e.unmount()}},[e,r,t,o,s]),dt(()=>{let y=V.current;y&&st(y,p)},[p]),(0,z.useEffect)(()=>{i!==void 0&&(i===null&&c.current===null||(c.current=i,e.applyTheme?.(i)))},[e,i]),(0,z.useEffect)(()=>{S!==I.current&&(I.current=S,S!==void 0&&Le.add(e),e.setSubmitLabel?.(S??null))},[e,S]),(0,ue.jsx)("div",{ref:V,"data-testid":"flopay-vault-card-fields"})}function ct({label:e}){return(0,ue.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,ue.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,ue.jsx)("span",{children:e}),(0,ue.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var Ce=require("@flopay/shared");var Ie=require("react/jsx-runtime"),be=class extends re.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function de(e,r={}){let t=e instanceof re.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 Ne=require("react");var Pe=require("@flopay/js/card-setup"),h=require("@flopay/shared"),a=Zt(require("react"),1);var ge=require("@flopay/js/card-setup"),R=require("@flopay/shared");var f=require("react/jsx-runtime"),nr=15,ar=2e3;function sr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Be(e){return new Promise(r=>setTimeout(r,e))}async function ir(e,r,t){if(!r.trim())throw new h.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!t.trim())throw new h.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,h.isCardSetupCheckoutSession)(s))throw new h.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let i=(0,R.readSetupAdvertisement)(o);if(!(0,R.advertisesAnyMethod)(i)){let{skippedForMissingCurrency:u}=i,p=u.length>0?`FloPay: this setup session advertises only Stripe methods (${u.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 h.FloPayError(p,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:s,advertisement:i}}async function lr(e,r,t,o,s){let i=r.vault??null;(0,h.isMountableVaultBlock)(i)||(i=await e.getVaultCapture(t,o));let u=(0,h.resolveVaultMountOptions)(i,{billingApiUrl:s,sessionId:t,nonce:o});if(!u)throw new h.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return u}var xe=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 ft({branches:{StripeSetupMethod:e,PayPalSetupMethod:r},sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,theme:u="modern-light",containerStyle:p,loading:g=null,onReady:x,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:w}){let[C]=(0,a.useState)(ge.readSetupRedirectReturn),[c,S]=(0,a.useState)(null),[L,I]=(0,a.useState)(!1),[y,X]=(0,a.useState)(null),[N,b]=(0,a.useState)(null),[H,j]=(0,a.useState)(null),[G,M]=(0,a.useState)(null),[ae,Y]=(0,a.useState)(()=>new Set),Z=(0,a.useRef)(ae),se=(0,a.useRef)(null);se.current=c;let q=(0,a.useRef)(!1),ce=(0,a.useRef)(!1),ie=(0,a.useRef)(!1),_=(0,a.useRef)(!1),W=(0,a.useRef)(0),A=(0,a.useRef)(0),me=(0,a.useRef)(!1),K=(0,a.useMemo)(()=>typeof u=="object"?void 0:(0,h.resolveTheme)(u),[u]),Yt=(0,a.useMemo)(()=>typeof u=="object"?u:K?(0,Ce.computeVaultCardThemeColors)({appearance:K.appearance,buttonsStyles:K.buttonsLayout,layout:"default"}):null,[K,u]),Wt=(0,a.useMemo)(()=>(0,Oe.mergeCardSetupSurface)(K?.buttonsLayout.cardFormContainer,p),[K,p]),Ye=(0,a.useMemo)(()=>K?lt(K):void 0,[K]),B=(0,a.useRef)({sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:x,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:w});B.current={sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:x,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:w},(0,a.useEffect)(()=>{me.current=!0;let n=W.current+1;return W.current=n,()=>{me.current=!1,A.current+=1,queueMicrotask(()=>{W.current===n&&(ie.current||_.current||(_.current=!0,(0,J.invokeMerchantCallback)(()=>{B.current.onCancel?.({status:"cancelled",sessionId:t})})))})}},[t]);let ye=(0,a.useCallback)((n,l)=>{ie.current=!0,q.current=!1,M({status:"success",wording:n,message:null}),(async()=>(await Be(600),!ce.current&&(ce.current=!0,(0,J.invokeMerchantCallback)(()=>{B.current.onComplete?.({status:"succeeded",sessionId:B.current.sessionId,...l?{paymentMethod:l}:{}})}),me.current&&M(null))))()},[]),fe=(0,a.useCallback)((n,l)=>{ie.current=!0,q.current=!1,M({status:"error",wording:n,message:l.message??null}),(0,J.invokeMerchantCallback)(()=>{B.current.onDecline?.({status:"declined",sessionId:B.current.sessionId,...l.reason?{reason:l.reason}:{},...l.message?{message:l.message}:{}})}),(async()=>(await Be(400),me.current&&M(null)))()},[]),te=(0,a.useCallback)((n,l)=>{q.current?(q.current=!1,M({status:"error",wording:n,message:l.message}),setTimeout(()=>{me.current&&M(null)},400)):M(null),(0,J.invokeMerchantCallback)(()=>B.current.onError?.(l))},[]),we=(0,a.useCallback)(async n=>{let l=A.current+1;A.current=l;let m=()=>!me.current||l!==A.current;q.current=!0,M({status:"processing",wording:"payment_method",message:null});let U=new Pe.PaymentAPI((0,h.resolveBillingApiUrl)(B.current.billingApiUrl),{telemetry:B.current.telemetry});try{for(let d=0;d<nr;d+=1){if((d>0||n.waitFirst)&&await Be(ar),m())return;let $=await U.getUnifiedCheckoutSession(B.current.sessionId,B.current.nonce);if(m())return;let le=$.data.session?.status;if(le==="complete"){I(!0),ye("payment_method");return}if(le==="expired")throw new h.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new h.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(d){if(m())return;let $=d instanceof h.FloPayError&&d.code==="payment_method_setup_unverified";te("payment_method",de(d,$?{retryable:!0}:{}))}finally{U.destroy()}},[te,ye]);(0,a.useEffect)(()=>{let n=!0,l=(0,h.resolveBillingApiUrl)(s),m=new Pe.PaymentAPI(l,{telemetry:i});S(null),I(!1),X(null),b(null),j(null);let U=new Set;return Z.current=U,Y(U),ie.current=!1,_.current=!1,ce.current=!1,(async()=>{try{let{session:d,advertisement:$}=await ir(m,t,o);if(!n)return;let le={advertisement:$,customer:sr(d),...d.futureUse?{futureUse:d.futureUse}:{},...d.futureUseUnsupported?{futureUseUnsupported:d.futureUseUnsupported}:{}};if(C){if((0,ge.clearSetupRedirectParams)(),d.status==="complete"){I(!0),S(le),ye("payment_method");return}C.failed?fe("payment_method",{reason:"redirect_failed"}):we({waitFirst:!0})}let nt=$.card?await lr(m,d,t,o,l):null;if(!n)return;S(le),nt&&(b(nt),X(new Pe.PciVaultCardCapture({sessionId:t,operation:"card_setup",telemetry:i})))}catch(d){if(!n)return;let $=de(d);ie.current=!0,j($),(0,J.invokeMerchantCallback)(()=>B.current.onError?.($))}})(),()=>{n=!1,m.destroy()}},[s,o,C,fe,ye,t,i,we]),(0,a.useEffect)(()=>{if(!y)return;q.current=!1;let n=y.on("submitting",()=>{q.current=!0,M({status:"processing",wording:"card",message:null})}),l=y.on("complete",d=>{ye("card",d.paymentMethod)}),m=y.on("decline",d=>{fe("card",{...d.declineReason?{reason:d.declineReason}:{},...d.message?{message:d.message}:{}})}),U=y.on("challenge_dismissed",()=>{M(null)});return()=>{n(),l(),m(),U()}},[y,fe,ye]);let We=(0,a.useCallback)((n,l,m)=>{if(m.retryable){te("payment_method",de(l,m));return}if(Z.current.has(n))return;let U=new Set(Z.current);U.add(n),Z.current=U,Y(U);let d=se.current?.advertisement,$=d?(0,R.advertisedMethodKeys)(d).some(le=>!U.has(le)):!1;te("payment_method",de(l,{code:m.code,retryable:$}))},[te]),ze=(0,a.useMemo)(()=>({onSubmitting:()=>{q.current=!0,M({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{we({waitFirst:!1})},onDeclined:n=>fe("payment_method",n),onValidation:n=>{(0,J.invokeMerchantCallback)(()=>B.current.onValidation?.(n))},onAbandoned:()=>{q.current=!1,M(null)}}),[fe,we]),He=(0,a.useRef)(We);He.current=We;let Ge=(0,a.useRef)(new Map),Re=n=>{let l=Ge.current.get(n);if(l)return l;let m=(U,d)=>He.current(n,U,d);return Ge.current.set(n,m),m},Ke=(0,a.useCallback)(n=>{if(Z.current.has(n))return;let l=new Set(Z.current);l.add(n),Z.current=l,Y(l);let m=se.current?.advertisement;m&&(0,R.advertisedMethodKeys)(m).some(d=>!l.has(d))||te("payment_method",de(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[te]),Xe=(0,a.useRef)(Ke);Xe.current=Ke;let je=(0,a.useRef)(new Map),qe=n=>{let l=je.current.get(n);if(l)return l;let m=()=>Xe.current(n);return je.current.set(n,m),m},$e=G?(0,f.jsx)(ut,{status:G.status,errorMessage:G.message,...(0,R.setupOverlayLabels)(G.wording),successNote:null,...Ye?{theme:Ye}:{}}):null;if(H)return(0,f.jsx)("div",{role:"alert",children:H.message});if(!c||L)return(0,f.jsxs)(f.Fragment,{children:[$e,c?null:g]});let{advertisement:Se,customer:zt,futureUse:Ze,futureUseUnsupported:Je}=c,Qe=(0,h.resolveBillingApiUrl)(s),et=i===void 0?{}:{telemetry:i},Te=Se.stripe.filter(({method:n})=>!ae.has(n)),ve=ae.has("paypal")?null:Se.paypal,tt=!!(Se.card&&y&&N?.html),rt=({method:n,publishableKey:l,currency:m})=>(0,f.jsx)("div",{"data-flopay-payment-method":n,style:{display:"contents"},children:(0,f.jsx)(xe,{onFailed:Re(n),children:(0,f.jsx)(a.Suspense,{fallback:null,children:(0,f.jsx)(e,{method:n,category:(0,R.stripeMethodCategory)(n),publishableKey:l,currency:m,...Ze?{futureUse:Ze}:{},...Je?{futureUseUnsupported:Je}:{},sessionId:t,nonce:o,billingApiUrl:Qe,...et,...K?{appearance:K.appearance,buttonsLayout:K.buttonsLayout}:{},...typeof u=="string"?{themeId:u}:{},...ze,onFailed:Re(n),onUnavailable:qe(n)})})})},n),Ht=Te.filter(({method:n})=>(0,R.stripeMethodCategory)(n)==="wallet"),Gt=Te.filter(({method:n})=>(0,R.stripeMethodCategory)(n)!=="wallet"),ot=Te.length>0||ve!==null;return(0,f.jsxs)(f.Fragment,{children:[$e,ot?(0,f.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ht.map(rt),ve?(0,f.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,f.jsx)(xe,{onFailed:Re("paypal"),children:(0,f.jsx)(a.Suspense,{fallback:null,children:(0,f.jsx)(r,{clientId:ve.clientId,...ve.environment?{environment:ve.environment}:{},...Se.currency?{currency:Se.currency}:{},sessionId:t,nonce:o,billingApiUrl:Qe,customer:zt,...et,...ze,onFailed:Re("paypal"),onUnavailable:qe("paypal")})})})}):null,Gt.map(rt)]}):null,tt&&ot?(0,f.jsx)(ct,{label:"or add a card"}):null,tt&&y&&N?.html?(0,f.jsx)("div",{"data-flopay-payment-method":"card",children:(0,f.jsx)(pt,{capture:y,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,verificationRequired:N.verificationRequired,theme:Yt,containerStyle:Wt,onReady:()=>{(0,J.invokeMerchantCallback)(()=>B.current.onReady?.())},onValidation:n=>{(0,J.invokeMerchantCallback)(()=>B.current.onValidation?.(n))},onError:n=>{n&&te("card",de(new Error(n),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var Nt=require("react/jsx-runtime"),Cr={StripeSetupMethod:(0,Ne.lazy)(()=>Promise.resolve().then(()=>(Ot(),At)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,Ne.lazy)(()=>Promise.resolve().then(()=>(Dt(),Bt)).then(e=>({default:e.PayPalSetupMethod})))};function Vt(e){return(0,Nt.jsx)(ft,{...e,branches:Cr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
27
|
+
`})]})})}var z=require("react");var ke=require("react"),dt=typeof window>"u"?ke.useEffect:ke.useLayoutEffect;var le=require("react/jsx-runtime"),Le=new WeakSet;function pt({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:s,theme:i,submitLabel:u,containerStyle:p,onReady:g,onError:_,onValidation:F}){let V=(0,z.useRef)(null),E=(0,z.useRef)(g),T=(0,z.useRef)(_),R=(0,z.useRef)(F);E.current=g,T.current=_,R.current=F;let C=(0,z.useRef)(i);C.current=i;let c=(0,z.useRef)(null),S=u??void 0,L=(0,z.useRef)(S);L.current=S;let I=(0,z.useRef)(void 0);return(0,z.useEffect)(()=>{let y=V.current;if(!y)return;let X=!0,N=!1,P=()=>{!X||N||(N=!0,E.current?.())},H=e.on("ready",()=>{P()}),j=e.on("error",Y=>{T.current?.(Y.message??"There was a problem loading the secure card form.")}),G=e.on("validation",Y=>{R.current?.(Y.message??null)}),M=L.current??(Le.has(e)?null:void 0),ne={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...C.current?{theme:C.current}:{},...M===void 0?{}:{submitLabel:M}};return c.current=C.current??null,I.current=L.current,L.current!==void 0&&Le.add(e),e.mount(y,ne).then(()=>{P()}).catch(Y=>{X&&T.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{X=!1,H(),j(),G(),e.unmount()}},[e,r,t,o,s]),dt(()=>{let y=V.current;y&&it(y,p)},[p]),(0,z.useEffect)(()=>{i!==void 0&&(i===null&&c.current===null||(c.current=i,e.applyTheme?.(i)))},[e,i]),(0,z.useEffect)(()=>{S!==I.current&&(I.current=S,S!==void 0&&Le.add(e),e.setSubmitLabel?.(S??null))},[e,S]),(0,le.jsx)("div",{ref:V,"data-testid":"flopay-vault-card-fields"})}function ct({label:e}){return(0,le.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,le.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,le.jsx)("span",{children:e}),(0,le.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var Ie=require("react/jsx-runtime"),Ce=class extends ue.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function de(e,r={}){let t=e instanceof ue.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 Ce(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 Pe=require("@flopay/js/card-setup"),h=require("@flopay/shared"),a=Zt(require("react"),1);var ge=require("@flopay/js/card-setup"),w=require("@flopay/shared");var Be=require("@flopay/shared");var f=require("react/jsx-runtime"),ar=15,sr=2e3;function ir(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(r=>setTimeout(r,e))}async function lr(e,r,t){if(!r.trim())throw new h.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!t.trim())throw new h.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,h.isCardSetupCheckoutSession)(s))throw new h.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let i=(0,w.readSetupAdvertisement)(o);if(!(0,w.advertisesAnyMethod)(i)){let{skippedForMissingCurrency:u}=i,p=u.length>0?`FloPay: this setup session advertises only Stripe methods (${u.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 h.FloPayError(p,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:s,advertisement:i}}async function ur(e,r,t,o,s){let i=r.vault??null;(0,h.isMountableVaultBlock)(i)||(i=await e.getVaultCapture(t,o));let u=(0,h.resolveVaultMountOptions)(i,{billingApiUrl:s,sessionId:t,nonce:o});if(!u)throw new h.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return u}var xe=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 ft({branches:{StripeSetupMethod:e,PayPalSetupMethod:r},sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,theme:u="modern-light",containerStyle:p,loading:g=null,onReady:_,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:R}){let[C]=(0,a.useState)(ge.readSetupRedirectReturn),[c,S]=(0,a.useState)(null),[L,I]=(0,a.useState)(!1),[y,X]=(0,a.useState)(null),[N,P]=(0,a.useState)(null),[H,j]=(0,a.useState)(null),[G,M]=(0,a.useState)(null),[ne,Y]=(0,a.useState)(()=>new Set),Z=(0,a.useRef)(ne),ae=(0,a.useRef)(null);ae.current=c;let q=(0,a.useRef)(!1),ce=(0,a.useRef)(!1),se=(0,a.useRef)(!1),x=(0,a.useRef)(!1),W=(0,a.useRef)(0),A=(0,a.useRef)(0),me=(0,a.useRef)(!1),K=(0,a.useMemo)(()=>typeof u=="object"?void 0:(0,h.resolveTheme)(u),[u]),Yt=(0,a.useMemo)(()=>typeof u=="object"?u:K?(0,Be.computeVaultCardThemeColors)({appearance:K.appearance,buttonsStyles:K.buttonsLayout,layout:"default"}):null,[K,u]),Wt=(0,a.useMemo)(()=>(0,Ae.mergeCardSetupSurface)(K?.buttonsLayout.cardFormContainer,p),[K,p]),We=(0,a.useMemo)(()=>K?lt(K):void 0,[K]),B=(0,a.useRef)({sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:_,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:R});B.current={sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:_,onComplete:F,onDecline:V,onCancel:E,onValidation:T,onError:R},(0,a.useEffect)(()=>{me.current=!0;let n=W.current+1;return W.current=n,()=>{me.current=!1,A.current+=1,queueMicrotask(()=>{W.current===n&&(se.current||x.current||(x.current=!0,(0,J.invokeMerchantCallback)(()=>{B.current.onCancel?.({status:"cancelled",sessionId:t})})))})}},[t]);let ye=(0,a.useCallback)((n,l)=>{se.current=!0,q.current=!1,M({status:"success",wording:n,message:null}),(async()=>(await Ue(600),!ce.current&&(ce.current=!0,(0,J.invokeMerchantCallback)(()=>{B.current.onComplete?.({status:"succeeded",sessionId:B.current.sessionId,...l?{paymentMethod:l}:{}})}),me.current&&M(null))))()},[]),fe=(0,a.useCallback)((n,l)=>{se.current=!0,q.current=!1,M({status:"error",wording:n,message:l.message??null}),(0,J.invokeMerchantCallback)(()=>{B.current.onDecline?.({status:"declined",sessionId:B.current.sessionId,...l.reason?{reason:l.reason}:{},...l.message?{message:l.message}:{}})}),(async()=>(await Ue(400),me.current&&M(null)))()},[]),te=(0,a.useCallback)((n,l)=>{q.current?(q.current=!1,M({status:"error",wording:n,message:l.message}),setTimeout(()=>{me.current&&M(null)},400)):M(null),(0,J.invokeMerchantCallback)(()=>B.current.onError?.(l))},[]),Ee=(0,a.useCallback)(async n=>{let l=A.current+1;A.current=l;let m=()=>!me.current||l!==A.current;q.current=!0,M({status:"processing",wording:"payment_method",message:null});let U=new Pe.PaymentAPI((0,h.resolveBillingApiUrl)(B.current.billingApiUrl),{telemetry:B.current.telemetry});try{for(let d=0;d<ar;d+=1){if((d>0||n.waitFirst)&&await Ue(sr),m())return;let $=await U.getUnifiedCheckoutSession(B.current.sessionId,B.current.nonce);if(m())return;let ie=$.data.session?.status;if(ie==="complete"){I(!0),ye("payment_method");return}if(ie==="expired")throw new h.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new h.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(d){if(m())return;let $=d instanceof h.FloPayError&&d.code==="payment_method_setup_unverified";te("payment_method",de(d,$?{retryable:!0}:{}))}finally{U.destroy()}},[te,ye]);(0,a.useEffect)(()=>{let n=!0,l=(0,h.resolveBillingApiUrl)(s),m=new Pe.PaymentAPI(l,{telemetry:i});S(null),I(!1),X(null),P(null),j(null);let U=new Set;return Z.current=U,Y(U),se.current=!1,x.current=!1,ce.current=!1,(async()=>{try{let{session:d,advertisement:$}=await lr(m,t,o);if(!n)return;let ie={advertisement:$,customer:ir(d),...d.futureUse?{futureUse:d.futureUse}:{},...d.futureUseUnsupported?{futureUseUnsupported:d.futureUseUnsupported}:{}};if(C){if((0,ge.clearSetupRedirectParams)(),d.status==="complete"){I(!0),S(ie),ye("payment_method");return}C.failed?fe("payment_method",{reason:"redirect_failed"}):Ee({waitFirst:!0})}let at=$.card?await ur(m,d,t,o,l):null;if(!n)return;S(ie),at&&(P(at),X(new Pe.PciVaultCardCapture({sessionId:t,operation:"card_setup",telemetry:i})))}catch(d){if(!n)return;let $=de(d);se.current=!0,j($),(0,J.invokeMerchantCallback)(()=>B.current.onError?.($))}})(),()=>{n=!1,m.destroy()}},[s,o,C,fe,ye,t,i,Ee]),(0,a.useEffect)(()=>{if(!y)return;q.current=!1;let n=y.on("submitting",()=>{q.current=!0,M({status:"processing",wording:"card",message:null})}),l=y.on("complete",d=>{ye("card",d.paymentMethod)}),m=y.on("decline",d=>{fe("card",{...d.declineReason?{reason:d.declineReason}:{},...d.message?{message:d.message}:{}})}),U=y.on("challenge_dismissed",()=>{M(null)});return()=>{n(),l(),m(),U()}},[y,fe,ye]);let ze=(0,a.useCallback)((n,l,m)=>{if(m.retryable){te("payment_method",de(l,m));return}if(Z.current.has(n))return;let U=new Set(Z.current);U.add(n),Z.current=U,Y(U);let d=ae.current?.advertisement,$=d?(0,w.advertisedMethodKeys)(d).some(ie=>!U.has(ie)):!1;te("payment_method",de(l,{code:m.code,retryable:$}))},[te]),He=(0,a.useMemo)(()=>({onSubmitting:()=>{q.current=!0,M({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{Ee({waitFirst:!1})},onDeclined:n=>fe("payment_method",n),onValidation:n=>{(0,J.invokeMerchantCallback)(()=>B.current.onValidation?.(n))},onAbandoned:()=>{q.current=!1,M(null)}}),[fe,Ee]),Ge=(0,a.useRef)(ze);Ge.current=ze;let Ke=(0,a.useRef)(new Map),Re=n=>{let l=Ke.current.get(n);if(l)return l;let m=(U,d)=>Ge.current(n,U,d);return Ke.current.set(n,m),m},Xe=(0,a.useCallback)(n=>{if(Z.current.has(n))return;let l=new Set(Z.current);l.add(n),Z.current=l,Y(l);let m=ae.current?.advertisement;m&&(0,w.advertisedMethodKeys)(m).some(d=>!l.has(d))||te("payment_method",de(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[te]),je=(0,a.useRef)(Xe);je.current=Xe;let qe=(0,a.useRef)(new Map),$e=n=>{let l=qe.current.get(n);if(l)return l;let m=()=>je.current(n);return qe.current.set(n,m),m},Ze=G?(0,f.jsx)(ut,{status:G.status,errorMessage:G.message,...(0,w.setupOverlayLabels)(G.wording),successNote:null,...We?{theme:We}:{}}):null;if(H)return(0,f.jsx)("div",{role:"alert",children:H.message});if(!c||L)return(0,f.jsxs)(f.Fragment,{children:[Ze,c?null:g]});let{advertisement:Se,customer:zt,futureUse:Je,futureUseUnsupported:Qe}=c,et=(0,h.resolveBillingApiUrl)(s),tt=i===void 0?{}:{telemetry:i},Fe=Se.stripe.filter(({method:n})=>!ne.has(n)),ve=ne.has("paypal")?null:Se.paypal,rt=!!(Se.card&&y&&N?.html),ot=({method:n,publishableKey:l,currency:m})=>(0,f.jsx)("div",{"data-flopay-payment-method":n,style:{display:"contents"},children:(0,f.jsx)(xe,{onFailed:Re(n),children:(0,f.jsx)(a.Suspense,{fallback:null,children:(0,f.jsx)(e,{method:n,category:(0,w.stripeMethodCategory)(n),publishableKey:l,currency:m,...Je?{futureUse:Je}:{},...Qe?{futureUseUnsupported:Qe}:{},sessionId:t,nonce:o,billingApiUrl:et,...tt,...K?{appearance:K.appearance,buttonsLayout:K.buttonsLayout}:{},...typeof u=="string"?{themeId:u}:{},...He,onFailed:Re(n),onUnavailable:$e(n)})})})},n),Ht=Fe.filter(({method:n})=>(0,w.stripeMethodCategory)(n)==="wallet"),Gt=Fe.filter(({method:n})=>(0,w.stripeMethodCategory)(n)!=="wallet"),nt=Fe.length>0||ve!==null;return(0,f.jsxs)(f.Fragment,{children:[Ze,nt?(0,f.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ht.map(ot),ve?(0,f.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,f.jsx)(xe,{onFailed:Re("paypal"),children:(0,f.jsx)(a.Suspense,{fallback:null,children:(0,f.jsx)(r,{clientId:ve.clientId,...ve.environment?{environment:ve.environment}:{},...Se.currency?{currency:Se.currency}:{},sessionId:t,nonce:o,billingApiUrl:et,customer:zt,...tt,...He,onFailed:Re("paypal"),onUnavailable:$e("paypal")})})})}):null,Gt.map(ot)]}):null,rt&&nt?(0,f.jsx)(ct,{label:"or add a card"}):null,rt&&y&&N?.html?(0,f.jsx)("div",{"data-flopay-payment-method":"card",children:(0,f.jsx)(pt,{capture:y,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,verificationRequired:N.verificationRequired,theme:Yt,containerStyle:Wt,onReady:()=>{(0,J.invokeMerchantCallback)(()=>B.current.onReady?.())},onValidation:n=>{(0,J.invokeMerchantCallback)(()=>B.current.onValidation?.(n))},onError:n=>{n&&te("card",de(new Error(n),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var Nt=require("react/jsx-runtime"),Pr={StripeSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(Ot(),At)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(Dt(),Bt)).then(e=>({default:e.PayPalSetupMethod})))};function Vt(e){return(0,Nt.jsx)(ft,{...e,branches:Pr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-
|
|
1
|
+
import{a as t}from"./chunk-4DGIEZ4S.mjs";import{h as a}from"./chunk-XVCGDHF2.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-6O2YE4RY.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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopay/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"@paypal/paypal-js": "^10.1.0",
|
|
40
40
|
"@stripe/react-stripe-js": "^6.12.0",
|
|
41
41
|
"@stripe/stripe-js": "^9.17.0",
|
|
42
|
-
"@flopay/js": "1.
|
|
43
|
-
"@flopay/shared": "1.
|
|
42
|
+
"@flopay/js": "1.12.1",
|
|
43
|
+
"@flopay/shared": "1.12.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=18.0.0",
|
package/dist/chunk-KKA5TF5P.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{useEffect as J,useRef as v}from"react";import{mergeCardSetupSurface as se}from"@flopay/shared";var ye=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 ge(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return ye.has(r.charAt(0).toLowerCase()+r.slice(1))}function Ce(e,r){return typeof r=="number"&&r!==0&&!ge(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]=Ce(t,o)}}}import{useEffect as he,useLayoutEffect as Se}from"react";var ie=typeof window>"u"?he:Se;import{jsx as B,jsxs as ve}from"react/jsx-runtime";var K=new WeakSet;function le({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:s,theme:i,submitLabel:E,containerStyle:d,onReady:h,onError:_,onValidation:F}){let w=v(null),M=v(h),l=v(_),V=v(F);M.current=h,l.current=_,V.current=F;let m=v(i);m.current=i;let x=v(null),y=E??void 0,R=v(y);R.current=y;let k=v(void 0);return J(()=>{let a=w.current;if(!a)return;let D=!0,P=!1,g=()=>{!D||P||(P=!0,M.current?.())},I=e.on("ready",()=>{g()}),p=e.on("error",C=>{l.current?.(C.message??"There was a problem loading the secure card form.")}),j=e.on("validation",C=>{V.current?.(C.message??null)}),Y=R.current??(K.has(e)?null:void 0),G={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...m.current?{theme:m.current}:{},...Y===void 0?{}:{submitLabel:Y}};return x.current=m.current??null,k.current=R.current,R.current!==void 0&&K.add(e),e.mount(a,G).then(()=>{g()}).catch(C=>{D&&l.current?.(C instanceof Error?C.message:"Failed to load the secure card form.")}),()=>{D=!1,I(),p(),j(),e.unmount()}},[e,r,t,o,s]),ie(()=>{let a=w.current;a&&ae(a,d)},[d]),J(()=>{i!==void 0&&(i===null&&x.current===null||(x.current=i,e.applyTheme?.(i)))},[e,i]),J(()=>{y!==k.current&&(k.current=y,y!==void 0&&K.add(e),e.setSubmitLabel?.(y??null))},[e,y]),B("div",{ref:w,"data-testid":"flopay-vault-card-fields"})}function Ue({label:e}){return ve("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[B("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),B("span",{children:e}),B("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}import{PaymentAPI as we,PciVaultCardCapture as xe}from"@flopay/js/card-setup";import{FloPayError as L,isCardSetupCheckoutSession as ke,isMountableVaultBlock as Pe,resolveBillingApiUrl as Te,resolveTheme as Oe,resolveVaultMountOptions as Ae}from"@flopay/shared";import{useEffect as Q,useMemo as H,useRef as f,useState as z}from"react";import{computeCardSetupOverlayTheme as be}from"@flopay/shared";function ce(e){return be(e)}import{invokeMerchantCallback as b}from"@flopay/shared";import{jsx as u,jsxs as A}from"react/jsx-runtime";var Re={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ue({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:s,errorLabel:i="PAYMENT FAILED",successNote:E="You will be automatically redirected, do not close or navigate away from this window.",theme:d=Re}){let h={fontSize:13,color:d.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)",...d.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:d.spinnerTrackColor,strokeWidth:"3"}),u("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:d.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:d.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(s??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&E!==null&&u("p",{style:h,children:E}),e==="error"&&r&&u("p",{style:h,children:r}),u("style",{children:`
|
|
2
|
-
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
|
-
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
|
-
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
|
-
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}import{computeVaultCardThemeColors as de,darkenHex as $e,toCssWeight as Je}from"@flopay/shared";import{Fragment as me,jsx as q,jsxs as Le}from"react/jsx-runtime";var ee=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,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 ee(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}})}function ir({sessionId:e,nonce:r,billingApiUrl:t,telemetry:o,theme:s="modern-light",containerStyle:i,loading:E=null,onReady:d,onComplete:h,onDecline:_,onCancel:F,onValidation:w,onError:M}){let[l,V]=z(null),[m,x]=z(null),[y,R]=z(null),[k,a]=z(null),[D,P]=z(null),g=f(!1),I=f(!1),p=H(()=>typeof s=="object"?void 0:Oe(s),[s]),j=H(()=>typeof s=="object"?s:p?de({appearance:p.appearance,buttonsStyles:p.buttonsLayout,layout:"default"}):null,[p,s]),Y=H(()=>se(p?.buttonsLayout.cardFormContainer,i),[p,i]),G=H(()=>p?ce(p):void 0,[p]),C=f(d),X=f(M),re=f(h),te=f(_),oe=f(F),ne=f(w),N=f(!1),Z=f(!1),$=f(0);return C.current=d,X.current=M,re.current=h,te.current=_,oe.current=F,ne.current=w,Q(()=>{let n=$.current+1;return $.current=n,()=>{queueMicrotask(()=>{$.current===n&&(N.current||Z.current||(Z.current=!0,b(()=>{oe.current?.({status:"cancelled",sessionId:e})})))})}},[e]),Q(()=>{let n=!0,T=Te(t),U=new we(T,{telemetry:o});return V(null),x(null),R(null),N.current=!1,Z.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 S=W.data.session;if(!S||!ke(S))throw new L("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let c=S.vault;Pe(c)||(c=await U.getVaultCapture(e,r));let O=Ae(c,{billingApiUrl:T,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;x(O),V(new xe({sessionId:e,operation:"card_setup",telemetry:o}))}catch(W){if(!n)return;let S=fe(W);N.current=!0,R(S),b(()=>X.current?.(S))}})(),()=>{n=!1,U.destroy()}},[t,r,e,o]),Q(()=>{if(!l)return;let n=!1;I.current=!1,g.current=!1;let T=l.on("submitting",()=>{g.current=!0,P(null),a("processing")}),U=l.on("complete",c=>{N.current=!0,g.current=!1,a("success"),(async()=>(await new Promise(O=>setTimeout(O,600)),!I.current&&(I.current=!0,b(()=>{re.current?.({status:"succeeded",sessionId:e,...c.paymentMethod?{paymentMethod:c.paymentMethod}:{}})}),n||a(null))))()}),W=l.on("decline",c=>{N.current=!0,g.current=!1,P(c.message??null),a("error"),b(()=>{te.current?.({status:"declined",sessionId:e,...c.declineReason?{reason:c.declineReason}:{},...c.message?{message:c.message}:{}})}),(async()=>(await new Promise(O=>setTimeout(O,400)),n||a(null)))()}),S=l.on("challenge_dismissed",()=>{a(null)});return()=>{n=!0,T(),U(),W(),S()}},[l,e]),y?q("div",{role:"alert",children:y.message}):!l||!m?.html?q(me,{children:E}):Le(me,{children:[k&&q(ue,{status:k,errorMessage:D,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...G?{theme:G}:{}}),q(le,{capture:l,html:m.html,messageToken:m.messageToken,expectedOrigin:m.expectedOrigin,verificationRequired:m.verificationRequired,theme:j,containerStyle:Y,onReady:()=>{b(()=>C.current?.())},onValidation:n=>{b(()=>ne.current?.(n))},onError:n=>{if(!n)return;g.current&&(g.current=!1,P(n),a("error"),setTimeout(()=>a(null),400));let T=fe(new Error(n),{code:"card_setup_widget_failed",retryable:!0});b(()=>X.current?.(T))}})]})}export{se as a,ce as b,b as c,ue as d,ie as e,le as f,Ue as g,de as h,$e as i,Je as j,ee as k,fe as l,ir as m};
|
package/dist/chunk-Q5RE4G4O.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as Ve,b as Ae,c as C,d as Te,f as Ie,g as xe,h as De,l as w}from"./chunk-KKA5TF5P.mjs";import{PaymentAPI as Ge,PciVaultCardCapture as rt}from"@flopay/js/card-setup";import{FloPayError as F,isCardSetupCheckoutSession as nt,isMountableVaultBlock as at,resolveBillingApiUrl as te,resolveTheme as ot,resolveVaultMountOptions as st}from"@flopay/shared";import it,{Suspense as Ke,useCallback as O,useEffect as re,useMemo as T,useRef as u,useState as b}from"react";import{clearSetupRedirectParams as Le,readSetupRedirectReturn as Ne}from"@flopay/js/card-setup";import{advertisedMethodKeys as ee,advertisesAnyMethod as We,readSetupAdvertisement as Ye,setupOverlayLabels as qe,stripeMethodCategory as Y}from"@flopay/shared";import{Fragment as He,jsx as c,jsxs as ae}from"react/jsx-runtime";var lt=15,ut=2e3;function dt(y){return{userId:y.customer?.id??"",email:y.customer?.email??""}}function ne(y){return new Promise(v=>setTimeout(v,y))}async function ct(y,v,a){if(!v.trim())throw new F("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new F("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let d=await y.getUnifiedCheckoutSession(v,a),f=d.data.session;if(!f||!nt(f))throw new F("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let o=Ye(d);if(!We(o)){let{skippedForMissingCurrency:l}=o,I=l.length>0?`FloPay: this setup session advertises only Stripe methods (${l.join(", ")}), and they need the session's currency, which the setup-session read did not carry.`:"FloPay: this setup session advertises no payment method.";throw new F(I,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:f,advertisement:o}}async function pt(y,v,a,d,f){let o=v.vault??null;at(o)||(o=await y.getVaultCapture(a,d));let l=st(o,{billingApiUrl:f,sessionId:a,nonce:d});if(!l)throw new F("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return l}var q=class extends it.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 _t({branches:{StripeSetupMethod:y,PayPalSetupMethod:v},sessionId:a,nonce:d,billingApiUrl:f,telemetry:o,theme:l="modern-light",containerStyle:I,loading:ze=null,onReady:oe,onComplete:se,onDecline:ie,onCancel:le,onValidation:ue,onError:de}){let[j]=b(Ne),[x,G]=b(null),[$e,K]=b(!1),[S,ce]=b(null),[_,pe]=b(null),[me,ye]=b(null),[D,p]=b(null),[H,z]=b(()=>new Set),M=u(H),$=u(null);$.current=x;let g=u(!1),J=u(!1),B=u(!1),Q=u(!1),X=u(0),L=u(0),E=u(!1),m=T(()=>typeof l=="object"?void 0:ot(l),[l]),Je=T(()=>typeof l=="object"?l:m?De({appearance:m.appearance,buttonsStyles:m.buttonsLayout,layout:"default"}):null,[m,l]),Qe=T(()=>Ve(m?.buttonsLayout.cardFormContainer,I),[m,I]),fe=T(()=>m?Ae(m):void 0,[m]),s=u({sessionId:a,nonce:d,billingApiUrl:f,telemetry:o,onReady:oe,onComplete:se,onDecline:ie,onCancel:le,onValidation:ue,onError:de});s.current={sessionId:a,nonce:d,billingApiUrl:f,telemetry:o,onReady:oe,onComplete:se,onDecline:ie,onCancel:le,onValidation:ue,onError:de},re(()=>{E.current=!0;let e=X.current+1;return X.current=e,()=>{E.current=!1,L.current+=1,queueMicrotask(()=>{X.current===e&&(B.current||Q.current||(Q.current=!0,C(()=>{s.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let U=O((e,t)=>{B.current=!0,g.current=!1,p({status:"success",wording:e,message:null}),(async()=>(await ne(600),!J.current&&(J.current=!0,C(()=>{s.current.onComplete?.({status:"succeeded",sessionId:s.current.sessionId,...t?{paymentMethod:t}:{}})}),E.current&&p(null))))()},[]),k=O((e,t)=>{B.current=!0,g.current=!1,p({status:"error",wording:e,message:t.message??null}),C(()=>{s.current.onDecline?.({status:"declined",sessionId:s.current.sessionId,...t.reason?{reason:t.reason}:{},...t.message?{message:t.message}:{}})}),(async()=>(await ne(400),E.current&&p(null)))()},[]),P=O((e,t)=>{g.current?(g.current=!1,p({status:"error",wording:e,message:t.message}),setTimeout(()=>{E.current&&p(null)},400)):p(null),C(()=>s.current.onError?.(t))},[]),N=O(async e=>{let t=L.current+1;L.current=t;let n=()=>!E.current||t!==L.current;g.current=!0,p({status:"processing",wording:"payment_method",message:null});let i=new Ge(te(s.current.billingApiUrl),{telemetry:s.current.telemetry});try{for(let r=0;r<lt;r+=1){if((r>0||e.waitFirst)&&await ne(ut),n())return;let h=await i.getUnifiedCheckoutSession(s.current.sessionId,s.current.nonce);if(n())return;let R=h.data.session?.status;if(R==="complete"){K(!0),U("payment_method");return}if(R==="expired")throw new F("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new F("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(r){if(n())return;let h=r instanceof F&&r.code==="payment_method_setup_unverified";P("payment_method",w(r,h?{retryable:!0}:{}))}finally{i.destroy()}},[P,U]);re(()=>{let e=!0,t=te(f),n=new Ge(t,{telemetry:o});G(null),K(!1),ce(null),pe(null),ye(null);let i=new Set;return M.current=i,z(i),B.current=!1,Q.current=!1,J.current=!1,(async()=>{try{let{session:r,advertisement:h}=await ct(n,a,d);if(!e)return;let R={advertisement:h,customer:dt(r),...r.futureUse?{futureUse:r.futureUse}:{},...r.futureUseUnsupported?{futureUseUnsupported:r.futureUseUnsupported}:{}};if(j){if(Le(),r.status==="complete"){K(!0),G(R),U("payment_method");return}j.failed?k("payment_method",{reason:"redirect_failed"}):N({waitFirst:!0})}let Be=h.card?await pt(n,r,a,d,t):null;if(!e)return;G(R),Be&&(pe(Be),ce(new rt({sessionId:a,operation:"card_setup",telemetry:o})))}catch(r){if(!e)return;let h=w(r);B.current=!0,ye(h),C(()=>s.current.onError?.(h))}})(),()=>{e=!1,n.destroy()}},[f,d,j,k,U,a,o,N]),re(()=>{if(!S)return;g.current=!1;let e=S.on("submitting",()=>{g.current=!0,p({status:"processing",wording:"card",message:null})}),t=S.on("complete",r=>{U("card",r.paymentMethod)}),n=S.on("decline",r=>{k("card",{...r.declineReason?{reason:r.declineReason}:{},...r.message?{message:r.message}:{}})}),i=S.on("challenge_dismissed",()=>{p(null)});return()=>{e(),t(),n(),i()}},[S,k,U]);let he=O((e,t,n)=>{if(n.retryable){P("payment_method",w(t,n));return}if(M.current.has(e))return;let i=new Set(M.current);i.add(e),M.current=i,z(i);let r=$.current?.advertisement,h=r?ee(r).some(R=>!i.has(R)):!1;P("payment_method",w(t,{code:n.code,retryable:h}))},[P]),ve=T(()=>({onSubmitting:()=>{g.current=!0,p({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{N({waitFirst:!1})},onDeclined:e=>k("payment_method",e),onValidation:e=>{C(()=>s.current.onValidation?.(e))},onAbandoned:()=>{g.current=!1,p(null)}}),[k,N]),Se=u(he);Se.current=he;let ge=u(new Map),W=e=>{let t=ge.current.get(e);if(t)return t;let n=(i,r)=>Se.current(e,i,r);return ge.current.set(e,n),n},Ce=O(e=>{if(M.current.has(e))return;let t=new Set(M.current);t.add(e),M.current=t,z(t);let n=$.current?.advertisement;n&&ee(n).some(r=>!t.has(r))||P("payment_method",w(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[P]),Pe=u(Ce);Pe.current=Ce;let be=u(new Map),Fe=e=>{let t=be.current.get(e);if(t)return t;let n=()=>Pe.current(e);return be.current.set(e,n),n},Me=D?c(Te,{status:D.status,errorMessage:D.message,...qe(D.wording),successNote:null,...fe?{theme:fe}:{}}):null;if(me)return c("div",{role:"alert",children:me.message});if(!x||$e)return ae(He,{children:[Me,x?null:ze]});let{advertisement:V,customer:Xe,futureUse:Re,futureUseUnsupported:we}=x,_e=te(f),Ee=o===void 0?{}:{telemetry:o},Z=V.stripe.filter(({method:e})=>!H.has(e)),A=H.has("paypal")?null:V.paypal,Ue=!!(V.card&&S&&_?.html),ke=({method:e,publishableKey:t,currency:n})=>c("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:c(q,{onFailed:W(e),children:c(Ke,{fallback:null,children:c(y,{method:e,category:Y(e),publishableKey:t,currency:n,...Re?{futureUse:Re}:{},...we?{futureUseUnsupported:we}:{},sessionId:a,nonce:d,billingApiUrl:_e,...Ee,...m?{appearance:m.appearance,buttonsLayout:m.buttonsLayout}:{},...typeof l=="string"?{themeId:l}:{},...ve,onFailed:W(e),onUnavailable:Fe(e)})})})},e),Ze=Z.filter(({method:e})=>Y(e)==="wallet"),et=Z.filter(({method:e})=>Y(e)!=="wallet"),Oe=Z.length>0||A!==null;return ae(He,{children:[Me,Oe?ae("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ze.map(ke),A?c("div",{"data-flopay-payment-method":"paypal",children:c(q,{onFailed:W("paypal"),children:c(Ke,{fallback:null,children:c(v,{clientId:A.clientId,...A.environment?{environment:A.environment}:{},...V.currency?{currency:V.currency}:{},sessionId:a,nonce:d,billingApiUrl:_e,customer:Xe,...Ee,...ve,onFailed:W("paypal"),onUnavailable:Fe("paypal")})})})}):null,et.map(ke)]}):null,Ue&&Oe?c(xe,{label:"or add a card"}):null,Ue&&S&&_?.html?c("div",{"data-flopay-payment-method":"card",children:c(Ie,{capture:S,html:_.html,messageToken:_.messageToken,expectedOrigin:_.expectedOrigin,verificationRequired:_.verificationRequired,theme:Je,containerStyle:Qe,onReady:()=>{C(()=>s.current.onReady?.())},onValidation:e=>{C(()=>s.current.onValidation?.(e))},onError:e=>{e&&P("card",w(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{_t as a};
|