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