@flopay/react 1.14.8 → 1.14.10
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 +4 -2
- package/dist/checkout-utils.d.ts +12 -3
- package/dist/chunk-BU7THP6H.mjs +1 -0
- package/dist/{chunk-JCJFICSM.mjs → chunk-FGCZOMML.mjs} +2 -2
- package/dist/index.cjs +9 -9
- package/dist/index.mjs +7 -7
- package/dist/payment-method-setup-entry.cjs +3 -3
- package/dist/payment-method-setup-entry.mjs +1 -1
- package/dist/payment-method-setup-paypal-CLV7JDJH.mjs +1 -0
- package/dist/payment-method-setup-stripe-526L4P5X.mjs +1 -0
- package/package.json +5 -5
- package/dist/chunk-HSYSKQPT.mjs +0 -1
- package/dist/payment-method-setup-paypal-AGIJIZDK.mjs +0 -1
- package/dist/payment-method-setup-stripe-AAZGNGQO.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var jt=Object.create;var Me=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var Jt=Object.getPrototypeOf,Qt=Object.prototype.hasOwnProperty;var Se=(e,r)=>()=>(e&&(r=e(e=0)),r);var Oe=(e,r)=>{for(var t in r)Me(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&&Me(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?Me(t,"default",{value:e,enumerable:!0}):t,e)),tr=e=>dt(Me({},"__esModule",{value:!0}),e);var P,Ve=Se(()=>{"use strict";P=require("@flopay/shared")});var mr,
|
|
1
|
+
"use strict";var jt=Object.create;var Me=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var Jt=Object.getPrototypeOf,Qt=Object.prototype.hasOwnProperty;var Se=(e,r)=>()=>(e&&(r=e(e=0)),r);var Oe=(e,r)=>{for(var t in r)Me(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&&Me(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?Me(t,"default",{value:e,enumerable:!0}):t,e)),tr=e=>dt(Me({},"__esModule",{value:!0}),e);var P,Ve=Se(()=>{"use strict";P=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,M.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,M.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,M.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,M.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:i=!1,onClick:d,backgroundColor:p,borderColor:f,textColor:F,borderRadius:L,fontFamily:Y}){let b=(0,re.resolveStripeMethodBrandVariant)(e,r),T=Ct[e],[E,w]=(0,bt.useState)(!1),y=!!T&&!E,g=b?.backgroundColor??p??"#ffffff",R=b?.borderColor??f??"#d1d5db",B=b?.textColor??F??"#262833";return(0,M.jsx)("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!t&&!o&&d()},disabled:t||o,"aria-busy":t||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:fr,padding:"0 1rem",backgroundColor:g,color:B,border:`1px solid ${R}`,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,M.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,re.getStripeMethodDisplayName)(e)}\u2026`}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,re.hasVendoredStripeMethodLogo)(e)?8:0},children:[y?(0,M.jsx)("img",{src:T,alt:"","aria-hidden":"true",onError:()=>w(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!y&&b?.logoSvg?(0,M.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:b.logoSvg}}):null,(0,M.jsx)("span",{children:(0,re.getStripeMethodDisplayName)(e)})]}),i&&(0,M.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:B,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,M.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function Mt(e){let r=new Set(e.map(re.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:i,style:d,children:p}){return(0,M.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",...d??{}},children:p})}var re,bt,M,yr,fr,xt,_t,Tt=Se(()=>{"use strict";re=require("@flopay/shared"),bt=require("react");Pt();M=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,oe.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,oe.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,oe.resolveSetupFutureUsage)({futureUse:s,futureUseUnsupported:i},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:Bt[t]?.types??[t],...L?{setupFutureUsage:L}:{},...F?{appearance:F}:{}}},[d,o,s,i,t]);return(0,O.jsx)(Z.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 R=(0,Z.useStripe)(),y=(0,Z.useElements)(),[g,w]=(0,N.useState)(!1),[B,I]=(0,N.useState)("loading"),[z,x]=(0,N.useState)(!1),[v,A]=(0,N.useState)(!1),G=(0,N.useRef)(!1),[q]=(0,N.useState)(()=>(0,Re.detectPayPalEnvironment)()),[ae,te]=(0,N.useState)(!1),m=(0,N.useCallback)((_,U)=>{if((0,P.classifyExternalMethodFailure)(_,{inAppBrowser:q.inAppBrowser,handoffObserved:!1}).popupBlocked){te(!0),b(new Error((0,P.buildExternalMethodRecoveryMessage)(At(e),!0,q.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}b(U.message===void 0?_:new Error(U.message),{code:U.code,retryable:!0})},[q.inAppBrowser,e,b]),ye=(0,N.useCallback)(async _=>{let U=!1,ie=!1,le=()=>{!_||U||ie||(ie=!0,_.paymentFailed({reason:"fail"}))};if(!R||!y||G.current){le();return}G.current=!0,w(!0);try{let Q=await y.submit();if(Q.error){le(),T(Q.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(j.provider!=="stripe"||j.intentKind!=="setup")throw new oe.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});U=!0;let H=await R.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(Q){le(),m(Q,{code:"payment_method_setup_failed"})}finally{G.current=!1,w(!1)}},[s,r,y,e,o,L,Y,F,T,m,t,R,i]),se=Bt[e]?.wallet,J=se==="paypal"&&(0,Te.resolveStripePayPalPresentation)(q,"auto",ae?"blocked":q.popupCapability)==="redirect",fe=d?.variables?.borderRadius??f?.cardButton?.borderRadius??8;if(r==="wallet"&&se&&!J)return(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(Et,{}),(0,O.jsx)(wt,{state:B,borderRadius:fe,children:(0,O.jsx)(Z.ExpressCheckoutElement,{options:{...xt,paymentMethods:Mt([e])},onReady:_=>{let U=Rt(_,[se]);I(U),U==="unavailable"&&E()},onLoadError:()=>{I("load_error"),E()},onConfirm:_=>{ye(_)}})})]});let K=At(e);return(0,O.jsxs)(O.Fragment,{children:[z?(0,O.jsx)(kt,{method:e,themeId:p,hasNextStep:!0,highlighted:v,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":!v,style:v?{display:"flex",flexDirection:"column"}:Cr,children:[(0,O.jsx)(Z.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:!R||!y||g||!v,onClick:()=>{ye()},color:d?.variables?.colorPrimary??"#4A49FF",borderRadius:d?.variables?.borderRadius??"8px",style:f?.submitButton,children:g?"Saving\u2026":`Save ${K}`})]})]})}var Ot,oe,Z,Lt,N,O,Bt,Ye,Cr,Ut=Se(()=>{"use strict";Ot=require("@flopay/js/card-setup"),oe=require("@flopay/shared"),Z=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[R]=(0,me.useState)(()=>(0,Re.detectPayPalEnvironment)().inAppBrowser);return(0,me.useEffect)(()=>{let y=!0,g,w=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 ne.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let x=I.Buttons({createVaultSetupToken:async()=>{E.current.onSubmitting();let v=await w.createSessionIntent(o,s,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:ne.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(v.provider!=="paypal"||v.providerObjectType!=="setup_token")throw new ne.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return v.providerObjectId},onApprove:async v=>{let A=v.vaultSetupToken;if(!A)throw new ne.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let G=await w.processPayment(B.userId,{sessionId:o,nonce:s,paymentMethodCategory:"paypal",tokenizedData:{id:A,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:ne.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:B});if(!G.ok)throw new ne.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:G.status});y&&E.current.onConfirmed()},onCancel:()=>{y&&E.current.onAbandoned()},onError:v=>{if(!y)return;let{popupBlocked:A}=(0,P.classifyExternalMethodFailure)(v,{inAppBrowser:R,handoffObserved:!1});E.current.onFailed(A?new Error((0,P.buildExternalMethodRecoveryMessage)("PayPal",!0,R)):v,{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(()=>{}),w.destroy()}},[i,e,t,f,r,R,s,o,d,p]),(0,Yt.jsx)("div",{ref:T,"data-flopay-paypal-setup":""})}var Dt,ne,Vt,me,Yt,Wt=Se(()=>{"use strict";Dt=require("@flopay/js/card-setup"),ne=require("@flopay/shared"),Vt=require("@paypal/paypal-js"),me=require("react");Ve();Ne();Yt=require("react/jsx-runtime")});var wr={};Oe(wr,{FloPayCardSetupError:()=>be,FloPayPaymentMethodSetup:()=>zt});module.exports=tr(wr);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 $=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: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,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)",...p.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:p.spinnerTrackColor,strokeWidth:"3"}),(0,S.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:p.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:p.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(s??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&d!==null&&(0,S.jsx)("p",{style:f,children:d}),e==="error"&&r&&(0,S.jsx)("p",{style:f,children:r}),(0,S.jsx)("style",{children:`
|
|
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:`
|
|
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 R=(0,W.useRef)(i);R.current=i;let y=(0,W.useRef)(null),g=d??void 0,w=(0,W.useRef)(g);w.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,v=()=>{!z||x||(x=!0,b.current?.())},A=e.on("ready",()=>{v()}),G=e.on("error",m=>{T.current?.(m.message??"There was a problem loading the secure card form.")}),q=e.on("validation",m=>{E.current?.(m.message??null)}),ae=w.current??(Ie.has(e)?null:void 0),te={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...R.current?{theme:R.current}:{},...ae===void 0?{}:{submitLabel:ae}};return y.current=R.current??null,B.current=w.current,w.current!==void 0&&Ie.add(e),e.mount(I,te).then(()=>{v()}).catch(m=>{z&&T.current?.(m instanceof Error?m.message:"Failed to load the secure card form.")}),()=>{z=!1,A(),G(),q(),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:R,onError:y}){let[g]=(0,a.useState)(ve.readSetupRedirectReturn),[w,B]=(0,a.useState)(null),[I,z]=(0,a.useState)(!1),[x,v]=(0,a.useState)(null),[A,G]=(0,a.useState)(null),[q,ae]=(0,a.useState)(null),[te,m]=(0,a.useState)(null),[ye,se]=(0,a.useState)(()=>new Set),J=(0,a.useRef)(ye),fe=(0,a.useRef)(null);fe.current=w;let K=(0,a.useRef)(!1),_=(0,a.useRef)(!1),U=(0,a.useRef)(!1),ie=(0,a.useRef)(!1),le=(0,a.useRef)(0),Q=(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:R,onError:y});D.current={sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:Y,onComplete:b,onDecline:T,onCancel:E,onValidation:R,onError:y},(0,a.useEffect)(()=>{j.current=!0;let n=le.current+1;return le.current=n,()=>{j.current=!1,Q.current+=1,queueMicrotask(()=>{le.current===n&&(U.current||ie.current||(ie.current=!0,(0,$.invokeMerchantCallback)(()=>{D.current.onCancel?.({status:"cancelled",sessionId:t})})))})}},[t]);let he=(0,a.useCallback)((n,l)=>{U.current=!0,K.current=!1,m({status:"success",wording:n,message:null}),(async()=>(await De(600),!_.current&&(_.current=!0,(0,$.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,K.current=!1,m({status:"error",wording:n,message:l.message??null}),(0,$.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)))()},[]),re=(0,a.useCallback)((n,l)=>{K.current?(K.current=!1,m({status:"error",wording:n,message:l.message}),setTimeout(()=>{j.current&&m(null)},400)):m(null),(0,$.invokeMerchantCallback)(()=>D.current.onError?.(l))},[]),we=(0,a.useCallback)(async n=>{let l=Q.current+1;Q.current=l;let c=()=>!j.current||l!==Q.current;K.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 X=await V.getUnifiedCheckoutSession(D.current.sessionId,D.current.nonce);if(c())return;let ue=X.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 X=u instanceof C.FloPayError&&u.code==="payment_method_setup_unverified";re("payment_method",ce(u,X?{retryable:!0}:{}))}finally{V.destroy()}},[re,he]);(0,a.useEffect)(()=>{let n=!0,l=(0,C.resolveBillingApiUrl)(s),c=new Ee.PaymentAPI(l,{telemetry:i});B(null),z(!1),v(null),G(null),ae(null);let V=new Set;return J.current=V,se(V),U.current=!1,ie.current=!1,_.current=!1,(async()=>{try{let{session:u,advertisement:X}=await pr(c,t,o);if(!n)return;let ue={advertisement:X,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"}):we({waitFirst:!0})}let ut=X.card?await cr(c,u,t,o,l):null;if(!n)return;B(ue),ut&&(G(ut),v(new Ee.PciVaultCardCapture({sessionId:t,operation:"card_setup",telemetry:i})))}catch(u){if(!n)return;let X=ce(u);U.current=!0,ae(X),(0,$.invokeMerchantCallback)(()=>D.current.onError?.(X))}})(),()=>{n=!1,c.destroy()}},[s,o,g,ge,he,t,i,we]),(0,a.useEffect)(()=>{if(!x)return;K.current=!1;let n=x.on("submitting",()=>{K.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){re("payment_method",ce(l,c));return}if(J.current.has(n))return;let V=new Set(J.current);V.add(n),J.current=V,se(V);let u=fe.current?.advertisement,X=u?(0,k.advertisedMethodKeys)(u).some(ue=>!V.has(ue)):!1;re("payment_method",ce(l,{code:c.code,retryable:X}))},[re]),qe=(0,a.useMemo)(()=>({onSubmitting:()=>{K.current=!0,m({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{we({waitFirst:!1})},onDeclined:n=>ge("payment_method",n),onValidation:n=>{(0,$.invokeMerchantCallback)(()=>D.current.onValidation?.(n))},onAbandoned:()=>{K.current=!1,m(null)}}),[ge,we]),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(J.current.has(n))return;let l=new Set(J.current);l.add(n),J.current=l,se(l);let c=fe.current?.advertisement;c&&(0,k.advertisedMethodKeys)(c).some(u=>!l.has(u))||re("payment_method",ce(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[re]),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=te?(0,h.jsx)(mt,{status:te.status,errorMessage:te.message,...(0,k.setupOverlayLabels)(te.wording),successNote:null,...He?{theme:He}:{}}):null;if(q)return(0,h.jsx)("div",{role:"alert",children:q.message});if(!w||I)return(0,h.jsxs)(h.Fragment,{children:[tt,w?null:L]});let{advertisement:Ce,customer:Kt,futureUse:rt,futureUseUnsupported:ot}=w,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,$.invokeMerchantCallback)(()=>D.current.onReady?.())},onValidation:n=>{(0,$.invokeMerchantCallback)(()=>D.current.onValidation?.(n))},onError:n=>{n&&re("card",ce(new Error(n),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var Ht=require("react/jsx-runtime"),Rr={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:Rr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
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});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-D4CVZRT4.mjs";import{h as a}from"./chunk-YR36EYW2.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-
|
|
1
|
+
import{a as t}from"./chunk-D4CVZRT4.mjs";import{h as a}from"./chunk-YR36EYW2.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a}from"./chunk-BU7THP6H.mjs";import"./chunk-VK67324N.mjs";export{a as PayPalSetupMethod};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{k as a}from"./chunk-FGCZOMML.mjs";import"./chunk-VK67324N.mjs";export{a as StripeSetupMethod};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopay/react",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@flopay/js": "1.14.
|
|
40
|
-
"@flopay/shared": "1.14.
|
|
39
|
+
"@flopay/js": "1.14.10",
|
|
40
|
+
"@flopay/shared": "1.14.10",
|
|
41
41
|
"@paypal/paypal-js": "^10.1.0",
|
|
42
|
-
"@stripe/react-stripe-js": "^
|
|
43
|
-
"@stripe/stripe-js": "^
|
|
42
|
+
"@stripe/react-stripe-js": "^7.0.1",
|
|
43
|
+
"@stripe/stripe-js": "^10.2.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=18.0.0",
|
package/dist/chunk-HSYSKQPT.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as T,b as A,j as R}from"./chunk-VK67324N.mjs";import{PaymentAPI as I}from"@flopay/js/card-setup";import{FloPayError as p,PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as B}from"@flopay/shared";import{loadScript as x}from"@paypal/paypal-js";import{useEffect as D,useRef as C,useState as O}from"react";import{jsx as F}from"react/jsx-runtime";function z({clientId:d,environment:o,currency:s,sessionId:i,nonce:l,billingApiUrl:y,telemetry:f,customer:{userId:m,email:P},onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b}){let w=C(null),t=C({onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b});t.current={onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b};let[c]=O(()=>R().inAppBrowser);return D(()=>{let a=!0,k,u=new I(y,{telemetry:f}),g={userId:m,email:P};return(async()=>{try{let n=await x({clientId:d,...s?{currency:s.toUpperCase()}:{},components:"buttons",...o==="sandbox"||o==="production"?{environment:o}:{}}),M=w.current;if(!a||!M)return;if(!n?.Buttons)throw new p("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let E=n.Buttons({createVaultSetupToken:async()=>{t.current.onSubmitting();let e=await u.createSessionIntent(i,l,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:B,paymentMethodId:null,intentKind:"setup"});if(e.provider!=="paypal"||e.providerObjectType!=="setup_token")throw new p("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return e.providerObjectId},onApprove:async e=>{let r=e.vaultSetupToken;if(!r)throw new p("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let S=await u.processPayment(g.userId,{sessionId:i,nonce:l,paymentMethodCategory:"paypal",tokenizedData:{id:r,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:B},accountData:g});if(!S.ok)throw new p("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:S.status});a&&t.current.onConfirmed()},onCancel:()=>{a&&t.current.onAbandoned()},onError:e=>{if(!a)return;let{popupBlocked:r}=A(e,{inAppBrowser:c,handoffObserved:!1});t.current.onFailed(r?new Error(T("PayPal",!0,c)):e,{code:r?"popup_blocked":"paypal_setup_failed",retryable:!0})}});k=()=>E.close(),await E.render(M)}catch(n){if(!a)return;t.current.onFailed(n,{code:"paypal_unavailable",retryable:!0})}})(),()=>{a=!1,k?.().catch(()=>{}),u.destroy()}},[y,d,s,P,o,c,l,i,f,m]),F("div",{ref:w,"data-flopay-paypal-setup":""})}export{z as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-HSYSKQPT.mjs";import"./chunk-VK67324N.mjs";export{a as PayPalSetupMethod};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{k as a}from"./chunk-JCJFICSM.mjs";import"./chunk-VK67324N.mjs";export{a as StripeSetupMethod};
|