@flopay/react 1.13.5 → 1.14.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -1
- package/dist/chunk-MSABDKVT.mjs +22 -0
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +19 -3
- package/dist/index.d.ts +19 -3
- 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-stripe-ULXLO3FW.mjs +1 -0
- package/package.json +3 -3
- package/dist/chunk-H4MQCBX4.mjs +0 -22
- package/dist/payment-method-setup-stripe-6O2YE4RY.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var jt=Object.create;var
|
|
1
|
+
"use strict";var jt=Object.create;var we=Object.defineProperty;var $t=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var Jt=Object.getPrototypeOf,Qt=Object.prototype.hasOwnProperty;var fe=(e,r)=>()=>(e&&(r=e(e=0)),r);var Ae=(e,r)=>{for(var t in r)we(e,t,{get:r[t],enumerable:!0})},ut=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Zt(r))!Qt.call(e,s)&&s!==t&&we(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)):{},ut(r||!e||!e.__esModule?we(t,"default",{value:e,enumerable:!0}):t,e)),tr=e=>ut(we({},"__esModule",{value:!0}),e);var P,De=fe(()=>{"use strict";P=require("@flopay/shared")});var mr,Pe,xe,Ve=fe(()=>{"use strict";mr=require("@flopay/shared"),Pe=require("@flopay/shared"),xe=require("@flopay/shared")});var vt,Ct=fe(()=>{"use strict";vt={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 bt(){return(0,M.jsx)("style",{children:yr})}function Et(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 wt({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:B,fontFamily:W}){let b=(0,J.resolveStripeMethodBrandVariant)(e,r),T=vt[e],[E,R]=(0,Pt.useState)(!1),y=!!T&&!E,g=b?.backgroundColor??p??"#ffffff",w=b?.borderColor??f??"#d1d5db",I=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:I,border:`1px solid ${w}`,borderRadius:B??8,fontSize:"0.95rem",fontWeight:600,fontFamily:W,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,J.getStripeMethodDisplayName)(e)}\u2026`}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,J.hasVendoredStripeMethodLogo)(e)?8:0},children:[y?(0,M.jsx)("img",{src:T,alt:"","aria-hidden":"true",onError:()=>R(!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,J.getStripeMethodDisplayName)(e)})]}),i&&(0,M.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:I,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:"1rem",top:"50%",transform:"translateY(-50%)",flexShrink:0,opacity:.7},"aria-hidden":"true",children:(0,M.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function kt(e){let r=new Set(e.map(J.stripeExpressMethodToOptionKey));return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(t=>[t,r.has(t)?"auto":"never"]))}function xt({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 J,Pt,M,yr,fr,Mt,_t,Ft=fe(()=>{"use strict";J=require("@flopay/shared"),Pt=require("react");Ct();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;Mt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},_t={type:"accordion",defaultCollapsed:!1,radios:"never"}});var Bt={};Ae(Bt,{StripeSetupMethod:()=>Pr});function hr(e){let r=Ne.get(e);if(r)return r;let t=(0,Ot.loadStripe)(e).catch(o=>{throw Ne.delete(e),o});return Ne.set(e,t),t}function gr(e){return e?(0,te.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 Tt(e){return e==="paypal"?"PayPal":(0,te.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,Y.useState)(()=>hr(r)),f=(0,Y.useMemo)(()=>{let F=gr(d),B=(0,te.resolveSetupFutureUsage)({futureUse:s,futureUseUnsupported:i},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:Lt[t]?.types??[t],...B?{setupFutureUsage:B}:{},...F?{appearance:F}:{}}},[d,o,s,i,t]);return(0,L.jsx)($.Elements,{stripe:p,options:f,children:(0,L.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:B,onDeclined:W,onFailed:b,onValidation:T,onUnavailable:E}){let w=(0,$.useStripe)(),y=(0,$.useElements)(),[g,R]=(0,Y.useState)(!1),[I,U]=(0,Y.useState)("loading"),[H,_]=(0,Y.useState)(!1),[v,A]=(0,Y.useState)(!1),G=(0,Y.useRef)(!1),[q]=(0,Y.useState)(()=>(0,Pe.detectPayPalEnvironment)()),[oe,Q]=(0,Y.useState)(!1),m=(0,Y.useCallback)((x,O)=>{if((0,P.classifyExternalMethodFailure)(x,{inAppBrowser:q.inAppBrowser,handoffObserved:!1}).popupBlocked){Q(!0),b(new Error((0,P.buildExternalMethodRecoveryMessage)(Tt(e),!0,q.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}b(O.message===void 0?x:new Error(O.message),{code:O.code,retryable:!0})},[q.inAppBrowser,e,b]),de=(0,Y.useCallback)(async()=>{if(!(!w||!y||G.current)){G.current=!0,R(!0);try{let x=await y.submit();if(x.error){T(x.error.message??null);return}F();let O=await new At.PaymentAPI(s,{telemetry:i}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(O.provider!=="stripe"||O.intentKind!=="setup")throw new te.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let D=await w.confirmSetup({elements:y,clientSecret:O.clientSecret,confirmParams:{return_url:vr()},redirect:"if_required"});if(D.error){Sr(D.error)?W({...D.error.decline_code||D.error.code?{reason:D.error.decline_code??D.error.code}:{},...D.error.message?{message:D.error.message}:{}}):m(D.error,{code:"payment_method_setup_provider_failed",message:D.error.message??"The payment method could not be saved."});return}B()}catch(x){m(x,{code:"payment_method_setup_failed"})}finally{G.current=!1,R(!1)}}},[s,r,y,e,o,B,W,F,T,m,t,w,i]),ne=Lt[e]?.wallet,Z=ne==="paypal"&&(0,xe.resolveStripePayPalPresentation)(q,"auto",oe?"blocked":q.popupCapability)==="redirect",pe=d?.variables?.borderRadius??f?.cardButton?.borderRadius??8;if(r==="wallet"&&ne&&!Z)return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(bt,{}),(0,L.jsx)(wt,{state:I,borderRadius:pe,children:(0,L.jsx)($.ExpressCheckoutElement,{options:{...Mt,paymentMethods:kt([e])},onReady:x=>{let O=Et(x,[ne]);U(O),O==="unavailable"&&E()},onLoadError:()=>{U("load_error"),E()},onConfirm:()=>{de()}})})]});let K=Tt(e);return(0,L.jsxs)(L.Fragment,{children:[H?(0,L.jsx)(Rt,{method:e,themeId:p,hasNextStep:!0,highlighted:v,disabled:g,onClick:()=>A(x=>!x),backgroundColor:f?.cardButton?.backgroundColor,borderColor:f?.cardInputBorder,textColor:f?.cardButton?.color,borderRadius:pe}):null,(0,L.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!v,style:v?{display:"flex",flexDirection:"column"}:Cr,children:[(0,L.jsx)($.PaymentElement,{options:{layout:_t},onReady:()=>_(!0),onLoadError:()=>E(),onChange:x=>{x.complete&&T(null)}}),(0,L.jsx)(xt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!w||!y||g||!v,onClick:()=>{de()},color:d?.variables?.colorPrimary??"#4A49FF",borderRadius:d?.variables?.borderRadius??"8px",style:f?.submitButton,children:g?"Saving\u2026":`Save ${K}`})]})]})}var At,te,$,Ot,Y,L,Lt,Ne,Cr,It=fe(()=>{"use strict";At=require("@flopay/js/card-setup"),te=require("@flopay/shared"),$=require("@stripe/react-stripe-js"),Ot=require("@stripe/stripe-js"),Y=require("react");De();Ve();Ft();L=require("react/jsx-runtime"),Lt={apple_pay:{types:["card"],wallet:"applePay"},google_pay:{types:["card"],wallet:"googlePay"},link:{types:["link"],wallet:"link"},paypal:{types:["paypal"],wallet:"paypal"},amazon_pay:{types:["amazon_pay"],wallet:"amazonPay"}},Ne=new Map;Cr={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var Vt={};Ae(Vt,{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:B,onFailed:W,onAbandoned:b}){let T=(0,ue.useRef)(null),E=(0,ue.useRef)({onSubmitting:F,onConfirmed:B,onFailed:W,onAbandoned:b});E.current={onSubmitting:F,onConfirmed:B,onFailed:W,onAbandoned:b};let[w]=(0,ue.useState)(()=>(0,Pe.detectPayPalEnvironment)().inAppBrowser);return(0,ue.useEffect)(()=>{let y=!0,g,R=new Ut.PaymentAPI(i,{telemetry:d}),I={userId:p,email:f};return(async()=>{try{let U=await(0,Dt.loadScript)({clientId:e,...t?{currency:t.toUpperCase()}:{},components:"buttons",...r==="sandbox"||r==="production"?{environment:r}:{}}),H=T.current;if(!y||!H)return;if(!U?.Buttons)throw new re.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let _=U.Buttons({createVaultSetupToken:async()=>{E.current.onSubmitting();let v=await R.createSessionIntent(o,s,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:re.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(v.provider!=="paypal"||v.providerObjectType!=="setup_token")throw new re.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 re.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let G=await R.processPayment(I.userId,{sessionId:o,nonce:s,paymentMethodCategory:"paypal",tokenizedData:{id:A,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:re.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:I});if(!G.ok)throw new re.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:w,handoffObserved:!1});E.current.onFailed(A?new Error((0,P.buildExternalMethodRecoveryMessage)("PayPal",!0,w)):v,{code:A?"popup_blocked":"paypal_setup_failed",retryable:!0})}});g=()=>_.close(),await _.render(H)}catch(U){if(!y)return;E.current.onFailed(U,{code:"paypal_unavailable",retryable:!0})}})(),()=>{y=!1,g?.().catch(()=>{}),R.destroy()}},[i,e,t,f,r,w,s,o,d,p]),(0,Nt.jsx)("div",{ref:T,"data-flopay-paypal-setup":""})}var Ut,re,Dt,ue,Nt,Yt=fe(()=>{"use strict";Ut=require("@flopay/js/card-setup"),re=require("@flopay/shared"),Dt=require("@paypal/paypal-js"),ue=require("react");De();Ve();Nt=require("react/jsx-runtime")});var Rr={};Ae(Rr,{FloPayCardSetupError:()=>ve,FloPayPaymentMethodSetup:()=>Wt});module.exports=tr(Rr);var ht=require("@flopay/js/card-setup"),ie=require("@flopay/shared"),Me=require("react");var Oe=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 dt(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 Le=require("@flopay/shared"),ar=require("@flopay/shared");function pt(e){let r=(0,Le.resolveCardSetupTheme)(e);return{...r,surface:r.surface,overlayTheme:r.overlayTheme}}var j=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 ct({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;Mt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},_t={type:"accordion",defaultCollapsed:!1,radios:"never"}});var Bt={};Ae(Bt,{StripeSetupMethod:()=>Pr});function hr(e){let r=Ne.get(e);if(r)return r;let t=(0,Ot.loadStripe)(e).catch(o=>{throw Ne.delete(e),o});return Ne.set(e,t),t}function gr(e){return e?(0,te.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 Tt(e){return e==="paypal"?"PayPal":(0,te.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,Y.useState)(()=>hr(r)),f=(0,Y.useMemo)(()=>{let F=gr(d),B=(0,te.resolveSetupFutureUsage)({futureUse:s,futureUseUnsupported:i},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:Lt[t]?.types??[t],...B?{setupFutureUsage:B}:{},...F?{appearance:F}:{}}},[d,o,s,i,t]);return(0,L.jsx)($.Elements,{stripe:p,options:f,children:(0,L.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:B,onDeclined:W,onFailed:b,onValidation:T,onUnavailable:E}){let R=(0,$.useStripe)(),y=(0,$.useElements)(),[g,w]=(0,Y.useState)(!1),[I,U]=(0,Y.useState)("loading"),[H,_]=(0,Y.useState)(!1),[v,A]=(0,Y.useState)(!1),G=(0,Y.useRef)(!1),[q]=(0,Y.useState)(()=>(0,Pe.detectPayPalEnvironment)()),[oe,Q]=(0,Y.useState)(!1),m=(0,Y.useCallback)((x,O)=>{if((0,P.classifyExternalMethodFailure)(x,{inAppBrowser:q.inAppBrowser,handoffObserved:!1}).popupBlocked){Q(!0),b(new Error((0,P.buildExternalMethodRecoveryMessage)(Tt(e),!0,q.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}b(O.message===void 0?x:new Error(O.message),{code:O.code,retryable:!0})},[q.inAppBrowser,e,b]),de=(0,Y.useCallback)(async()=>{if(!(!R||!y||G.current)){G.current=!0,w(!0);try{let x=await y.submit();if(x.error){T(x.error.message??null);return}F();let O=await new At.PaymentAPI(s,{telemetry:i}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(O.provider!=="stripe"||O.intentKind!=="setup")throw new te.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let D=await R.confirmSetup({elements:y,clientSecret:O.clientSecret,confirmParams:{return_url:vr()},redirect:"if_required"});if(D.error){Sr(D.error)?W({...D.error.decline_code||D.error.code?{reason:D.error.decline_code??D.error.code}:{},...D.error.message?{message:D.error.message}:{}}):m(D.error,{code:"payment_method_setup_provider_failed",message:D.error.message??"The payment method could not be saved."});return}B()}catch(x){m(x,{code:"payment_method_setup_failed"})}finally{G.current=!1,w(!1)}}},[s,r,y,e,o,B,W,F,T,m,t,R,i]),ne=Lt[e]?.wallet,Z=ne==="paypal"&&(0,xe.resolveStripePayPalPresentation)(q,"auto",oe?"blocked":q.popupCapability)==="redirect",pe=d?.variables?.borderRadius??f?.cardButton?.borderRadius??8;if(r==="wallet"&&ne&&!Z)return(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)(bt,{}),(0,L.jsx)(Rt,{state:I,borderRadius:pe,children:(0,L.jsx)($.ExpressCheckoutElement,{options:{...Mt,paymentMethods:kt([e])},onReady:x=>{let O=Et(x,[ne]);U(O),O==="unavailable"&&E()},onLoadError:()=>{U("load_error"),E()},onConfirm:()=>{de()}})})]});let K=Tt(e);return(0,L.jsxs)(L.Fragment,{children:[H?(0,L.jsx)(wt,{method:e,themeId:p,hasNextStep:!0,highlighted:v,disabled:g,onClick:()=>A(x=>!x),backgroundColor:f?.cardButton?.backgroundColor,borderColor:f?.cardInputBorder,textColor:f?.cardButton?.color,borderRadius:pe}):null,(0,L.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!v,style:v?{display:"flex",flexDirection:"column"}:Cr,children:[(0,L.jsx)($.PaymentElement,{options:{layout:_t},onReady:()=>_(!0),onLoadError:()=>E(),onChange:x=>{x.complete&&T(null)}}),(0,L.jsx)(xt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!R||!y||g||!v,onClick:()=>{de()},color:d?.variables?.colorPrimary??"#4A49FF",borderRadius:d?.variables?.borderRadius??"8px",style:f?.submitButton,children:g?"Saving\u2026":`Save ${K}`})]})]})}var At,te,$,Ot,Y,L,Lt,Ne,Cr,It=fe(()=>{"use strict";At=require("@flopay/js/card-setup"),te=require("@flopay/shared"),$=require("@stripe/react-stripe-js"),Ot=require("@stripe/stripe-js"),Y=require("react");De();Ve();Ft();L=require("react/jsx-runtime"),Lt={apple_pay:{types:["card"],wallet:"applePay"},google_pay:{types:["card"],wallet:"googlePay"},link:{types:["link"],wallet:"link"},paypal:{types:["paypal"],wallet:"paypal"},amazon_pay:{types:["amazon_pay"],wallet:"amazonPay"}},Ne=new Map;Cr={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var Vt={};Ae(Vt,{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:B,onFailed:W,onAbandoned:b}){let T=(0,ue.useRef)(null),E=(0,ue.useRef)({onSubmitting:F,onConfirmed:B,onFailed:W,onAbandoned:b});E.current={onSubmitting:F,onConfirmed:B,onFailed:W,onAbandoned:b};let[R]=(0,ue.useState)(()=>(0,Pe.detectPayPalEnvironment)().inAppBrowser);return(0,ue.useEffect)(()=>{let y=!0,g,w=new Ut.PaymentAPI(i,{telemetry:d}),I={userId:p,email:f};return(async()=>{try{let U=await(0,Dt.loadScript)({clientId:e,...t?{currency:t.toUpperCase()}:{},components:"buttons",...r==="sandbox"||r==="production"?{environment:r}:{}}),H=T.current;if(!y||!H)return;if(!U?.Buttons)throw new re.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let _=U.Buttons({createVaultSetupToken:async()=>{E.current.onSubmitting();let v=await w.createSessionIntent(o,s,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:re.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(v.provider!=="paypal"||v.providerObjectType!=="setup_token")throw new re.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 re.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let G=await w.processPayment(I.userId,{sessionId:o,nonce:s,paymentMethodCategory:"paypal",tokenizedData:{id:A,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:re.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:I});if(!G.ok)throw new re.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=()=>_.close(),await _.render(H)}catch(U){if(!y)return;E.current.onFailed(U,{code:"paypal_unavailable",retryable:!0})}})(),()=>{y=!1,g?.().catch(()=>{}),w.destroy()}},[i,e,t,f,r,R,s,o,d,p]),(0,Nt.jsx)("div",{ref:T,"data-flopay-paypal-setup":""})}var Ut,re,Dt,ue,Nt,Yt=fe(()=>{"use strict";Ut=require("@flopay/js/card-setup"),re=require("@flopay/shared"),Dt=require("@paypal/paypal-js"),ue=require("react");De();Ve();Nt=require("react/jsx-runtime")});var wr={};Ae(wr,{FloPayCardSetupError:()=>ve,FloPayPaymentMethodSetup:()=>Wt});module.exports=tr(wr);var ht=require("@flopay/js/card-setup"),ie=require("@flopay/shared"),Me=require("react");var Oe=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 dt(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 Le=require("@flopay/shared"),ar=require("@flopay/shared");function pt(e){let r=(0,Le.resolveCardSetupTheme)(e);return{...r,surface:r.surface,overlayTheme:r.overlayTheme}}var j=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 ct({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:`
|
|
23
23
|
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
24
24
|
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
25
25
|
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
26
26
|
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
27
|
-
`})]})})}var z=require("react");var ke=require("react"),mt=typeof window>"u"?ke.useEffect:ke.useLayoutEffect;var se=require("react/jsx-runtime"),Be=new WeakSet;function yt({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:s,theme:i,submitLabel:d,containerStyle:p,onReady:f,onError:F,onValidation:B}){let W=(0,z.useRef)(null),b=(0,z.useRef)(f),T=(0,z.useRef)(F),E=(0,z.useRef)(B);b.current=f,T.current=F,E.current=B;let w=(0,z.useRef)(i);w.current=i;let y=(0,z.useRef)(null),g=d??void 0,R=(0,z.useRef)(g);R.current=g;let I=(0,z.useRef)(void 0);return(0,z.useEffect)(()=>{let U=W.current;if(!U)return;let H=!0,_=!1,v=()=>{!H||_||(_=!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)}),oe=R.current??(Be.has(e)?null:void 0),Q={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...w.current?{theme:w.current}:{},...oe===void 0?{}:{submitLabel:oe}};return y.current=w.current??null,I.current=R.current,R.current!==void 0&&Be.add(e),e.mount(U,Q).then(()=>{v()}).catch(m=>{H&&T.current?.(m instanceof Error?m.message:"Failed to load the secure card form.")}),()=>{H=!1,A(),G(),q(),e.unmount()}},[e,r,t,o,s]),mt(()=>{let U=W.current;U&&dt(U,p)},[p]),(0,z.useEffect)(()=>{i!==void 0&&(i===null&&y.current===null||(y.current=i,e.applyTheme?.(i)))},[e,i]),(0,z.useEffect)(()=>{g!==I.current&&(I.current=g,g!==void 0&&Be.add(e),e.setSubmitLabel?.(g??null))},[e,g]),(0,se.jsx)("div",{ref:W,"data-testid":"flopay-vault-card-fields"})}function ft({label:e}){return(0,se.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,se.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,se.jsx)("span",{children:e}),(0,se.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var Ie=require("react/jsx-runtime"),ve=class extends ie.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function le(e,r={}){let t=e instanceof ie.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 ve(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:s,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}var Ye=require("react");var Ce=require("@flopay/js/card-setup"),C=require("@flopay/shared"),a=er(require("react"),1);var he=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 Ue(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 _e=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 St({branches:{StripeSetupMethod:e,PayPalSetupMethod:r},sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,theme:d="modern-light",containerStyle:p,appearance:f,buttonsStyles:F,loading:B=null,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:w,onError:y}){let[g]=(0,a.useState)(he.readSetupRedirectReturn),[R,I]=(0,a.useState)(null),[U,H]=(0,a.useState)(!1),[_,v]=(0,a.useState)(null),[A,G]=(0,a.useState)(null),[q,oe]=(0,a.useState)(null),[Q,m]=(0,a.useState)(null),[de,ne]=(0,a.useState)(()=>new Set),Z=(0,a.useRef)(de),pe=(0,a.useRef)(null);pe.current=R;let K=(0,a.useRef)(!1),x=(0,a.useRef)(!1),O=(0,a.useRef)(!1),D=(0,a.useRef)(!1),Fe=(0,a.useRef)(0),be=(0,a.useRef)(0),ce=(0,a.useRef)(!1),{vaultTheme:Ht,surface:We,overlayTheme:ze,appearance:He,buttonsLayout:Ge}=(0,a.useMemo)(()=>pt({theme:d,appearance:f,buttonsStyles:F}),[d,f,F]),Gt=(0,a.useMemo)(()=>(0,Oe.mergeCardSetupSurface)(We,p),[We,p]),V=(0,a.useRef)({sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:w,onError:y});V.current={sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:w,onError:y},(0,a.useEffect)(()=>{ce.current=!0;let n=Fe.current+1;return Fe.current=n,()=>{ce.current=!1,be.current+=1,queueMicrotask(()=>{Fe.current===n&&(O.current||D.current||(D.current=!0,(0,j.invokeMerchantCallback)(()=>{V.current.onCancel?.({status:"cancelled",sessionId:t})})))})}},[t]);let me=(0,a.useCallback)((n,l)=>{O.current=!0,K.current=!1,m({status:"success",wording:n,message:null}),(async()=>(await Ue(600),!x.current&&(x.current=!0,(0,j.invokeMerchantCallback)(()=>{V.current.onComplete?.({status:"succeeded",sessionId:V.current.sessionId,...l?{paymentMethod:l}:{}})}),ce.current&&m(null))))()},[]),ye=(0,a.useCallback)((n,l)=>{O.current=!0,K.current=!1,m({status:"error",wording:n,message:l.message??null}),(0,j.invokeMerchantCallback)(()=>{V.current.onDecline?.({status:"declined",sessionId:V.current.sessionId,...l.reason?{reason:l.reason}:{},...l.message?{message:l.message}:{}})}),(async()=>(await Ue(400),ce.current&&m(null)))()},[]),ee=(0,a.useCallback)((n,l)=>{K.current?(K.current=!1,m({status:"error",wording:n,message:l.message}),setTimeout(()=>{ce.current&&m(null)},400)):m(null),(0,j.invokeMerchantCallback)(()=>V.current.onError?.(l))},[]),Ee=(0,a.useCallback)(async n=>{let l=be.current+1;be.current=l;let c=()=>!ce.current||l!==be.current;K.current=!0,m({status:"processing",wording:"payment_method",message:null});let N=new Ce.PaymentAPI((0,C.resolveBillingApiUrl)(V.current.billingApiUrl),{telemetry:V.current.telemetry});try{for(let u=0;u<lr;u+=1){if((u>0||n.waitFirst)&&await Ue(ur),c())return;let X=await N.getUnifiedCheckoutSession(V.current.sessionId,V.current.nonce);if(c())return;let ae=X.data.session?.status;if(ae==="complete"){H(!0),me("payment_method");return}if(ae==="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";ee("payment_method",le(u,X?{retryable:!0}:{}))}finally{N.destroy()}},[ee,me]);(0,a.useEffect)(()=>{let n=!0,l=(0,C.resolveBillingApiUrl)(s),c=new Ce.PaymentAPI(l,{telemetry:i});I(null),H(!1),v(null),G(null),oe(null);let N=new Set;return Z.current=N,ne(N),O.current=!1,D.current=!1,x.current=!1,(async()=>{try{let{session:u,advertisement:X}=await pr(c,t,o);if(!n)return;let ae={advertisement:X,customer:dr(u),...u.futureUse?{futureUse:u.futureUse}:{},...u.futureUseUnsupported?{futureUseUnsupported:u.futureUseUnsupported}:{}};if(g){if((0,he.clearSetupRedirectParams)(),u.status==="complete"){H(!0),I(ae),me("payment_method");return}g.failed?ye("payment_method",{reason:"redirect_failed"}):Ee({waitFirst:!0})}let lt=X.card?await cr(c,u,t,o,l):null;if(!n)return;I(ae),lt&&(G(lt),v(new Ce.PciVaultCardCapture({sessionId:t,operation:"card_setup",telemetry:i})))}catch(u){if(!n)return;let X=le(u);O.current=!0,oe(X),(0,j.invokeMerchantCallback)(()=>V.current.onError?.(X))}})(),()=>{n=!1,c.destroy()}},[s,o,g,ye,me,t,i,Ee]),(0,a.useEffect)(()=>{if(!_)return;K.current=!1;let n=_.on("submitting",()=>{K.current=!0,m({status:"processing",wording:"card",message:null})}),l=_.on("complete",u=>{me("card",u.paymentMethod)}),c=_.on("decline",u=>{ye("card",{...u.declineReason?{reason:u.declineReason}:{},...u.message?{message:u.message}:{}})}),N=_.on("challenge_dismissed",()=>{m(null)});return()=>{n(),l(),c(),N()}},[_,ye,me]);let Ke=(0,a.useCallback)((n,l,c)=>{if(c.retryable){ee("payment_method",le(l,c));return}if(Z.current.has(n))return;let N=new Set(Z.current);N.add(n),Z.current=N,ne(N);let u=pe.current?.advertisement,X=u?(0,k.advertisedMethodKeys)(u).some(ae=>!N.has(ae)):!1;ee("payment_method",le(l,{code:c.code,retryable:X}))},[ee]),Xe=(0,a.useMemo)(()=>({onSubmitting:()=>{K.current=!0,m({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{Ee({waitFirst:!1})},onDeclined:n=>ye("payment_method",n),onValidation:n=>{(0,j.invokeMerchantCallback)(()=>V.current.onValidation?.(n))},onAbandoned:()=>{K.current=!1,m(null)}}),[ye,Ee]),qe=(0,a.useRef)(Ke);qe.current=Ke;let je=(0,a.useRef)(new Map),we=n=>{let l=je.current.get(n);if(l)return l;let c=(N,u)=>qe.current(n,N,u);return je.current.set(n,c),c},$e=(0,a.useCallback)(n=>{if(Z.current.has(n))return;let l=new Set(Z.current);l.add(n),Z.current=l,ne(l);let c=pe.current?.advertisement;c&&(0,k.advertisedMethodKeys)(c).some(u=>!l.has(u))||ee("payment_method",le(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[ee]),Ze=(0,a.useRef)($e);Ze.current=$e;let Je=(0,a.useRef)(new Map),Qe=n=>{let l=Je.current.get(n);if(l)return l;let c=()=>Ze.current(n);return Je.current.set(n,c),c},et=Q?(0,h.jsx)(ct,{status:Q.status,errorMessage:Q.message,...(0,k.setupOverlayLabels)(Q.wording),successNote:null,...ze?{theme:ze}:{}}):null;if(q)return(0,h.jsx)("div",{role:"alert",children:q.message});if(!R||U)return(0,h.jsxs)(h.Fragment,{children:[et,R?null:B]});let{advertisement:ge,customer:Kt,futureUse:tt,futureUseUnsupported:rt}=R,ot=(0,C.resolveBillingApiUrl)(s),nt=i===void 0?{}:{telemetry:i},Te=ge.stripe.filter(({method:n})=>!de.has(n)),Se=de.has("paypal")?null:ge.paypal,at=!!(ge.card&&_&&A?.html),st=({method:n,publishableKey:l,currency:c})=>(0,h.jsx)("div",{"data-flopay-payment-method":n,style:{display:"contents"},children:(0,h.jsx)(_e,{onFailed:we(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,...tt?{futureUse:tt}:{},...rt?{futureUseUnsupported:rt}:{},sessionId:t,nonce:o,billingApiUrl:ot,...nt,...He?{appearance:He}:{},...Ge?{buttonsLayout:Ge}:{},...typeof d=="string"?{themeId:d}:{},...Xe,onFailed:we(n),onUnavailable:Qe(n)})})})},n),Xt=Te.filter(({method:n})=>(0,k.stripeMethodCategory)(n)==="wallet"),qt=Te.filter(({method:n})=>(0,k.stripeMethodCategory)(n)!=="wallet"),it=Te.length>0||Se!==null;return(0,h.jsxs)(h.Fragment,{children:[et,it?(0,h.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Xt.map(st),Se?(0,h.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,h.jsx)(_e,{onFailed:we("paypal"),children:(0,h.jsx)(a.Suspense,{fallback:null,children:(0,h.jsx)(r,{clientId:Se.clientId,...Se.environment?{environment:Se.environment}:{},...ge.currency?{currency:ge.currency}:{},sessionId:t,nonce:o,billingApiUrl:ot,customer:Kt,...nt,...Xe,onFailed:we("paypal"),onUnavailable:Qe("paypal")})})})}):null,qt.map(st)]}):null,at&&it?(0,h.jsx)(ft,{label:"or add a card"}):null,at&&_&&A?.html?(0,h.jsx)("div",{"data-flopay-payment-method":"card",children:(0,h.jsx)(yt,{capture:_,html:A.html,messageToken:A.messageToken,expectedOrigin:A.expectedOrigin,verificationRequired:A.verificationRequired,theme:Ht,containerStyle:Gt,onReady:()=>{(0,j.invokeMerchantCallback)(()=>V.current.onReady?.())},onValidation:n=>{(0,j.invokeMerchantCallback)(()=>V.current.onValidation?.(n))},onError:n=>{n&&ee("card",le(new Error(n),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var zt=require("react/jsx-runtime"),wr={StripeSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(It(),Bt)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(Yt(),Vt)).then(e=>({default:e.PayPalSetupMethod})))};function Wt(e){return(0,zt.jsx)(St,{...e,branches:wr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
27
|
+
`})]})})}var z=require("react");var ke=require("react"),mt=typeof window>"u"?ke.useEffect:ke.useLayoutEffect;var se=require("react/jsx-runtime"),Be=new WeakSet;function yt({capture:e,html:r,messageToken:t,expectedOrigin:o,verificationRequired:s,theme:i,submitLabel:d,containerStyle:p,onReady:f,onError:F,onValidation:B}){let W=(0,z.useRef)(null),b=(0,z.useRef)(f),T=(0,z.useRef)(F),E=(0,z.useRef)(B);b.current=f,T.current=F,E.current=B;let R=(0,z.useRef)(i);R.current=i;let y=(0,z.useRef)(null),g=d??void 0,w=(0,z.useRef)(g);w.current=g;let I=(0,z.useRef)(void 0);return(0,z.useEffect)(()=>{let U=W.current;if(!U)return;let H=!0,_=!1,v=()=>{!H||_||(_=!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)}),oe=w.current??(Be.has(e)?null:void 0),Q={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...s?{verificationRequired:!0}:{},...R.current?{theme:R.current}:{},...oe===void 0?{}:{submitLabel:oe}};return y.current=R.current??null,I.current=w.current,w.current!==void 0&&Be.add(e),e.mount(U,Q).then(()=>{v()}).catch(m=>{H&&T.current?.(m instanceof Error?m.message:"Failed to load the secure card form.")}),()=>{H=!1,A(),G(),q(),e.unmount()}},[e,r,t,o,s]),mt(()=>{let U=W.current;U&&dt(U,p)},[p]),(0,z.useEffect)(()=>{i!==void 0&&(i===null&&y.current===null||(y.current=i,e.applyTheme?.(i)))},[e,i]),(0,z.useEffect)(()=>{g!==I.current&&(I.current=g,g!==void 0&&Be.add(e),e.setSubmitLabel?.(g??null))},[e,g]),(0,se.jsx)("div",{ref:W,"data-testid":"flopay-vault-card-fields"})}function ft({label:e}){return(0,se.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,se.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,se.jsx)("span",{children:e}),(0,se.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var Ie=require("react/jsx-runtime"),ve=class extends ie.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function le(e,r={}){let t=e instanceof ie.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 ve(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:s,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}var Ye=require("react");var Ce=require("@flopay/js/card-setup"),C=require("@flopay/shared"),a=er(require("react"),1);var he=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 Ue(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 _e=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 St({branches:{StripeSetupMethod:e,PayPalSetupMethod:r},sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,theme:d="modern-light",containerStyle:p,appearance:f,buttonsStyles:F,loading:B=null,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:R,onError:y}){let[g]=(0,a.useState)(he.readSetupRedirectReturn),[w,I]=(0,a.useState)(null),[U,H]=(0,a.useState)(!1),[_,v]=(0,a.useState)(null),[A,G]=(0,a.useState)(null),[q,oe]=(0,a.useState)(null),[Q,m]=(0,a.useState)(null),[de,ne]=(0,a.useState)(()=>new Set),Z=(0,a.useRef)(de),pe=(0,a.useRef)(null);pe.current=w;let K=(0,a.useRef)(!1),x=(0,a.useRef)(!1),O=(0,a.useRef)(!1),D=(0,a.useRef)(!1),Fe=(0,a.useRef)(0),be=(0,a.useRef)(0),ce=(0,a.useRef)(!1),{vaultTheme:Ht,surface:We,overlayTheme:ze,appearance:He,buttonsLayout:Ge}=(0,a.useMemo)(()=>pt({theme:d,appearance:f,buttonsStyles:F}),[d,f,F]),Gt=(0,a.useMemo)(()=>(0,Oe.mergeCardSetupSurface)(We,p),[We,p]),V=(0,a.useRef)({sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:R,onError:y});V.current={sessionId:t,nonce:o,billingApiUrl:s,telemetry:i,onReady:W,onComplete:b,onDecline:T,onCancel:E,onValidation:R,onError:y},(0,a.useEffect)(()=>{ce.current=!0;let n=Fe.current+1;return Fe.current=n,()=>{ce.current=!1,be.current+=1,queueMicrotask(()=>{Fe.current===n&&(O.current||D.current||(D.current=!0,(0,j.invokeMerchantCallback)(()=>{V.current.onCancel?.({status:"cancelled",sessionId:t})})))})}},[t]);let me=(0,a.useCallback)((n,l)=>{O.current=!0,K.current=!1,m({status:"success",wording:n,message:null}),(async()=>(await Ue(600),!x.current&&(x.current=!0,(0,j.invokeMerchantCallback)(()=>{V.current.onComplete?.({status:"succeeded",sessionId:V.current.sessionId,...l?{paymentMethod:l}:{}})}),ce.current&&m(null))))()},[]),ye=(0,a.useCallback)((n,l)=>{O.current=!0,K.current=!1,m({status:"error",wording:n,message:l.message??null}),(0,j.invokeMerchantCallback)(()=>{V.current.onDecline?.({status:"declined",sessionId:V.current.sessionId,...l.reason?{reason:l.reason}:{},...l.message?{message:l.message}:{}})}),(async()=>(await Ue(400),ce.current&&m(null)))()},[]),ee=(0,a.useCallback)((n,l)=>{K.current?(K.current=!1,m({status:"error",wording:n,message:l.message}),setTimeout(()=>{ce.current&&m(null)},400)):m(null),(0,j.invokeMerchantCallback)(()=>V.current.onError?.(l))},[]),Ee=(0,a.useCallback)(async n=>{let l=be.current+1;be.current=l;let c=()=>!ce.current||l!==be.current;K.current=!0,m({status:"processing",wording:"payment_method",message:null});let N=new Ce.PaymentAPI((0,C.resolveBillingApiUrl)(V.current.billingApiUrl),{telemetry:V.current.telemetry});try{for(let u=0;u<lr;u+=1){if((u>0||n.waitFirst)&&await Ue(ur),c())return;let X=await N.getUnifiedCheckoutSession(V.current.sessionId,V.current.nonce);if(c())return;let ae=X.data.session?.status;if(ae==="complete"){H(!0),me("payment_method");return}if(ae==="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";ee("payment_method",le(u,X?{retryable:!0}:{}))}finally{N.destroy()}},[ee,me]);(0,a.useEffect)(()=>{let n=!0,l=(0,C.resolveBillingApiUrl)(s),c=new Ce.PaymentAPI(l,{telemetry:i});I(null),H(!1),v(null),G(null),oe(null);let N=new Set;return Z.current=N,ne(N),O.current=!1,D.current=!1,x.current=!1,(async()=>{try{let{session:u,advertisement:X}=await pr(c,t,o);if(!n)return;let ae={advertisement:X,customer:dr(u),...u.futureUse?{futureUse:u.futureUse}:{},...u.futureUseUnsupported?{futureUseUnsupported:u.futureUseUnsupported}:{}};if(g){if((0,he.clearSetupRedirectParams)(),u.status==="complete"){H(!0),I(ae),me("payment_method");return}g.failed?ye("payment_method",{reason:"redirect_failed"}):Ee({waitFirst:!0})}let lt=X.card?await cr(c,u,t,o,l):null;if(!n)return;I(ae),lt&&(G(lt),v(new Ce.PciVaultCardCapture({sessionId:t,operation:"card_setup",telemetry:i})))}catch(u){if(!n)return;let X=le(u);O.current=!0,oe(X),(0,j.invokeMerchantCallback)(()=>V.current.onError?.(X))}})(),()=>{n=!1,c.destroy()}},[s,o,g,ye,me,t,i,Ee]),(0,a.useEffect)(()=>{if(!_)return;K.current=!1;let n=_.on("submitting",()=>{K.current=!0,m({status:"processing",wording:"card",message:null})}),l=_.on("complete",u=>{me("card",u.paymentMethod)}),c=_.on("decline",u=>{ye("card",{...u.declineReason?{reason:u.declineReason}:{},...u.message?{message:u.message}:{}})}),N=_.on("challenge_dismissed",()=>{m(null)});return()=>{n(),l(),c(),N()}},[_,ye,me]);let Ke=(0,a.useCallback)((n,l,c)=>{if(c.retryable){ee("payment_method",le(l,c));return}if(Z.current.has(n))return;let N=new Set(Z.current);N.add(n),Z.current=N,ne(N);let u=pe.current?.advertisement,X=u?(0,k.advertisedMethodKeys)(u).some(ae=>!N.has(ae)):!1;ee("payment_method",le(l,{code:c.code,retryable:X}))},[ee]),Xe=(0,a.useMemo)(()=>({onSubmitting:()=>{K.current=!0,m({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{Ee({waitFirst:!1})},onDeclined:n=>ye("payment_method",n),onValidation:n=>{(0,j.invokeMerchantCallback)(()=>V.current.onValidation?.(n))},onAbandoned:()=>{K.current=!1,m(null)}}),[ye,Ee]),qe=(0,a.useRef)(Ke);qe.current=Ke;let je=(0,a.useRef)(new Map),Re=n=>{let l=je.current.get(n);if(l)return l;let c=(N,u)=>qe.current(n,N,u);return je.current.set(n,c),c},$e=(0,a.useCallback)(n=>{if(Z.current.has(n))return;let l=new Set(Z.current);l.add(n),Z.current=l,ne(l);let c=pe.current?.advertisement;c&&(0,k.advertisedMethodKeys)(c).some(u=>!l.has(u))||ee("payment_method",le(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[ee]),Ze=(0,a.useRef)($e);Ze.current=$e;let Je=(0,a.useRef)(new Map),Qe=n=>{let l=Je.current.get(n);if(l)return l;let c=()=>Ze.current(n);return Je.current.set(n,c),c},et=Q?(0,h.jsx)(ct,{status:Q.status,errorMessage:Q.message,...(0,k.setupOverlayLabels)(Q.wording),successNote:null,...ze?{theme:ze}:{}}):null;if(q)return(0,h.jsx)("div",{role:"alert",children:q.message});if(!w||U)return(0,h.jsxs)(h.Fragment,{children:[et,w?null:B]});let{advertisement:ge,customer:Kt,futureUse:tt,futureUseUnsupported:rt}=w,ot=(0,C.resolveBillingApiUrl)(s),nt=i===void 0?{}:{telemetry:i},Te=ge.stripe.filter(({method:n})=>!de.has(n)),Se=de.has("paypal")?null:ge.paypal,at=!!(ge.card&&_&&A?.html),st=({method:n,publishableKey:l,currency:c})=>(0,h.jsx)("div",{"data-flopay-payment-method":n,style:{display:"contents"},children:(0,h.jsx)(_e,{onFailed:Re(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,...tt?{futureUse:tt}:{},...rt?{futureUseUnsupported:rt}:{},sessionId:t,nonce:o,billingApiUrl:ot,...nt,...He?{appearance:He}:{},...Ge?{buttonsLayout:Ge}:{},...typeof d=="string"?{themeId:d}:{},...Xe,onFailed:Re(n),onUnavailable:Qe(n)})})})},n),Xt=Te.filter(({method:n})=>(0,k.stripeMethodCategory)(n)==="wallet"),qt=Te.filter(({method:n})=>(0,k.stripeMethodCategory)(n)!=="wallet"),it=Te.length>0||Se!==null;return(0,h.jsxs)(h.Fragment,{children:[et,it?(0,h.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Xt.map(st),Se?(0,h.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,h.jsx)(_e,{onFailed:Re("paypal"),children:(0,h.jsx)(a.Suspense,{fallback:null,children:(0,h.jsx)(r,{clientId:Se.clientId,...Se.environment?{environment:Se.environment}:{},...ge.currency?{currency:ge.currency}:{},sessionId:t,nonce:o,billingApiUrl:ot,customer:Kt,...nt,...Xe,onFailed:Re("paypal"),onUnavailable:Qe("paypal")})})})}):null,qt.map(st)]}):null,at&&it?(0,h.jsx)(ft,{label:"or add a card"}):null,at&&_&&A?.html?(0,h.jsx)("div",{"data-flopay-payment-method":"card",children:(0,h.jsx)(yt,{capture:_,html:A.html,messageToken:A.messageToken,expectedOrigin:A.expectedOrigin,verificationRequired:A.verificationRequired,theme:Ht,containerStyle:Gt,onReady:()=>{(0,j.invokeMerchantCallback)(()=>V.current.onReady?.())},onValidation:n=>{(0,j.invokeMerchantCallback)(()=>V.current.onValidation?.(n))},onError:n=>{n&&ee("card",le(new Error(n),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var zt=require("react/jsx-runtime"),Rr={StripeSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(It(),Bt)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,Ye.lazy)(()=>Promise.resolve().then(()=>(Yt(),Vt)).then(e=>({default:e.PayPalSetupMethod})))};function Wt(e){return(0,zt.jsx)(St,{...e,branches:Rr})}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-ULXLO3FW.mjs").then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:o(()=>import("./payment-method-setup-paypal-AGIJIZDK.mjs").then(e=>({default:e.PayPalSetupMethod})))};function y(e){return P(t,{...e,branches:p})}export{a as FloPayCardSetupError,y as FloPayPaymentMethodSetup};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{k as a}from"./chunk-MSABDKVT.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.
|
|
3
|
+
"version": "1.14.1",
|
|
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.
|
|
40
|
-
"@flopay/shared": "1.
|
|
39
|
+
"@flopay/js": "1.14.1",
|
|
40
|
+
"@flopay/shared": "1.14.1",
|
|
41
41
|
"@paypal/paypal-js": "^10.1.0",
|
|
42
42
|
"@stripe/react-stripe-js": "^6.12.0",
|
|
43
43
|
"@stripe/stripe-js": "^9.17.0"
|
package/dist/chunk-H4MQCBX4.mjs
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import{a as U,b as N,h as D,j as H,l as X}from"./chunk-VK67324N.mjs";import{PaymentAPI as he}from"@flopay/js/card-setup";import{FloPayError as ge,getStripeMethodDisplayName as Se,resolveSetupFutureUsage as be,toStripeAppearance as ve}from"@flopay/shared";import{Elements as Ee,ExpressCheckoutElement as ke,PaymentElement as xe,useElements as we,useStripe as Pe}from"@stripe/react-stripe-js";import{loadStripe as Re}from"@stripe/stripe-js";import{useCallback as Q,useMemo as _e,useRef as Ce,useState as S}from"react";import{getStripeMethodDisplayName as z,hasVendoredStripeMethodLogo as le,resolveStripeMethodBrandVariant as de,stripeExpressMethodToOptionKey as ce}from"@flopay/shared";import{useState as ue}from"react";var Y={alipay:"https://cdn.flopay.com/sdk-logos/v1/alipay.svg",bancontact:"https://cdn.flopay.com/sdk-logos/v1/bancontact.svg",blik:"https://cdn.flopay.com/sdk-logos/v1/blik.svg",eps:"https://cdn.flopay.com/sdk-logos/v1/eps.svg",giropay:"https://cdn.flopay.com/sdk-logos/v1/giropay.svg",ideal:"https://cdn.flopay.com/sdk-logos/v1/ideal.svg",klarna:"https://cdn.flopay.com/sdk-logos/v1/klarna.svg",p24:"https://cdn.flopay.com/sdk-logos/v1/p24.svg",sepa_debit:"https://cdn.flopay.com/sdk-logos/v1/sepa_debit.svg",wechat_pay:"https://cdn.flopay.com/sdk-logos/v1/wechat_pay.svg"};import{Fragment as fe,jsx as s,jsxs as L}from"react/jsx-runtime";var ye=`
|
|
2
|
-
.paypal-buttons { margin: 0 !important; vertical-align: top !important; }
|
|
3
|
-
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
4
|
-
@keyframes flopay-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
|
|
5
|
-
@keyframes flopay-fade-in { 0% { opacity: 0; } 100% { opacity: 1; } }
|
|
6
|
-
@keyframes flopay-buttons-enter {
|
|
7
|
-
0% { opacity: 0; transform: translateX(-16px) scale(0.97); }
|
|
8
|
-
100% { opacity: 1; transform: translateX(0) scale(1); }
|
|
9
|
-
}
|
|
10
|
-
@keyframes flopay-buttons-exit {
|
|
11
|
-
0% { opacity: 1; transform: translateX(0) scale(1); }
|
|
12
|
-
100% { opacity: 0; transform: translateX(-16px) scale(0.97); }
|
|
13
|
-
}
|
|
14
|
-
@keyframes flopay-card-enter {
|
|
15
|
-
0% { opacity: 0; transform: translateX(16px) scale(0.97); }
|
|
16
|
-
100% { opacity: 1; transform: translateX(0) scale(1); }
|
|
17
|
-
}
|
|
18
|
-
@keyframes flopay-card-exit {
|
|
19
|
-
0% { opacity: 1; transform: translateX(0) scale(1); }
|
|
20
|
-
100% { opacity: 0; transform: translateX(16px) scale(0.97); }
|
|
21
|
-
}
|
|
22
|
-
`,me=44;function K(){return s("style",{children:ye})}function W(e,r){let t=e.availablePaymentMethods;return t&&r.some(o=>t[o])?"ready":"unavailable"}function $({state:e,placeholderTestId:r,borderRadius:t=8,children:o}){return e==="unavailable"||e==="load_error"?null:L("div",{style:{position:"relative",minHeight:44},children:[s("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"}}),s("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 De(e){return e!=="unavailable"&&e!=="load_error"}function j({method:e,themeId:r,submitting:t=!1,disabled:o=!1,highlighted:l=!1,hasNextStep:d=!1,onClick:i,backgroundColor:f,borderColor:c,textColor:h,borderRadius:g,fontFamily:w}){let u=de(e,r),b=Y[e],[E,v]=ue(!1),y=!!b&&!E,k=u?.backgroundColor??f??"#ffffff",P=u?.borderColor??c??"#d1d5db",R=u?.textColor??h??"#262833";return s("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:me,padding:"0 1rem",backgroundColor:k,color:R,border:`1px solid ${P}`,borderRadius:g??8,fontSize:"0.95rem",fontWeight:600,fontFamily:w,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:l?"0 0 0 2px rgba(74, 73, 255, 0.15)":void 0},children:t?s("span",{style:{margin:"0 auto"},children:`Connecting to ${z(e)}\u2026`}):L(fe,{children:[L("span",{style:{display:"inline-flex",alignItems:"center",gap:le(e)?8:0},children:[y?s("img",{src:b,alt:"","aria-hidden":"true",onError:()=>v(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!y&&u?.logoSvg?s("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:u.logoSvg}}):null,s("span",{children:z(e)})]}),d&&s("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:R,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:s("path",{d:"M9 18l6-6-6-6"})})]})})}function G(e){let r=new Set(e.map(ce)),t=o=>o==="applePay"||o==="googlePay"?"always":"auto";return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(o=>[o,r.has(o)?t(o):"never"]))}var V={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},q={type:"accordion",defaultCollapsed:!1,radios:"never"};function J({testId:e,attributes:r,disabled:t,onClick:o,color:l,borderRadius:d,style:i,children:f}){return s("button",{type:"button","data-testid":e,...r,onClick:o,disabled:t,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:l,color:"white",border:"none",borderRadius:d,fontSize:"1rem",fontWeight:600,cursor:t?"not-allowed":"pointer",opacity:t?.5:1,transition:"opacity 120ms ease-out",...i??{}},children:f})}import{Fragment as ee,jsx as m,jsxs as I}from"react/jsx-runtime";var te={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"}},B=new Map;function Me(e){let r=B.get(e);if(r)return r;let t=Re(e).catch(o=>{throw B.delete(e),o});return B.set(e,t),t}function Te(e){return e?ve(e):void 0}function Le(e){return D(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Z(e){return e==="paypal"?"PayPal":Se(e)}function Be(){return typeof window>"u"?"":window.location.href}var Ie={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"};function qe(e){let{publishableKey:r,method:t,currency:o,futureUse:l,futureUseUnsupported:d,appearance:i}=e,[f]=S(()=>Me(r)),c=_e(()=>{let h=Te(i),g=be({futureUse:l,futureUseUnsupported:d},t,"setup");return{mode:"setup",currency:o.toLowerCase(),paymentMethodTypes:te[t]?.types??[t],...g?{setupFutureUsage:g}:{},...h?{appearance:h}:{}}},[i,o,l,d,t]);return m(Ee,{stripe:f,options:c,children:m(Ae,{...e})})}function Ae({method:e,category:r,sessionId:t,nonce:o,billingApiUrl:l,telemetry:d,appearance:i,themeId:f,buttonsLayout:c,onSubmitting:h,onConfirmed:g,onDeclined:w,onFailed:u,onValidation:b,onUnavailable:E}){let v=Pe(),y=we(),[k,P]=S(!1),[R,A]=S("loading"),[oe,re]=S(!1),[_,ae]=S(!1),C=Ce(!1),[x]=S(()=>H()),[ne,se]=S(!1),M=Q((a,p)=>{if(N(a,{inAppBrowser:x.inAppBrowser,handoffObserved:!1}).popupBlocked){se(!0),u(new Error(U(Z(e),!0,x.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}u(p.message===void 0?a:new Error(p.message),{code:p.code,retryable:!0})},[x.inAppBrowser,e,u]),F=Q(async()=>{if(!(!v||!y||C.current)){C.current=!0,P(!0);try{let a=await y.submit();if(a.error){b(a.error.message??null);return}h();let p=await new he(l,{telemetry:d}).createSessionIntent(t,o,{provider:"stripe",paymentMethodCategory:r,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(p.provider!=="stripe"||p.intentKind!=="setup")throw new ge("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let n=await v.confirmSetup({elements:y,clientSecret:p.clientSecret,confirmParams:{return_url:Be()},redirect:"if_required"});if(n.error){Le(n.error)?w({...n.error.decline_code||n.error.code?{reason:n.error.decline_code??n.error.code}:{},...n.error.message?{message:n.error.message}:{}}):M(n.error,{code:"payment_method_setup_provider_failed",message:n.error.message??"The payment method could not be saved."});return}g()}catch(a){M(a,{code:"payment_method_setup_failed"})}finally{C.current=!1,P(!1)}}},[l,r,y,e,o,g,w,h,b,M,t,v,d]),T=te[e]?.wallet,ie=T==="paypal"&&X(x,"auto",ne?"blocked":x.popupCapability)==="redirect",O=i?.variables?.borderRadius??c?.cardButton?.borderRadius??8;if(r==="wallet"&&T&&!ie)return I(ee,{children:[m(K,{}),m($,{state:R,borderRadius:O,children:m(ke,{options:{...V,paymentMethods:G([e])},onReady:a=>{let p=W(a,[T]);A(p),p==="unavailable"&&E()},onLoadError:()=>{A("load_error"),E()},onConfirm:()=>{F()}})})]});let pe=Z(e);return I(ee,{children:[oe?m(j,{method:e,themeId:f,hasNextStep:!0,highlighted:_,disabled:k,onClick:()=>ae(a=>!a),backgroundColor:c?.cardButton?.backgroundColor,borderColor:c?.cardInputBorder,textColor:c?.cardButton?.color,borderRadius:O}):null,I("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!_,style:_?{display:"flex",flexDirection:"column"}:Ie,children:[m(xe,{options:{layout:q},onReady:()=>re(!0),onLoadError:()=>E(),onChange:a=>{a.complete&&b(null)}}),m(J,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!v||!y||k||!_,onClick:()=>{F()},color:i?.variables?.colorPrimary??"#4A49FF",borderRadius:i?.variables?.borderRadius??"8px",style:c?.submitButton,children:k?"Saving\u2026":`Save ${pe}`})]})]})}export{me as a,K as b,W as c,$ as d,De as e,j as f,G as g,V as h,q as i,J as j,qe as k};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{k as a}from"./chunk-H4MQCBX4.mjs";import"./chunk-VK67324N.mjs";export{a as StripeSetupMethod};
|