@flopay/react 1.11.3 → 1.11.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/card-setup-entry.cjs +2 -2
- package/dist/card-setup-entry.mjs +1 -1
- package/dist/chunk-52RFSQJ7.mjs +1 -0
- package/dist/chunk-AW5LOT2K.mjs +6 -0
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- package/dist/index.mjs +6 -6
- package/dist/payment-method-setup-entry.cjs +3 -3
- package/dist/payment-method-setup-entry.mjs +1 -1
- package/package.json +11 -11
- package/dist/chunk-AZRGKPW7.mjs +0 -6
- package/dist/chunk-LIYRDFMO.mjs +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var yr=Object.create;var Re=Object.defineProperty;var gr=Object.getOwnPropertyDescriptor;var hr=Object.getOwnPropertyNames;var Sr=Object.getPrototypeOf,br=Object.prototype.hasOwnProperty;var me=(e,t)=>()=>(e&&(t=e(e=0)),t);var De=(e,t)=>{for(var r in t)Re(e,r,{get:t[r],enumerable:!0})},dt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hr(t))!br.call(e,o)&&o!==r&&Re(e,o,{get:()=>t[o],enumerable:!(n=gr(t,o))||n.enumerable});return e};var vr=(e,t,r)=>(r=e!=null?yr(Sr(e)):{},dt(t||!e||!e.__esModule?Re(r,"default",{value:e,enumerable:!0}):r,e)),Cr=e=>dt(Re({},"__esModule",{value:!0}),e);function Le(e,t,r){let n=`We couldn't open ${e}. Try again or choose another payment method.`;return t?r?`${n} Open this page in your system browser, then try again.`:`${n} Allow pop-ups for this site, then try again.`:n}function It(e){if(e instanceof Error)return e.message;if(typeof e=="object"&&e!==null){let t=e.message;return typeof t=="string"?t:void 0}return typeof e=="string"?e:void 0}function we(e){if(typeof e!="string")return;let t=e.trim();return/^[a-z0-9_.-]{1,64}$/i.test(t)?t:void 0}function Dt(e){if(typeof e!="object"||e===null)return;let t=e;return we(t.code)??we(t.type)??we(t.name)}function rn(e){if(!(typeof e!="object"||e===null))return we(e.decline_code)}function He(e){return typeof e!="object"||e===null?!1:we(e.type)?.toLowerCase()==="card_error"||rn(e)!==void 0}function nn(e){let t=It(e)?.toLowerCase()??"",r=Dt(e)?.toLowerCase()??"";return en.has(r)?!0:/(?:popup|pop-up).{0,40}(?:block|denied|prevent)/i.test(t)||/(?:block|denied|prevent).{0,40}(?:popup|pop-up)/i.test(t)}function on(e){if(Dt(e)?.toLowerCase()==="paypal_init_timeout")return!0;let r=It(e)??"";return r.includes("No ack for postMessage init()")&&tn.some(n=>r.includes(n))&&r.includes("10000ms")}function Be(e,t){if(He(e))return{errorCode:"PROVIDER_RUNTIME_FAILED",popupBlocked:!1,providerDeclined:!0,terminalReason:"provider_declined"};let n=nn(e)||t.inAppBrowser&&!t.handoffObserved&&on(e);return{errorCode:n?"POPUP_BLOCKED":"PROVIDER_RUNTIME_FAILED",popupBlocked:n,providerDeclined:!1,terminalReason:n?"popup_blocked":"provider_error"}}var en,tn,We=me(()=>{"use strict";en=new Set(["err_blocked_by_client","notallowederror","popup_blocked","popupblocked"]),tn=["https://www.paypal.com","https://www.sandbox.paypal.com"]});function Oe(e){let t=e??(typeof navigator>"u"?"":navigator.userAgent),r=n=>({inAppBrowser:n!=="none",appFamily:n,popupCapability:"unknown"});return t?/FBAN|FBAV|FB_IAB|FBIOS/i.test(t)?r("facebook"):/Instagram/i.test(t)?r("instagram"):/musical_ly|BytedanceWebview|TikTok/i.test(t)?r("tiktok"):/Twitter|Snapchat|Pinterest|LinkedInApp|Line\/|MicroMessenger|GSA\//i.test(t)?r("other_in_app"):/Android.*;\s?wv\)/.test(t)||/(iPhone|iPad|iPod).*AppleWebKit(?!.*Safari)/.test(t)?r("generic_webview"):r("none"):r("none")}function Vt(e,t,r=e.popupCapability){return e.inAppBrowser||r==="blocked"||t==="prefer_redirect"?"redirect":"popup"}var Ye=me(()=>{"use strict"});var Ut,Nt=me(()=>{"use strict";Ut={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 Wt(){return(0,_.jsx)("style",{children:an})}function Yt(e,t){let r=e.availablePaymentMethods;return r&&t.some(n=>r[n])?"ready":"unavailable"}function zt({state:e,placeholderTestId:t,borderRadius:r=8,children:n}){return e==="unavailable"||e==="load_error"?null:(0,_.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,_.jsx)("div",{"data-testid":t,"aria-hidden":e==="ready",style:{position:"absolute",inset:0,height:44,borderRadius:r,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,_.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:n})]})}function $t({method:e,themeId:t,submitting:r=!1,disabled:n=!1,highlighted:o=!1,hasNextStep:a=!1,onClick:s,backgroundColor:l,borderColor:d,textColor:c,borderRadius:f,fontFamily:h}){let S=(0,J.resolveStripeMethodBrandVariant)(e,t),k=Ut[e],[x,E]=(0,Ht.useState)(!1),y=!!k&&!x,P=S?.backgroundColor??l??"#ffffff",L=S?.borderColor??d??"#d1d5db",B=S?.textColor??c??"#262833";return(0,_.jsx)("button",{type:"button","data-testid":`flopay-stripe-method-button-${e}`,"data-method":e,onClick:()=>{!r&&!n&&s()},disabled:r||n,"aria-busy":r||void 0,style:{position:"relative",width:"100%",boxSizing:"border-box",height:sn,padding:"0 1rem",backgroundColor:P,color:B,border:`1px solid ${L}`,borderRadius:f??8,fontSize:"0.95rem",fontWeight:600,fontFamily:h,cursor:r||n?"not-allowed":"pointer",opacity:n&&!r?.55:1,animation:r?"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:o?"0 0 0 2px rgba(74, 73, 255, 0.15)":void 0},children:r?(0,_.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,J.getStripeMethodDisplayName)(e)}\u2026`}):(0,_.jsxs)(_.Fragment,{children:[(0,_.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,J.hasVendoredStripeMethodLogo)(e)?8:0},children:[y?(0,_.jsx)("img",{src:k,alt:"","aria-hidden":"true",onError:()=>E(!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&&S?.logoSvg?(0,_.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:S.logoSvg}}):null,(0,_.jsx)("span",{children:(0,J.getStripeMethodDisplayName)(e)})]}),a&&(0,_.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,_.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function Gt(e){let t=new Set(e.map(J.stripeExpressMethodToOptionKey)),r=n=>n==="applePay"||n==="googlePay"?"always":"auto";return Object.fromEntries(["applePay","googlePay","paypal","link","amazonPay","klarna"].map(n=>[n,t.has(n)?r(n):"never"]))}function Xt({testId:e,attributes:t,disabled:r,onClick:n,color:o,borderRadius:a,style:s,children:l}){return(0,_.jsx)("button",{type:"button","data-testid":e,...t,onClick:n,disabled:r,style:{width:"100%",marginTop:"0.75rem",padding:"0.875rem",backgroundColor:o,color:"white",border:"none",borderRadius:a,fontSize:"1rem",fontWeight:600,cursor:r?"not-allowed":"pointer",opacity:r?.5:1,transition:"opacity 120ms ease-out",...s??{}},children:l})}var J,Ht,_,an,sn,jt,Kt,qt=me(()=>{"use strict";J=require("@flopay/shared"),Ht=require("react");Nt();_=require("react/jsx-runtime"),an=`
|
|
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
|
-
`,an=44;Gt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},jt={type:"accordion",defaultCollapsed:!1,radios:"never"}});var er={};De(er,{StripeSetupMethod:()=>fn});function sn(e){let t=ze.get(e);if(t)return t;let r=(0,Jt.loadStripe)(e).catch(n=>{throw ze.delete(e),n});return ze.set(e,r),r}function un(e){return e?{theme:ln[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function dn(e){return He(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function qt(e){return e==="paypal"?"PayPal":(0,ge.getStripeMethodDisplayName)(e)}function cn(){return typeof window>"u"?"":window.location.href}function fn(e){let{publishableKey:t,method:r,currency:n,futureUse:o,futureUseUnsupported:a,appearance:s}=e,[l]=(0,I.useState)(()=>sn(t)),d=(0,I.useMemo)(()=>{let p=un(s),f=(0,ge.resolveSetupFutureUsage)({futureUse:o,futureUseUnsupported:a},r,"setup");return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:Qt[r]?.types??[r],...f?{setupFutureUsage:f}:{},...p?{appearance:p}:{}}},[s,n,o,a,r]);return(0,B.jsx)(X.Elements,{stripe:l,options:d,children:(0,B.jsx)(mn,{...e})})}function mn({method:e,category:t,sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,appearance:s,themeId:l,buttonsLayout:d,onSubmitting:p,onConfirmed:f,onDeclined:S,onFailed:g,onValidation:k,onUnavailable:P}){let E=(0,X.useStripe)(),m=(0,X.useElements)(),[_,D]=(0,I.useState)(!1),[M,v]=(0,I.useState)("loading"),[j,N]=(0,I.useState)(!1),[R,W]=(0,I.useState)(!1),$=(0,I.useRef)(!1),[U]=(0,I.useState)(()=>Oe()),[A,Y]=(0,I.useState)(!1),te=(0,I.useCallback)((F,V)=>{if(Be(F,{inAppBrowser:U.inAppBrowser,handoffObserved:!1}).popupBlocked){Y(!0),g(new Error(Le(qt(e),!0,U.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}g(V.message===void 0?F:new Error(V.message),{code:V.code,retryable:!0})},[U.inAppBrowser,e,g]),K=(0,I.useCallback)(async()=>{if(!(!E||!m||$.current)){$.current=!0,D(!0);try{let F=await m.submit();if(F.error){k(F.error.message??null);return}p();let V=await new Zt.PaymentAPI(o,{telemetry:a}).createSessionIntent(r,n,{provider:"stripe",paymentMethodCategory:t,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(V.provider!=="stripe"||V.intentKind!=="setup")throw new ge.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let L=await E.confirmSetup({elements:m,clientSecret:V.clientSecret,confirmParams:{return_url:cn()},redirect:"if_required"});if(L.error){dn(L.error)?S({...L.error.decline_code||L.error.code?{reason:L.error.decline_code??L.error.code}:{},...L.error.message?{message:L.error.message}:{}}):te(L.error,{code:"payment_method_setup_provider_failed",message:L.error.message??"The payment method could not be saved."});return}f()}catch(F){te(F,{code:"payment_method_setup_failed"})}finally{$.current=!1,D(!1)}}},[o,t,m,e,n,f,S,p,k,te,r,E,a]),re=Qt[e]?.wallet,G=re==="paypal"&&Dt(U,"auto",A?"blocked":U.popupCapability)==="redirect",ue=s?.variables?.borderRadius??d?.cardButton?.borderRadius??8;if(t==="wallet"&&re&&!G)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Ht,{}),(0,B.jsx)(Yt,{state:M,borderRadius:ue,children:(0,B.jsx)(X.ExpressCheckoutElement,{options:{...Gt,paymentMethods:$t([e])},onReady:F=>{let V=Wt(F,[re]);v(V),V==="unavailable"&&P()},onLoadError:()=>{v("load_error"),P()},onConfirm:()=>{K()}})})]});let ne=qt(e);return(0,B.jsxs)(B.Fragment,{children:[j?(0,B.jsx)(zt,{method:e,themeId:l,hasNextStep:!0,highlighted:R,disabled:_,onClick:()=>W(F=>!F),backgroundColor:d?.cardButton?.backgroundColor,borderColor:d?.cardInputBorder,textColor:d?.cardButton?.color,borderRadius:ue}):null,(0,B.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!R,style:R?{display:"flex",flexDirection:"column"}:pn,children:[(0,B.jsx)(X.PaymentElement,{options:{layout:jt},onReady:()=>N(!0),onLoadError:()=>P(),onChange:F=>{F.complete&&k(null)}}),(0,B.jsx)(Kt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!E||!m||_||!R,onClick:()=>{K()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:_?"Saving\u2026":`Save ${ne}`})]})]})}var Zt,ge,X,Jt,I,B,Qt,ze,ln,pn,tr=fe(()=>{"use strict";Zt=require("@flopay/js/card-setup"),ge=require("@flopay/shared"),X=require("@stripe/react-stripe-js"),Jt=require("@stripe/stripe-js"),I=require("react");We();Ye();Xt();B=require("react/jsx-runtime"),Qt={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"}},ze=new Map;ln={night:"night",flat:"flat"};pn={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var or={};De(or,{PayPalSetupMethod:()=>yn});function yn({clientId:e,environment:t,currency:r,sessionId:n,nonce:o,billingApiUrl:a,telemetry:s,customer:{userId:l,email:d},onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g}){let k=(0,le.useRef)(null),P=(0,le.useRef)({onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g});P.current={onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g};let[E]=(0,le.useState)(()=>Oe().inAppBrowser);return(0,le.useEffect)(()=>{let m=!0,_,D=new rr.PaymentAPI(a,{telemetry:s}),M={userId:l,email:d};return(async()=>{try{let v=await(0,nr.loadScript)({clientId:e,...r?{currency:r.toUpperCase()}:{},components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),j=k.current;if(!m||!j)return;if(!v?.Buttons)throw new ee.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=v.Buttons({createVaultSetupToken:async()=>{P.current.onSubmitting();let R=await D.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(R.provider!=="paypal"||R.providerObjectType!=="setup_token")throw new ee.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return R.providerObjectId},onApprove:async R=>{let W=R.vaultSetupToken;if(!W)throw new ee.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let $=await D.processPayment(M.userId,{sessionId:n,nonce:o,paymentMethodCategory:"paypal",tokenizedData:{id:W,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:M});if(!$.ok)throw new ee.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:$.status});m&&P.current.onConfirmed()},onCancel:()=>{m&&P.current.onAbandoned()},onError:R=>{if(!m)return;let{popupBlocked:W}=Be(R,{inAppBrowser:E,handoffObserved:!1});P.current.onFailed(W?new Error(Le("PayPal",!0,E)):R,{code:W?"popup_blocked":"paypal_setup_failed",retryable:!0})}});_=()=>N.close(),await N.render(j)}catch(v){if(!m)return;P.current.onFailed(v,{code:"paypal_unavailable",retryable:!0})}})(),()=>{m=!1,_?.().catch(()=>{}),D.destroy()}},[a,e,r,d,t,E,o,n,s,l]),(0,ar.jsx)("div",{ref:k,"data-flopay-paypal-setup":""})}var rr,ee,nr,le,ar,sr=fe(()=>{"use strict";rr=require("@flopay/js/card-setup"),ee=require("@flopay/shared"),nr=require("@paypal/paypal-js"),le=require("react");We();Ye();ar=require("react/jsx-runtime")});var hn={};De(hn,{FloPayCardSetupError:()=>Ce,FloPayPaymentMethodSetup:()=>ir});module.exports=vr(hn);var Rt=require("@flopay/js/card-setup"),me=require("@flopay/shared"),Me=require("react");function dt(e,t){if(!e)return t;let r=t??{},n=Object.keys(r),o=n.some(s=>s.startsWith("background")),a={};for(let[s,l]of Object.entries(e))s in r||o&&s.startsWith("background")||(a[s]=l);for(let s of n)a[s]=r[s];return a}var Cr=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 Pr(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Cr.has(t.charAt(0).toLowerCase()+t.slice(1))}function wr(e,t){return typeof t=="number"&&t!==0&&!Pr(e)?`${t}px`:String(t).trim()}function ct(e,t){if(e.style.cssText="",!!t){for(let[r,n]of Object.entries(t))if(!(n==null||n==="")){if(r.startsWith("--")){e.style.setProperty(r,String(n));continue}e.style[r]=wr(r,n)}}}var pt={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ft(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?pt.dark:pt.light,a=t.colorText??(n?"#F1F5F9":"#262833"),s=e.appearance.rules?.[".Label"];return{panel:{...r.background===void 0?{}:{background:r.background},...r.backgroundColor===void 0?{}:{backgroundColor:r.backgroundColor},...r.border===void 0?{}:{border:r.border},...r.borderRadius===void 0?{}:{borderRadius:r.borderRadius},...r.boxShadow===void 0?{}:{boxShadow:r.boxShadow},color:a,...t.fontFamily?{fontFamily:t.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:t.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:s?.color??a}}function q(e){if(!e)return;let t=r=>{console.error("[FloPay] Merchant callback failed; checkout continued.",r)};try{Promise.resolve(e()).catch(t)}catch(r){t(r)}}var w=require("react/jsx-runtime");var kr={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function mt({status:e,errorMessage:t,authorized:r=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:s="You will be automatically redirected, do not close or navigate away from this window.",theme:l=kr}){let d={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,w.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,w.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...l.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,w.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,w.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,w.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,w.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,w.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,w.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,w.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(r?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&s!==null&&(0,w.jsx)("p",{style:d,children:s}),e==="error"&&t&&(0,w.jsx)("p",{style:d,children:t}),(0,w.jsx)("style",{children:`
|
|
22
|
+
`,sn=44;jt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},Kt={type:"accordion",defaultCollapsed:!1,radios:"never"}});var tr={};De(tr,{StripeSetupMethod:()=>mn});function ln(e){let t=ze.get(e);if(t)return t;let r=(0,Qt.loadStripe)(e).catch(n=>{throw ze.delete(e),n});return ze.set(e,r),r}function dn(e){return e?{theme:un[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function cn(e){return He(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Zt(e){return e==="paypal"?"PayPal":(0,ge.getStripeMethodDisplayName)(e)}function pn(){return typeof window>"u"?"":window.location.href}function mn(e){let{publishableKey:t,method:r,currency:n,futureUse:o,futureUseUnsupported:a,appearance:s}=e,[l]=(0,D.useState)(()=>ln(t)),d=(0,D.useMemo)(()=>{let c=dn(s),f=(0,ge.resolveSetupFutureUsage)({futureUse:o,futureUseUnsupported:a},r,"setup");return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:er[r]?.types??[r],...f?{setupFutureUsage:f}:{},...c?{appearance:c}:{}}},[s,n,o,a,r]);return(0,A.jsx)(q.Elements,{stripe:l,options:d,children:(0,A.jsx)(yn,{...e})})}function yn({method:e,category:t,sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,appearance:s,themeId:l,buttonsLayout:d,onSubmitting:c,onConfirmed:f,onDeclined:h,onFailed:S,onValidation:k,onUnavailable:x}){let E=(0,q.useStripe)(),y=(0,q.useElements)(),[P,L]=(0,D.useState)(!1),[B,b]=(0,D.useState)("loading"),[$,V]=(0,D.useState)(!1),[R,W]=(0,D.useState)(!1),G=(0,D.useRef)(!1),[Y]=(0,D.useState)(()=>Oe()),[M,re]=(0,D.useState)(!1),U=(0,D.useCallback)((F,N)=>{if(Be(F,{inAppBrowser:Y.inAppBrowser,handoffObserved:!1}).popupBlocked){re(!0),S(new Error(Le(Zt(e),!0,Y.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}S(N.message===void 0?F:new Error(N.message),{code:N.code,retryable:!0})},[Y.inAppBrowser,e,S]),X=(0,D.useCallback)(async()=>{if(!(!E||!y||G.current)){G.current=!0,L(!0);try{let F=await y.submit();if(F.error){k(F.error.message??null);return}c();let N=await new Jt.PaymentAPI(o,{telemetry:a}).createSessionIntent(r,n,{provider:"stripe",paymentMethodCategory:t,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(N.provider!=="stripe"||N.intentKind!=="setup")throw new ge.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let T=await E.confirmSetup({elements:y,clientSecret:N.clientSecret,confirmParams:{return_url:pn()},redirect:"if_required"});if(T.error){cn(T.error)?h({...T.error.decline_code||T.error.code?{reason:T.error.decline_code??T.error.code}:{},...T.error.message?{message:T.error.message}:{}}):U(T.error,{code:"payment_method_setup_provider_failed",message:T.error.message??"The payment method could not be saved."});return}f()}catch(F){U(F,{code:"payment_method_setup_failed"})}finally{G.current=!1,L(!1)}}},[o,t,y,e,n,f,h,c,k,U,r,E,a]),ne=er[e]?.wallet,j=ne==="paypal"&&Vt(Y,"auto",M?"blocked":Y.popupCapability)==="redirect",de=s?.variables?.borderRadius??d?.cardButton?.borderRadius??8;if(t==="wallet"&&ne&&!j)return(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(Wt,{}),(0,A.jsx)(zt,{state:B,borderRadius:de,children:(0,A.jsx)(q.ExpressCheckoutElement,{options:{...jt,paymentMethods:Gt([e])},onReady:F=>{let N=Yt(F,[ne]);b(N),N==="unavailable"&&x()},onLoadError:()=>{b("load_error"),x()},onConfirm:()=>{X()}})})]});let oe=Zt(e);return(0,A.jsxs)(A.Fragment,{children:[$?(0,A.jsx)($t,{method:e,themeId:l,hasNextStep:!0,highlighted:R,disabled:P,onClick:()=>W(F=>!F),backgroundColor:d?.cardButton?.backgroundColor,borderColor:d?.cardInputBorder,textColor:d?.cardButton?.color,borderRadius:de}):null,(0,A.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!R,style:R?{display:"flex",flexDirection:"column"}:fn,children:[(0,A.jsx)(q.PaymentElement,{options:{layout:Kt},onReady:()=>V(!0),onLoadError:()=>x(),onChange:F=>{F.complete&&k(null)}}),(0,A.jsx)(Xt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!E||!y||P||!R,onClick:()=>{X()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:P?"Saving\u2026":`Save ${oe}`})]})]})}var Jt,ge,q,Qt,D,A,er,ze,un,fn,rr=me(()=>{"use strict";Jt=require("@flopay/js/card-setup"),ge=require("@flopay/shared"),q=require("@stripe/react-stripe-js"),Qt=require("@stripe/stripe-js"),D=require("react");We();Ye();qt();A=require("react/jsx-runtime"),er={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"}},ze=new Map;un={night:"night",flat:"flat"};fn={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var ar={};De(ar,{PayPalSetupMethod:()=>gn});function gn({clientId:e,environment:t,currency:r,sessionId:n,nonce:o,billingApiUrl:a,telemetry:s,customer:{userId:l,email:d},onSubmitting:c,onConfirmed:f,onFailed:h,onAbandoned:S}){let k=(0,ue.useRef)(null),x=(0,ue.useRef)({onSubmitting:c,onConfirmed:f,onFailed:h,onAbandoned:S});x.current={onSubmitting:c,onConfirmed:f,onFailed:h,onAbandoned:S};let[E]=(0,ue.useState)(()=>Oe().inAppBrowser);return(0,ue.useEffect)(()=>{let y=!0,P,L=new nr.PaymentAPI(a,{telemetry:s}),B={userId:l,email:d};return(async()=>{try{let b=await(0,or.loadScript)({clientId:e,...r?{currency:r.toUpperCase()}:{},components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),$=k.current;if(!y||!$)return;if(!b?.Buttons)throw new te.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let V=b.Buttons({createVaultSetupToken:async()=>{x.current.onSubmitting();let R=await L.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:te.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(R.provider!=="paypal"||R.providerObjectType!=="setup_token")throw new te.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return R.providerObjectId},onApprove:async R=>{let W=R.vaultSetupToken;if(!W)throw new te.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let G=await L.processPayment(B.userId,{sessionId:n,nonce:o,paymentMethodCategory:"paypal",tokenizedData:{id:W,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:te.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:B});if(!G.ok)throw new te.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:G.status});y&&x.current.onConfirmed()},onCancel:()=>{y&&x.current.onAbandoned()},onError:R=>{if(!y)return;let{popupBlocked:W}=Be(R,{inAppBrowser:E,handoffObserved:!1});x.current.onFailed(W?new Error(Le("PayPal",!0,E)):R,{code:W?"popup_blocked":"paypal_setup_failed",retryable:!0})}});P=()=>V.close(),await V.render($)}catch(b){if(!y)return;x.current.onFailed(b,{code:"paypal_unavailable",retryable:!0})}})(),()=>{y=!1,P?.().catch(()=>{}),L.destroy()}},[a,e,r,d,t,E,o,n,s,l]),(0,sr.jsx)("div",{ref:k,"data-flopay-paypal-setup":""})}var nr,te,or,ue,sr,ir=me(()=>{"use strict";nr=require("@flopay/js/card-setup"),te=require("@flopay/shared"),or=require("@paypal/paypal-js"),ue=require("react");We();Ye();sr=require("react/jsx-runtime")});var Sn={};De(Sn,{FloPayCardSetupError:()=>Ce,FloPayPaymentMethodSetup:()=>lr});module.exports=Cr(Sn);var xt=require("@flopay/js/card-setup"),ee=require("@flopay/shared"),Me=require("react");function ct(e,t){if(!e)return t;let r=t??{},n=Object.keys(r),o=n.some(s=>s.startsWith("background")),a={};for(let[s,l]of Object.entries(e))s in r||o&&s.startsWith("background")||(a[s]=l);for(let s of n)a[s]=r[s];return a}var Pr=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 wr(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Pr.has(t.charAt(0).toLowerCase()+t.slice(1))}function kr(e,t){return typeof t=="number"&&t!==0&&!wr(e)?`${t}px`:String(t).trim()}function pt(e,t){if(e.style.cssText="",!!t){for(let[r,n]of Object.entries(t))if(!(n==null||n==="")){if(r.startsWith("--")){e.style.setProperty(r,String(n));continue}e.style[r]=kr(r,n)}}}var ft={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function mt(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?ft.dark:ft.light,a=t.colorText??(n?"#F1F5F9":"#262833"),s=e.appearance.rules?.[".Label"];return{panel:{...r.background===void 0?{}:{background:r.background},...r.backgroundColor===void 0?{}:{backgroundColor:r.backgroundColor},...r.border===void 0?{}:{border:r.border},...r.borderRadius===void 0?{}:{borderRadius:r.borderRadius},...r.boxShadow===void 0?{}:{boxShadow:r.boxShadow},color:a,...t.fontFamily?{fontFamily:t.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:t.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:s?.color??a}}function Z(e){if(!e)return;let t=r=>{console.error("[FloPay] Merchant callback failed; checkout continued.",r)};try{Promise.resolve(e()).catch(t)}catch(r){t(r)}}var w=require("react/jsx-runtime");var Er={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function yt({status:e,errorMessage:t,authorized:r=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:s="You will be automatically redirected, do not close or navigate away from this window.",theme:l=Er}){let d={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,w.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,w.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...l.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,w.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,w.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,w.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,w.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,w.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,w.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,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,w.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,w.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(r?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&s!==null&&(0,w.jsx)("p",{style:d,children:s}),e==="error"&&t&&(0,w.jsx)("p",{style:d,children:t}),(0,w.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 H=require("react");var xe=require("react"),yt=typeof window>"u"?xe.useEffect:xe.useLayoutEffect;var ae=require("react/jsx-runtime"),Ve=new WeakSet;function gt({capture:e,html:t,messageToken:r,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:s,onReady:l,onError:d,onValidation:p}){let f=(0,H.useRef)(null),S=(0,H.useRef)(l),g=(0,H.useRef)(d),k=(0,H.useRef)(p);S.current=l,g.current=d,k.current=p;let P=(0,H.useRef)(o);P.current=o;let E=(0,H.useRef)(null),m=a??void 0,_=(0,H.useRef)(m);_.current=m;let D=(0,H.useRef)(void 0);return(0,H.useEffect)(()=>{let M=f.current;if(!M)return;let v=!0,j=!1,N=()=>{!v||j||(j=!0,S.current?.())},R=e.on("ready",()=>{N()}),W=e.on("error",Y=>{g.current?.(Y.message??"There was a problem loading the secure card form.")}),$=e.on("validation",Y=>{k.current?.(Y.message??null)}),U=_.current??(Ve.has(e)?null:void 0),A={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...P.current?{theme:P.current}:{},...U===void 0?{}:{submitLabel:U}};return E.current=P.current??null,D.current=_.current,_.current!==void 0&&Ve.add(e),e.mount(M,A).then(()=>{N()}).catch(Y=>{v&&g.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{v=!1,R(),W(),$(),e.unmount()}},[e,t,r,n]),yt(()=>{let M=f.current;M&&ct(M,s)},[s]),(0,H.useEffect)(()=>{o!==void 0&&(o===null&&E.current===null||(E.current=o,e.applyTheme?.(o)))},[e,o]),(0,H.useEffect)(()=>{m!==D.current&&(D.current=m,m!==void 0&&Ve.add(e),e.setSubmitLabel?.(m??null))},[e,m]),(0,ae.jsx)("div",{ref:f,"data-testid":"flopay-vault-card-fields"})}function ht({label:e}){return(0,ae.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,ae.jsx)("span",{children:e}),(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var bt=/^#([0-9a-f]{6})$/i,Er=/^#([0-9a-f]{3})$/i,vt=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ct=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Rr=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,xr=/^(-?\d+(?:\.\d+)?)(?:px)?$/,_r=/^(-?\d+(?:\.\d+)?)em$/,Mr=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Fr=/^[a-z][a-z0-9 -]{0,31}$/i,Tr=new Set(["none","uppercase","lowercase","capitalize"]);function Pt(e){if(typeof e!="string")return null;let t=e.trim(),r=bt.exec(t);if(r){let f=Number.parseInt(r[1],16);return{r:f>>16&255,g:f>>8&255,b:f&255,a:null}}let n=Er.exec(t);if(n){let[f,S,g]=n[1].split("").map(k=>Number.parseInt(k+k,16));return{r:f,g:S,b:g,a:null}}let o=vt.exec(t),a=o?null:Ct.exec(t),s=o??a;if(!s)return null;let l=Number(s[1]),d=Number(s[2]),p=Number(s[3]);return l>255||d>255||p>255?null:{r:l,g:d,b:p,a:a?Number(a[4]):null}}function wt({r:e,g:t,b:r,a:n}){return n===null?`#${(1<<24|e<<16|t<<8|r).toString(16).slice(1)}`:`rgba(${e},${t},${r},${n})`}function be(e){if(typeof e!="string")return;let t=e.trim();if(bt.test(t)||vt.test(t))return t;let r=Ct.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=Pt(t);return n?wt(n):void 0}function _e(e,t=.12){let r=Pt(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return wt({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function ve(e,t){let r=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===t&&n===0){o.trim()&&r.push(o.trim()),o="";continue}o+=a}return o.trim()&&r.push(o.trim()),r}function se(e,t,r){if(typeof e!="number"&&typeof e!="string")return;let n=xr.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Ar(e,t,r){if(typeof e!="string")return;let n=_r.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Lr(e){let t=ve(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=ve(o," "),s=be(a[0]);if(!s)return;let l=n/(t.length-1)*100,d=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),p=r[r.length-1]?.position??-1;if(!Number.isFinite(d)||d<0||d>100||d<p)return;r.push({color:s,position:d})}return{type:"linearGradient",angle:0,stops:r}}function Br(e){if(typeof e!="string")return;let t=e.trim(),r=be(t);if(r)return{type:"solid",color:r};let n=Rr.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Lr(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Or(e){return e.type==="solid"?{type:"solid",color:_e(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:_e(t.color)}))}}function Ir(e){let t=!1,r,n=[];for(let d of ve(e," ")){if(d.toLowerCase()==="inset"){t=!0;continue}let p=be(d);if(p){r=p;continue}let f=se(d,-128,128);if(f===void 0)return;n.push(f)}if(!r||n.length<2||n.length>4)return;let[o,a,s=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||s>128||Math.abs(l)>32))return{color:r,inset:t,offsetX:o,offsetY:a,blur:s,spread:l}}function Dr(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=ve(t,",").map(Ir);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function St(e){if(typeof e!="string")return;let t=ve(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>Fr.test(r)).slice(0,4);return t.length>0?t:void 0}function Vr(e){let t=typeof e=="string"?e.trim().split(/\s+/):[e],r=se(t[0],0,64),n=se(t[1]??t[0],0,64);if(!(r===void 0||n===void 0))return{paddingBlock:r,paddingInline:n}}function Nr(e){if(e==="bold")return 700;if(e==="normal")return 400;let t=Number(e);return Number.isInteger(t)&&t>=100&&t<=900?t:void 0}function kt({appearance:e,buttonsStyles:t,fontFamily:r}){let n=t.submitButton;if(!n)return;let o=e?.variables,a=Br(n.background??n.backgroundColor),s=be(o?.colorPrimaryHover),l=s?{type:"solid",color:s}:a&&Or(a),d={fontFamilies:St(n.fontFamily)??St(r),fontSize:se(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:Nr(n.fontWeight)??600,letterSpacing:Ar(n.letterSpacing,-.1,.5)??.01,lineHeight:se(n.lineHeight,.8,2)??1,textTransform:Tr.has(String(n.textTransform))?n.textTransform:"uppercase"},p=Vr(n.padding),f=Dr(n.boxShadow),S=se(n.borderRadius,0,9999),g=typeof n.backdropFilter=="string"?se(Mr.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:be(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:d,...p?{spacing:p}:{},...f?{shadow:f}:{},...S===void 0?{}:{borderRadius:S},disabledOpacity:e?.theme==="night"?.8:.6,...g===void 0?{}:{backdropBlur:g}}}function Ur(e,t=.12){let r=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(r)?`#${r}`:r;return/^#[0-9a-fA-F]{6}$/.test(n)?_e(n,t):e}function Hr(e){if(typeof e=="number"||typeof e=="string")return e}function Et({appearance:e,buttonsStyles:t,layout:r="default"}){let n=e?.variables,o=S=>typeof S=="string"&&S?S:void 0,a=t.submitButton,s=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=r==="buttons",d=t.nameInput,p=o(d?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",f=kt({appearance:e,buttonsStyles:t,fontFamily:p});return{primaryColor:s,primaryHoverColor:o(n?.colorPrimaryHover)??Ur(s,.12),inputBackgroundColor:o(t.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(t.cardInputColor)??o(d?.color)??o(n?.colorText)??"#262833",borderColor:o(t.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(t.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:p,fontSize:o(t.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Hr(d?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...f?{submitButton:f}:{}}}var Ne=require("react/jsx-runtime"),Ce=class extends me.FloPayError{constructor(t,r,n){super(t,r,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ie(e,t={}){let r=e instanceof me.FloPayError?e:void 0,n=r?.statusCode,o=t.retryable??(r?.type==="network_error"||r?.type==="rate_limit_error"||typeof n=="number"&&n>=500||r?.code==="vault_capture_timeout"||!r);return new Ce(r?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),r?.type??"api_error",{code:t.code??r?.code??"card_setup_load_failed",retryable:o,...r?.param?{param:r.param}:{},...n===void 0?{}:{statusCode:n}})}var $e=require("react");var Pe=require("@flopay/js/card-setup"),T=require("@flopay/shared"),u=br(require("react"),1);var xt=require("@flopay/shared"),Wr=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),Yr=new Set(["wallet","apm"]);function ye(e){return typeof e=="string"&&e.trim().length>0}function zr(e){if(typeof e!="object"||e===null)return!1;let t=e;return ye(t.family)&&ye(t.paymentMethodType)}function $r(e){let r=e.raw?.data?.currency;return ye(r)?r.trim().toUpperCase():null}function _t(e){let t=$r(e),r=e.data.session?.advertisedPaymentMethods;if(!Array.isArray(r))return{card:!0,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]};let n={card:!1,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]},o=new Set;for(let a of r){if(!zr(a)||o.has(a.paymentMethodType))continue;let{family:s,paymentMethodType:l,providerType:d,publishableKey:p}=a;if(s==="card"){if(l!=="card")continue;n.card=!0}else if(Yr.has(s)){if(d!=="stripe"||l==="card"||!ye(p))continue;if(t===null){n.skippedForMissingCurrency.includes(l)||n.skippedForMissingCurrency.push(l);continue}n.stripe.push({method:l,publishableKey:p,currency:t})}else if(s==="paypal"){if(l!==xt.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE||d!=="paypal"||!ye(p))continue;n.paypal={clientId:p,...ye(a.environment)?{environment:a.environment}:{}}}else continue;o.add(l)}return n.paypal&&(n.stripe=n.stripe.filter(a=>a.method!=="paypal")),n}function Fe(e){return[...e.card?["card"]:[],...e.stripe.map(t=>t.method),...e.paypal?["paypal"]:[]]}function Mt(e){return Fe(e).length>0}function Te(e){return Wr.has(e)?"wallet":"apm"}var Gr=["setup_intent","setup_intent_client_secret","redirect_status"];function Ft(){if(typeof window>"u")return null;let e=new URLSearchParams(window.location.search);return!e.has("setup_intent")||!e.has("redirect_status")?null:{failed:e.get("redirect_status")==="failed"}}function Tt(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of Gr)e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0);t&&window.history.replaceState(window.history.state,"",e.toString())}function At(e){return e==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}var C=require("react/jsx-runtime"),Kr=15,Xr=2e3;function qr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(t=>setTimeout(t,e))}async function Zr(e,t,r){if(!t.trim())throw new T.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new T.FloPayError("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let n=await e.getUnifiedCheckoutSession(t,r),o=n.data.session;if(!o||!(0,T.isCardSetupCheckoutSession)(o))throw new T.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=_t(n);if(!Mt(a)){let{skippedForMissingCurrency:s}=a,l=s.length>0?`FloPay: this setup session advertises only Stripe methods (${s.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 T.FloPayError(l,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:o,advertisement:a}}async function Jr(e,t,r,n){let o=t.vault??null;if(o?.html?.trim()||(o=await e.getVaultCapture(r,n)),!o.html?.trim())throw new T.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var Ae=class extends u.default.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(r){this.props.onFailed(r,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function Bt({branches:{StripeSetupMethod:e,PayPalSetupMethod:t},sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,theme:s="modern-light",containerStyle:l,loading:d=null,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P}){let[E]=(0,u.useState)(Ft),[m,_]=(0,u.useState)(null),[D,M]=(0,u.useState)(!1),[v,j]=(0,u.useState)(null),[N,R]=(0,u.useState)(null),[W,$]=(0,u.useState)(null),[U,A]=(0,u.useState)(null),[Y,te]=(0,u.useState)(()=>new Set),K=(0,u.useRef)(Y),re=(0,u.useRef)(null);re.current=m;let G=(0,u.useRef)(!1),ue=(0,u.useRef)(!1),ne=(0,u.useRef)(!1),F=(0,u.useRef)(!1),V=(0,u.useRef)(0),L=(0,u.useRef)(0),de=(0,u.useRef)(!1),z=(0,u.useMemo)(()=>typeof s=="object"?void 0:(0,T.resolveTheme)(s),[s]),ur=(0,u.useMemo)(()=>typeof s=="object"?s:z?Et({appearance:z.appearance,buttonsStyles:z.buttonsLayout,layout:"default"}):null,[z,s]),dr=(0,u.useMemo)(()=>dt(z?.buttonsLayout.cardFormContainer,l),[z,l]),Ge=(0,u.useMemo)(()=>z?ft(z):void 0,[z]),O=(0,u.useRef)({sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P});O.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P},(0,u.useEffect)(()=>{de.current=!0;let i=V.current+1;return V.current=i,()=>{de.current=!1,L.current+=1,queueMicrotask(()=>{V.current===i&&(ne.current||F.current||(F.current=!0,q(()=>{O.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let ce=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"success",wording:i,message:null}),(async()=>(await Ue(600),!ue.current&&(ue.current=!0,q(()=>{O.current.onComplete?.({status:"succeeded",sessionId:O.current.sessionId,...c?{paymentMethod:c}:{}})}),de.current&&A(null))))()},[]),pe=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"error",wording:i,message:c.message??null}),q(()=>{O.current.onDecline?.({status:"declined",sessionId:O.current.sessionId,...c.reason?{reason:c.reason}:{},...c.message?{message:c.message}:{}})}),(async()=>(await Ue(400),de.current&&A(null)))()},[]),J=(0,u.useCallback)((i,c)=>{G.current?(G.current=!1,A({status:"error",wording:i,message:c.message}),setTimeout(()=>{de.current&&A(null)},400)):A(null),q(()=>O.current.onError?.(c))},[]),ke=(0,u.useCallback)(async i=>{let c=L.current+1;L.current=c;let h=()=>!de.current||c!==L.current;G.current=!0,A({status:"processing",wording:"payment_method",message:null});let b=new Pe.PaymentAPI((0,T.resolveBillingApiUrl)(O.current.billingApiUrl),{telemetry:O.current.telemetry});try{for(let y=0;y<Kr;y+=1){if((y>0||i.waitFirst)&&await Ue(Xr),h())return;let Q=await b.getUnifiedCheckoutSession(O.current.sessionId,O.current.nonce);if(h())return;let oe=Q.data.session?.status;if(oe==="complete"){M(!0),ce("payment_method");return}if(oe==="expired")throw new T.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new T.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(y){if(h())return;let Q=y instanceof T.FloPayError&&y.code==="payment_method_setup_unverified";J("payment_method",ie(y,Q?{retryable:!0}:{}))}finally{b.destroy()}},[J,ce]);(0,u.useEffect)(()=>{let i=!0,c=new Pe.PaymentAPI((0,T.resolveBillingApiUrl)(o),{telemetry:a});_(null),M(!1),j(null),R(null),$(null);let h=new Set;return K.current=h,te(h),ne.current=!1,F.current=!1,ue.current=!1,(async()=>{try{let{session:b,advertisement:y}=await Zr(c,r,n);if(!i)return;let Q={advertisement:y,customer:qr(b),...b.futureUse?{futureUse:b.futureUse}:{},...b.futureUseUnsupported?{futureUseUnsupported:b.futureUseUnsupported}:{}};if(E){if(Tt(),b.status==="complete"){M(!0),_(Q),ce("payment_method");return}E.failed?pe("payment_method",{reason:"redirect_failed"}):ke({waitFirst:!0})}let oe=y.card?await Jr(c,b,r,n):null;if(!i)return;_(Q),oe&&(R(oe),j(new Pe.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(b){if(!i)return;let y=ie(b);ne.current=!0,$(y),q(()=>O.current.onError?.(y))}})(),()=>{i=!1,c.destroy()}},[o,n,E,pe,ce,r,a,ke]),(0,u.useEffect)(()=>{if(!v)return;G.current=!1;let i=v.on("submitting",()=>{G.current=!0,A({status:"processing",wording:"card",message:null})}),c=v.on("complete",y=>{ce("card",y.paymentMethod)}),h=v.on("decline",y=>{pe("card",{...y.declineReason?{reason:y.declineReason}:{},...y.message?{message:y.message}:{}})}),b=v.on("challenge_dismissed",()=>{A(null)});return()=>{i(),c(),h(),b()}},[v,pe,ce]);let je=(0,u.useCallback)((i,c,h)=>{if(h.retryable){J("payment_method",ie(c,h));return}if(K.current.has(i))return;let b=new Set(K.current);b.add(i),K.current=b,te(b);let y=re.current?.advertisement,Q=y?Fe(y).some(oe=>!b.has(oe)):!1;J("payment_method",ie(c,{code:h.code,retryable:Q}))},[J]),Ke=(0,u.useMemo)(()=>({onSubmitting:()=>{G.current=!0,A({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{ke({waitFirst:!1})},onDeclined:i=>pe("payment_method",i),onValidation:i=>{q(()=>O.current.onValidation?.(i))},onAbandoned:()=>{G.current=!1,A(null)}}),[pe,ke]),Xe=(0,u.useRef)(je);Xe.current=je;let qe=(0,u.useRef)(new Map),Ee=i=>{let c=qe.current.get(i);if(c)return c;let h=(b,y)=>Xe.current(i,b,y);return qe.current.set(i,h),h},Ze=(0,u.useCallback)(i=>{if(K.current.has(i))return;let c=new Set(K.current);c.add(i),K.current=c,te(c);let h=re.current?.advertisement;h&&Fe(h).some(y=>!c.has(y))||J("payment_method",ie(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[J]),Je=(0,u.useRef)(Ze);Je.current=Ze;let Qe=(0,u.useRef)(new Map),et=i=>{let c=Qe.current.get(i);if(c)return c;let h=()=>Je.current(i);return Qe.current.set(i,h),h},tt=U?(0,C.jsx)(mt,{status:U.status,errorMessage:U.message,...At(U.wording),successNote:null,...Ge?{theme:Ge}:{}}):null;if(W)return(0,C.jsx)("div",{role:"alert",children:W.message});if(!m||D)return(0,C.jsxs)(C.Fragment,{children:[tt,m?null:d]});let{advertisement:he,customer:cr,futureUse:rt,futureUseUnsupported:nt}=m,ot=(0,T.resolveBillingApiUrl)(o),at=a===void 0?{}:{telemetry:a},Ie=he.stripe.filter(({method:i})=>!Y.has(i)),Se=Y.has("paypal")?null:he.paypal,st=!!(he.card&&v&&N?.html),it=({method:i,publishableKey:c,currency:h})=>(0,C.jsx)("div",{"data-flopay-payment-method":i,style:{display:"contents"},children:(0,C.jsx)(Ae,{onFailed:Ee(i),children:(0,C.jsx)(u.Suspense,{fallback:null,children:(0,C.jsx)(e,{method:i,category:Te(i),publishableKey:c,currency:h,...rt?{futureUse:rt}:{},...nt?{futureUseUnsupported:nt}:{},sessionId:r,nonce:n,billingApiUrl:ot,...at,...z?{appearance:z.appearance,buttonsLayout:z.buttonsLayout}:{},...typeof s=="string"?{themeId:s}:{},...Ke,onFailed:Ee(i),onUnavailable:et(i)})})})},i),pr=Ie.filter(({method:i})=>Te(i)==="wallet"),fr=Ie.filter(({method:i})=>Te(i)!=="wallet"),lt=Ie.length>0||Se!==null;return(0,C.jsxs)(C.Fragment,{children:[tt,lt?(0,C.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[pr.map(it),Se?(0,C.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,C.jsx)(Ae,{onFailed:Ee("paypal"),children:(0,C.jsx)(u.Suspense,{fallback:null,children:(0,C.jsx)(t,{clientId:Se.clientId,...Se.environment?{environment:Se.environment}:{},...he.currency?{currency:he.currency}:{},sessionId:r,nonce:n,billingApiUrl:ot,customer:cr,...at,...Ke,onFailed:Ee("paypal"),onUnavailable:et("paypal")})})})}):null,fr.map(it)]}):null,st&<?(0,C.jsx)(ht,{label:"or add a card"}):null,st&&v&&N?.html?(0,C.jsx)("div",{"data-flopay-payment-method":"card",children:(0,C.jsx)(gt,{capture:v,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,theme:ur,containerStyle:dr,onReady:()=>{q(()=>O.current.onReady?.())},onValidation:i=>{q(()=>O.current.onValidation?.(i))},onError:i=>{i&&J("card",ie(new Error(i),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var lr=require("react/jsx-runtime"),gn={StripeSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(tr(),er)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(sr(),or)).then(e=>({default:e.PayPalSetupMethod})))};function ir(e){return(0,lr.jsx)(Bt,{...e,branches:gn})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
27
|
+
`})]})})}var H=require("react");var xe=require("react"),gt=typeof window>"u"?xe.useEffect:xe.useLayoutEffect;var se=require("react/jsx-runtime"),Ve=new WeakSet;function ht({capture:e,html:t,messageToken:r,expectedOrigin:n,verificationRequired:o,theme:a,submitLabel:s,containerStyle:l,onReady:d,onError:c,onValidation:f}){let h=(0,H.useRef)(null),S=(0,H.useRef)(d),k=(0,H.useRef)(c),x=(0,H.useRef)(f);S.current=d,k.current=c,x.current=f;let E=(0,H.useRef)(a);E.current=a;let y=(0,H.useRef)(null),P=s??void 0,L=(0,H.useRef)(P);L.current=P;let B=(0,H.useRef)(void 0);return(0,H.useEffect)(()=>{let b=h.current;if(!b)return;let $=!0,V=!1,R=()=>{!$||V||(V=!0,S.current?.())},W=e.on("ready",()=>{R()}),G=e.on("error",U=>{k.current?.(U.message??"There was a problem loading the secure card form.")}),Y=e.on("validation",U=>{x.current?.(U.message??null)}),M=L.current??(Ve.has(e)?null:void 0),re={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...o?{verificationRequired:!0}:{},...E.current?{theme:E.current}:{},...M===void 0?{}:{submitLabel:M}};return y.current=E.current??null,B.current=L.current,L.current!==void 0&&Ve.add(e),e.mount(b,re).then(()=>{R()}).catch(U=>{$&&k.current?.(U instanceof Error?U.message:"Failed to load the secure card form.")}),()=>{$=!1,W(),G(),Y(),e.unmount()}},[e,t,r,n,o]),gt(()=>{let b=h.current;b&&pt(b,l)},[l]),(0,H.useEffect)(()=>{a!==void 0&&(a===null&&y.current===null||(y.current=a,e.applyTheme?.(a)))},[e,a]),(0,H.useEffect)(()=>{P!==B.current&&(B.current=P,P!==void 0&&Ve.add(e),e.setSubmitLabel?.(P??null))},[e,P]),(0,se.jsx)("div",{ref:h,"data-testid":"flopay-vault-card-fields"})}function St({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 vt=/^#([0-9a-f]{6})$/i,Rr=/^#([0-9a-f]{3})$/i,Ct=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Pt=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,xr=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,_r=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Mr=/^(-?\d+(?:\.\d+)?)em$/,Fr=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Tr=/^[a-z][a-z0-9 -]{0,31}$/i,Ar=new Set(["none","uppercase","lowercase","capitalize"]);function wt(e){if(typeof e!="string")return null;let t=e.trim(),r=vt.exec(t);if(r){let f=Number.parseInt(r[1],16);return{r:f>>16&255,g:f>>8&255,b:f&255,a:null}}let n=Rr.exec(t);if(n){let[f,h,S]=n[1].split("").map(k=>Number.parseInt(k+k,16));return{r:f,g:h,b:S,a:null}}let o=Ct.exec(t),a=o?null:Pt.exec(t),s=o??a;if(!s)return null;let l=Number(s[1]),d=Number(s[2]),c=Number(s[3]);return l>255||d>255||c>255?null:{r:l,g:d,b:c,a:a?Number(a[4]):null}}function kt({r:e,g:t,b:r,a:n}){return n===null?`#${(1<<24|e<<16|t<<8|r).toString(16).slice(1)}`:`rgba(${e},${t},${r},${n})`}function be(e){if(typeof e!="string")return;let t=e.trim();if(vt.test(t)||Ct.test(t))return t;let r=Pt.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=wt(t);return n?kt(n):void 0}function _e(e,t=.12){let r=wt(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return kt({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function ve(e,t){let r=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===t&&n===0){o.trim()&&r.push(o.trim()),o="";continue}o+=a}return o.trim()&&r.push(o.trim()),r}function ie(e,t,r){if(typeof e!="number"&&typeof e!="string")return;let n=_r.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Lr(e,t,r){if(typeof e!="string")return;let n=Mr.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Br(e){let t=ve(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=ve(o," "),s=be(a[0]);if(!s)return;let l=n/(t.length-1)*100,d=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),c=r[r.length-1]?.position??-1;if(!Number.isFinite(d)||d<0||d>100||d<c)return;r.push({color:s,position:d})}return{type:"linearGradient",angle:0,stops:r}}function Or(e){if(typeof e!="string")return;let t=e.trim(),r=be(t);if(r)return{type:"solid",color:r};let n=xr.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Br(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Ir(e){return e.type==="solid"?{type:"solid",color:_e(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:_e(t.color)}))}}function Dr(e){let t=!1,r,n=[];for(let d of ve(e," ")){if(d.toLowerCase()==="inset"){t=!0;continue}let c=be(d);if(c){r=c;continue}let f=ie(d,-128,128);if(f===void 0)return;n.push(f)}if(!r||n.length<2||n.length>4)return;let[o,a,s=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||s>128||Math.abs(l)>32))return{color:r,inset:t,offsetX:o,offsetY:a,blur:s,spread:l}}function Vr(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=ve(t,",").map(Dr);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function bt(e){if(typeof e!="string")return;let t=ve(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>Tr.test(r)).slice(0,4);return t.length>0?t:void 0}function Ur(e){let t=typeof e=="string"?e.trim().split(/\s+/):[e],r=ie(t[0],0,64),n=ie(t[1]??t[0],0,64);if(!(r===void 0||n===void 0))return{paddingBlock:r,paddingInline:n}}function Nr(e){if(e==="bold")return 700;if(e==="normal")return 400;let t=Number(e);return Number.isInteger(t)&&t>=100&&t<=900?t:void 0}function Et({appearance:e,buttonsStyles:t,fontFamily:r}){let n=t.submitButton;if(!n)return;let o=e?.variables,a=Or(n.background??n.backgroundColor),s=be(o?.colorPrimaryHover),l=s?{type:"solid",color:s}:a&&Ir(a),d={fontFamilies:bt(n.fontFamily)??bt(r),fontSize:ie(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:Nr(n.fontWeight)??600,letterSpacing:Lr(n.letterSpacing,-.1,.5)??.01,lineHeight:ie(n.lineHeight,.8,2)??1,textTransform:Ar.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Ur(n.padding),f=Vr(n.boxShadow),h=ie(n.borderRadius,0,9999),S=typeof n.backdropFilter=="string"?ie(Fr.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:be(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:d,...c?{spacing:c}:{},...f?{shadow:f}:{},...h===void 0?{}:{borderRadius:h},disabledOpacity:e?.theme==="night"?.8:.6,...S===void 0?{}:{backdropBlur:S}}}function Hr(e,t=.12){let r=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(r)?`#${r}`:r;return/^#[0-9a-fA-F]{6}$/.test(n)?_e(n,t):e}function Wr(e){if(typeof e=="number"||typeof e=="string")return e}function Rt({appearance:e,buttonsStyles:t,layout:r="default"}){let n=e?.variables,o=h=>typeof h=="string"&&h?h:void 0,a=t.submitButton,s=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=r==="buttons",d=t.nameInput,c=o(d?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",f=Et({appearance:e,buttonsStyles:t,fontFamily:c});return{primaryColor:s,primaryHoverColor:o(n?.colorPrimaryHover)??Hr(s,.12),inputBackgroundColor:o(t.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(t.cardInputColor)??o(d?.color)??o(n?.colorText)??"#262833",borderColor:o(t.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(t.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:c,fontSize:o(t.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Wr(d?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...f?{submitButton:f}:{}}}var Ue=require("react/jsx-runtime"),Ce=class extends ee.FloPayError{constructor(t,r,n){super(t,r,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function le(e,t={}){let r=e instanceof ee.FloPayError?e:void 0,n=r?.statusCode,o=t.retryable??(r?.type==="network_error"||r?.type==="rate_limit_error"||typeof n=="number"&&n>=500||r?.code==="vault_capture_timeout"||!r);return new Ce(r?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),r?.type??"api_error",{code:t.code??r?.code??"card_setup_load_failed",retryable:o,...r?.param?{param:r.param}:{},...n===void 0?{}:{statusCode:n}})}var $e=require("react");var Pe=require("@flopay/js/card-setup"),C=require("@flopay/shared"),u=vr(require("react"),1);var _t=require("@flopay/shared"),Yr=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),zr=new Set(["wallet","apm"]);function ye(e){return typeof e=="string"&&e.trim().length>0}function $r(e){if(typeof e!="object"||e===null)return!1;let t=e;return ye(t.family)&&ye(t.paymentMethodType)}function Gr(e){let r=e.raw?.data?.currency;return ye(r)?r.trim().toUpperCase():null}function Mt(e){let t=Gr(e),r=e.data.session?.advertisedPaymentMethods;if(!Array.isArray(r))return{card:!0,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]};let n={card:!1,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]},o=new Set;for(let a of r){if(!$r(a)||o.has(a.paymentMethodType))continue;let{family:s,paymentMethodType:l,providerType:d,publishableKey:c}=a;if(s==="card"){if(l!=="card")continue;n.card=!0}else if(zr.has(s)){if(d!=="stripe"||l==="card"||!ye(c))continue;if(t===null){n.skippedForMissingCurrency.includes(l)||n.skippedForMissingCurrency.push(l);continue}n.stripe.push({method:l,publishableKey:c,currency:t})}else if(s==="paypal"){if(l!==_t.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE||d!=="paypal"||!ye(c))continue;n.paypal={clientId:c,...ye(a.environment)?{environment:a.environment}:{}}}else continue;o.add(l)}return n.paypal&&(n.stripe=n.stripe.filter(a=>a.method!=="paypal")),n}function Fe(e){return[...e.card?["card"]:[],...e.stripe.map(t=>t.method),...e.paypal?["paypal"]:[]]}function Ft(e){return Fe(e).length>0}function Te(e){return Yr.has(e)?"wallet":"apm"}var jr=["setup_intent","setup_intent_client_secret","redirect_status"];function Tt(){if(typeof window>"u")return null;let e=new URLSearchParams(window.location.search);return!e.has("setup_intent")||!e.has("redirect_status")?null:{failed:e.get("redirect_status")==="failed"}}function At(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of jr)e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0);t&&window.history.replaceState(window.history.state,"",e.toString())}function Lt(e){return e==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}var v=require("react/jsx-runtime"),Xr=15,qr=2e3;function Zr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ne(e){return new Promise(t=>setTimeout(t,e))}async function Jr(e,t,r){if(!t.trim())throw new C.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new C.FloPayError("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let n=await e.getUnifiedCheckoutSession(t,r),o=n.data.session;if(!o||!(0,C.isCardSetupCheckoutSession)(o))throw new C.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=Mt(n);if(!Ft(a)){let{skippedForMissingCurrency:s}=a,l=s.length>0?`FloPay: this setup session advertises only Stripe methods (${s.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(l,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:o,advertisement:a}}async function Qr(e,t,r,n,o){let a=t.vault??null;(0,C.isMountableVaultBlock)(a)||(a=await e.getVaultCapture(r,n));let s=(0,C.resolveVaultMountOptions)(a,{billingApiUrl:o,sessionId:r,nonce:n});if(!s)throw new C.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return s}var Ae=class extends u.default.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(r){this.props.onFailed(r,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function Ot({branches:{StripeSetupMethod:e,PayPalSetupMethod:t},sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,theme:s="modern-light",containerStyle:l,loading:d=null,onReady:c,onComplete:f,onDecline:h,onCancel:S,onValidation:k,onError:x}){let[E]=(0,u.useState)(Tt),[y,P]=(0,u.useState)(null),[L,B]=(0,u.useState)(!1),[b,$]=(0,u.useState)(null),[V,R]=(0,u.useState)(null),[W,G]=(0,u.useState)(null),[Y,M]=(0,u.useState)(null),[re,U]=(0,u.useState)(()=>new Set),X=(0,u.useRef)(re),ne=(0,u.useRef)(null);ne.current=y;let j=(0,u.useRef)(!1),de=(0,u.useRef)(!1),oe=(0,u.useRef)(!1),F=(0,u.useRef)(!1),N=(0,u.useRef)(0),T=(0,u.useRef)(0),ce=(0,u.useRef)(!1),z=(0,u.useMemo)(()=>typeof s=="object"?void 0:(0,C.resolveTheme)(s),[s]),dr=(0,u.useMemo)(()=>typeof s=="object"?s:z?Rt({appearance:z.appearance,buttonsStyles:z.buttonsLayout,layout:"default"}):null,[z,s]),cr=(0,u.useMemo)(()=>ct(z?.buttonsLayout.cardFormContainer,l),[z,l]),Ge=(0,u.useMemo)(()=>z?mt(z):void 0,[z]),O=(0,u.useRef)({sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:c,onComplete:f,onDecline:h,onCancel:S,onValidation:k,onError:x});O.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:c,onComplete:f,onDecline:h,onCancel:S,onValidation:k,onError:x},(0,u.useEffect)(()=>{ce.current=!0;let i=N.current+1;return N.current=i,()=>{ce.current=!1,T.current+=1,queueMicrotask(()=>{N.current===i&&(oe.current||F.current||(F.current=!0,Z(()=>{O.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let pe=(0,u.useCallback)((i,p)=>{oe.current=!0,j.current=!1,M({status:"success",wording:i,message:null}),(async()=>(await Ne(600),!de.current&&(de.current=!0,Z(()=>{O.current.onComplete?.({status:"succeeded",sessionId:O.current.sessionId,...p?{paymentMethod:p}:{}})}),ce.current&&M(null))))()},[]),fe=(0,u.useCallback)((i,p)=>{oe.current=!0,j.current=!1,M({status:"error",wording:i,message:p.message??null}),Z(()=>{O.current.onDecline?.({status:"declined",sessionId:O.current.sessionId,...p.reason?{reason:p.reason}:{},...p.message?{message:p.message}:{}})}),(async()=>(await Ne(400),ce.current&&M(null)))()},[]),Q=(0,u.useCallback)((i,p)=>{j.current?(j.current=!1,M({status:"error",wording:i,message:p.message}),setTimeout(()=>{ce.current&&M(null)},400)):M(null),Z(()=>O.current.onError?.(p))},[]),ke=(0,u.useCallback)(async i=>{let p=T.current+1;T.current=p;let g=()=>!ce.current||p!==T.current;j.current=!0,M({status:"processing",wording:"payment_method",message:null});let I=new Pe.PaymentAPI((0,C.resolveBillingApiUrl)(O.current.billingApiUrl),{telemetry:O.current.telemetry});try{for(let m=0;m<Xr;m+=1){if((m>0||i.waitFirst)&&await Ne(qr),g())return;let K=await I.getUnifiedCheckoutSession(O.current.sessionId,O.current.nonce);if(g())return;let ae=K.data.session?.status;if(ae==="complete"){B(!0),pe("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(m){if(g())return;let K=m instanceof C.FloPayError&&m.code==="payment_method_setup_unverified";Q("payment_method",le(m,K?{retryable:!0}:{}))}finally{I.destroy()}},[Q,pe]);(0,u.useEffect)(()=>{let i=!0,p=(0,C.resolveBillingApiUrl)(o),g=new Pe.PaymentAPI(p,{telemetry:a});P(null),B(!1),$(null),R(null),G(null);let I=new Set;return X.current=I,U(I),oe.current=!1,F.current=!1,de.current=!1,(async()=>{try{let{session:m,advertisement:K}=await Jr(g,r,n);if(!i)return;let ae={advertisement:K,customer:Zr(m),...m.futureUse?{futureUse:m.futureUse}:{},...m.futureUseUnsupported?{futureUseUnsupported:m.futureUseUnsupported}:{}};if(E){if(At(),m.status==="complete"){B(!0),P(ae),pe("payment_method");return}E.failed?fe("payment_method",{reason:"redirect_failed"}):ke({waitFirst:!0})}let ut=K.card?await Qr(g,m,r,n,p):null;if(!i)return;P(ae),ut&&(R(ut),$(new Pe.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(m){if(!i)return;let K=le(m);oe.current=!0,G(K),Z(()=>O.current.onError?.(K))}})(),()=>{i=!1,g.destroy()}},[o,n,E,fe,pe,r,a,ke]),(0,u.useEffect)(()=>{if(!b)return;j.current=!1;let i=b.on("submitting",()=>{j.current=!0,M({status:"processing",wording:"card",message:null})}),p=b.on("complete",m=>{pe("card",m.paymentMethod)}),g=b.on("decline",m=>{fe("card",{...m.declineReason?{reason:m.declineReason}:{},...m.message?{message:m.message}:{}})}),I=b.on("challenge_dismissed",()=>{M(null)});return()=>{i(),p(),g(),I()}},[b,fe,pe]);let je=(0,u.useCallback)((i,p,g)=>{if(g.retryable){Q("payment_method",le(p,g));return}if(X.current.has(i))return;let I=new Set(X.current);I.add(i),X.current=I,U(I);let m=ne.current?.advertisement,K=m?Fe(m).some(ae=>!I.has(ae)):!1;Q("payment_method",le(p,{code:g.code,retryable:K}))},[Q]),Ke=(0,u.useMemo)(()=>({onSubmitting:()=>{j.current=!0,M({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{ke({waitFirst:!1})},onDeclined:i=>fe("payment_method",i),onValidation:i=>{Z(()=>O.current.onValidation?.(i))},onAbandoned:()=>{j.current=!1,M(null)}}),[fe,ke]),Xe=(0,u.useRef)(je);Xe.current=je;let qe=(0,u.useRef)(new Map),Ee=i=>{let p=qe.current.get(i);if(p)return p;let g=(I,m)=>Xe.current(i,I,m);return qe.current.set(i,g),g},Ze=(0,u.useCallback)(i=>{if(X.current.has(i))return;let p=new Set(X.current);p.add(i),X.current=p,U(p);let g=ne.current?.advertisement;g&&Fe(g).some(m=>!p.has(m))||Q("payment_method",le(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[Q]),Je=(0,u.useRef)(Ze);Je.current=Ze;let Qe=(0,u.useRef)(new Map),et=i=>{let p=Qe.current.get(i);if(p)return p;let g=()=>Je.current(i);return Qe.current.set(i,g),g},tt=Y?(0,v.jsx)(yt,{status:Y.status,errorMessage:Y.message,...Lt(Y.wording),successNote:null,...Ge?{theme:Ge}:{}}):null;if(W)return(0,v.jsx)("div",{role:"alert",children:W.message});if(!y||L)return(0,v.jsxs)(v.Fragment,{children:[tt,y?null:d]});let{advertisement:he,customer:pr,futureUse:rt,futureUseUnsupported:nt}=y,ot=(0,C.resolveBillingApiUrl)(o),at=a===void 0?{}:{telemetry:a},Ie=he.stripe.filter(({method:i})=>!re.has(i)),Se=re.has("paypal")?null:he.paypal,st=!!(he.card&&b&&V?.html),it=({method:i,publishableKey:p,currency:g})=>(0,v.jsx)("div",{"data-flopay-payment-method":i,style:{display:"contents"},children:(0,v.jsx)(Ae,{onFailed:Ee(i),children:(0,v.jsx)(u.Suspense,{fallback:null,children:(0,v.jsx)(e,{method:i,category:Te(i),publishableKey:p,currency:g,...rt?{futureUse:rt}:{},...nt?{futureUseUnsupported:nt}:{},sessionId:r,nonce:n,billingApiUrl:ot,...at,...z?{appearance:z.appearance,buttonsLayout:z.buttonsLayout}:{},...typeof s=="string"?{themeId:s}:{},...Ke,onFailed:Ee(i),onUnavailable:et(i)})})})},i),fr=Ie.filter(({method:i})=>Te(i)==="wallet"),mr=Ie.filter(({method:i})=>Te(i)!=="wallet"),lt=Ie.length>0||Se!==null;return(0,v.jsxs)(v.Fragment,{children:[tt,lt?(0,v.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[fr.map(it),Se?(0,v.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,v.jsx)(Ae,{onFailed:Ee("paypal"),children:(0,v.jsx)(u.Suspense,{fallback:null,children:(0,v.jsx)(t,{clientId:Se.clientId,...Se.environment?{environment:Se.environment}:{},...he.currency?{currency:he.currency}:{},sessionId:r,nonce:n,billingApiUrl:ot,customer:pr,...at,...Ke,onFailed:Ee("paypal"),onUnavailable:et("paypal")})})})}):null,mr.map(it)]}):null,st&<?(0,v.jsx)(St,{label:"or add a card"}):null,st&&b&&V?.html?(0,v.jsx)("div",{"data-flopay-payment-method":"card",children:(0,v.jsx)(ht,{capture:b,html:V.html,messageToken:V.messageToken,expectedOrigin:V.expectedOrigin,verificationRequired:V.verificationRequired,theme:dr,containerStyle:cr,onReady:()=>{Z(()=>O.current.onReady?.())},onValidation:i=>{Z(()=>O.current.onValidation?.(i))},onError:i=>{i&&Q("card",le(new Error(i),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var ur=require("react/jsx-runtime"),hn={StripeSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(rr(),tr)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(ir(),ar)).then(e=>({default:e.PayPalSetupMethod})))};function lr(e){return(0,ur.jsx)(Ot,{...e,branches:hn})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-
|
|
1
|
+
import{a as t}from"./chunk-52RFSQJ7.mjs";import{k as a}from"./chunk-AW5LOT2K.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-TI2A5JPE.mjs").then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:o(()=>import("./payment-method-setup-paypal-FRRQW56L.mjs").then(e=>({default:e.PayPalSetupMethod})))};function y(e){return P(t,{...e,branches:p})}export{a as FloPayCardSetupError,y as FloPayPaymentMethodSetup};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopay/react",
|
|
3
|
-
"version": "1.11.
|
|
3
|
+
"version": "1.11.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"publishConfig": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"dist"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@paypal/paypal-js": "^10.
|
|
40
|
-
"@stripe/react-stripe-js": "^6.
|
|
41
|
-
"@stripe/stripe-js": "^9.
|
|
42
|
-
"@flopay/js": "1.11.
|
|
43
|
-
"@flopay/shared": "1.11.
|
|
39
|
+
"@paypal/paypal-js": "^10.1.0",
|
|
40
|
+
"@stripe/react-stripe-js": "^6.12.0",
|
|
41
|
+
"@stripe/stripe-js": "^9.17.0",
|
|
42
|
+
"@flopay/js": "1.11.5",
|
|
43
|
+
"@flopay/shared": "1.11.5"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=18.0.0",
|
|
@@ -48,12 +48,12 @@
|
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@testing-library/jest-dom": "^6.6.0",
|
|
51
|
-
"@testing-library/react": "^16.
|
|
52
|
-
"@types/react": "^19.
|
|
53
|
-
"@types/react-dom": "^19.
|
|
51
|
+
"@testing-library/react": "^16.3.3",
|
|
52
|
+
"@types/react": "^19.3.0",
|
|
53
|
+
"@types/react-dom": "^19.3.0",
|
|
54
54
|
"jsdom": "^29.1.1",
|
|
55
|
-
"react": "^19.
|
|
56
|
-
"react-dom": "^19.
|
|
55
|
+
"react": "^19.3.0",
|
|
56
|
+
"react-dom": "^19.3.0",
|
|
57
57
|
"tsup": "^8.3.0",
|
|
58
58
|
"typescript": "^6.0.3",
|
|
59
59
|
"vitest": "4.1.11"
|
package/dist/chunk-AZRGKPW7.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{useEffect as ee,useRef as E}from"react";function le(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(a=>a.startsWith("background")),i={};for(let[a,u]of Object.entries(e))a in t||o&&a.startsWith("background")||(i[a]=u);for(let a of n)i[a]=t[a];return i}var Fe=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 Te(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Fe.has(r.charAt(0).toLowerCase()+r.slice(1))}function Pe(e,r){return typeof r=="number"&&r!==0&&!Te(e)?`${r}px`:String(r).trim()}function ce(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Pe(t,n)}}}import{useEffect as Ve,useLayoutEffect as Ae}from"react";var de=typeof window>"u"?Ve:Ae;import{jsx as Y,jsxs as Le}from"react/jsx-runtime";var re=new WeakSet;function fe({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:i,containerStyle:a,onReady:u,onError:s,onValidation:c}){let l=E(null),f=E(u),y=E(s),p=E(c);f.current=u,y.current=s,p.current=c;let T=E(o);T.current=o;let k=E(null),C=i??void 0,P=E(C);P.current=C;let L=E(void 0);return ee(()=>{let w=l.current;if(!w)return;let m=!0,G=!1,B=()=>{!m||G||(G=!0,f.current?.())},x=e.on("ready",()=>{B()}),_=e.on("error",S=>{y.current?.(S.message??"There was a problem loading the secure card form.")}),b=e.on("validation",S=>{p.current?.(S.message??null)}),H=P.current??(re.has(e)?null:void 0),q={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...T.current?{theme:T.current}:{},...H===void 0?{}:{submitLabel:H}};return k.current=T.current??null,L.current=P.current,P.current!==void 0&&re.add(e),e.mount(w,q).then(()=>{B()}).catch(S=>{m&&y.current?.(S instanceof Error?S.message:"Failed to load the secure card form.")}),()=>{m=!1,x(),_(),b(),e.unmount()}},[e,r,t,n]),de(()=>{let w=l.current;w&&ce(w,a)},[a]),ee(()=>{o!==void 0&&(o===null&&k.current===null||(k.current=o,e.applyTheme?.(o)))},[e,o]),ee(()=>{C!==L.current&&(L.current=C,C!==void 0&&re.add(e),e.setSubmitLabel?.(C??null))},[e,C]),Y("div",{ref:l,"data-testid":"flopay-vault-card-fields"})}function cr({label:e}){return Le("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[Y("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),Y("span",{children:e}),Y("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}import{PaymentAPI as Je,PciVaultCardCapture as Qe}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as er,resolveBillingApiUrl as rr,resolveTheme as tr}from"@flopay/shared";import{useEffect as te,useMemo as X,useRef as h,useState as $}from"react";var pe={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function me(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?pe.dark:pe.light,i=r.colorText??(n?"#F1F5F9":"#262833"),a=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:i,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:i,success:o.success,error:o.error},noteColor:a?.color??i}}function F(e){if(!e)return;let r=t=>{console.error("[FloPay] Merchant callback failed; checkout continued.",t)};try{Promise.resolve(e()).catch(r)}catch(t){r(t)}}import{jsx as g,jsxs as I}from"react/jsx-runtime";var Be={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ge({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:i="PAYMENT FAILED",successNote:a="You will be automatically redirected, do not close or navigate away from this window.",theme:u=Be}){let s={fontSize:13,color:u.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return g("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:I("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...u.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[I("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&I("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:[g("circle",{cx:"12",cy:"12",r:"10",stroke:u.spinnerTrackColor,strokeWidth:"3"}),g("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:u.spinnerAccentColor})]}),e==="success"&&g("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:I("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),g("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"&&g("div",{style:{animation:"flopay-shake 0.4s ease"},children:I("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),g("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"}})]})})]}),I("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:u.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&a!==null&&g("p",{style:s,children:a}),e==="error"&&r&&g("p",{style:s,children:r}),g("style",{children:`
|
|
2
|
-
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
|
-
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
|
-
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
|
-
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}var be=/^#([0-9a-f]{6})$/i,Oe=/^#([0-9a-f]{3})$/i,he=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ce=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Ie=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Me=/^(-?\d+(?:\.\d+)?)(?:px)?$/,_e=/^(-?\d+(?:\.\d+)?)em$/,Ne=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,De=/^[a-z][a-z0-9 -]{0,31}$/i,ze=new Set(["none","uppercase","lowercase","capitalize"]);function Se(e){if(typeof e!="string")return null;let r=e.trim(),t=be.exec(r);if(t){let l=Number.parseInt(t[1],16);return{r:l>>16&255,g:l>>8&255,b:l&255,a:null}}let n=Oe.exec(r);if(n){let[l,f,y]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:l,g:f,b:y,a:null}}let o=he.exec(r),i=o?null:Ce.exec(r),a=o??i;if(!a)return null;let u=Number(a[1]),s=Number(a[2]),c=Number(a[3]);return u>255||s>255||c>255?null:{r:u,g:s,b:c,a:i?Number(i[4]):null}}function ke({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(be.test(r)||he.test(r))return r;let t=Ce.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Se(r);return n?ke(n):void 0}function U(e,r=.12){let t=Se(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ke({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let i of e){if(i==="("&&(n+=1),i===")"&&(n-=1),i===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=i}return o.trim()&&t.push(o.trim()),t}function A(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=Me.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(e,r,t){if(typeof e!="string")return;let n=_e.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let i=W(o," "),a=z(i[0]);if(!a)return;let u=n/(r.length-1)*100,s=i[1]===void 0?u:Number(/^(\d+(?:\.\d+)?)%$/.exec(i[1])?.[1]),c=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<c)return;t.push({color:a,position:s})}return{type:"linearGradient",angle:0,stops:t}}function Ge(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Ie.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=$e(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function He(e){return e.type==="solid"?{type:"solid",color:U(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:U(r.color)}))}}function Ye(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=z(s);if(c){t=c;continue}let l=A(s,-128,128);if(l===void 0)return;n.push(l)}if(!t||n.length<2||n.length>4)return;let[o,i,a=0,u=0]=n;if(!(Math.abs(o)>64||Math.abs(i)>64||a>128||Math.abs(u)>32))return{color:t,inset:r,offsetX:o,offsetY:i,blur:a,spread:u}}function Ue(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(Ye);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ye(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>De.test(t)).slice(0,4);return r.length>0?r:void 0}function Xe(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=A(r[0],0,64),n=A(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function je(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function we({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=Ge(n.background??n.backgroundColor),a=z(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&He(i),s={fontFamilies:ye(n.fontFamily)??ye(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:je(n.fontWeight)??600,letterSpacing:We(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:ze.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Xe(n.padding),l=Ue(n.boxShadow),f=A(n.borderRadius,0,9999),y=typeof n.backdropFilter=="string"?A(Ne.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...i?{background:i,disabledBackground:i}:{},...u?{hoverBackground:u}:{},typography:s,...c?{spacing:c}:{},...l?{shadow:l}:{},...f===void 0?{}:{borderRadius:f},disabledOpacity:e?.theme==="night"?.8:.6,...y===void 0?{}:{backdropBlur:y}}}function qe(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?U(n,r):e}function Ke(e){if(typeof e=="number"||typeof e=="string")return e}function xe({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=f=>typeof f=="string"&&f?f:void 0,i=r.submitButton,a=o(n?.colorPrimary)??o(i?.backgroundColor)??"#4A49FF",u=t==="buttons",s=r.nameInput,c=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",l=we({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??qe(a,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ke(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as Ee,jsx as j,jsxs as nr}from"react/jsx-runtime";var ne=class extends M{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ve(e,r={}){let t=e instanceof M?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new ne(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:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Pr({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:i,loading:a=null,onReady:u,onComplete:s,onDecline:c,onCancel:l,onValidation:f,onError:y}){let[p,T]=$(null),[k,C]=$(null),[P,L]=$(null),[w,m]=$(null),[G,B]=$(null),x=h(!1),_=h(!1),b=X(()=>typeof o=="object"?void 0:tr(o),[o]),H=X(()=>typeof o=="object"?o:b?xe({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),q=X(()=>le(b?.buttonsLayout.cardFormContainer,i),[b,i]),S=X(()=>b?me(b):void 0,[b]),oe=h(u),K=h(y),ie=h(s),ae=h(c),se=h(l),ue=h(f),N=h(!1),Z=h(!1),J=h(0);return oe.current=u,K.current=y,ie.current=s,ae.current=c,se.current=l,ue.current=f,te(()=>{let d=J.current+1;return J.current=d,()=>{queueMicrotask(()=>{J.current===d&&(N.current||Z.current||(Z.current=!0,F(()=>{se.current?.({status:"cancelled",sessionId:e})})))})}},[e]),te(()=>{let d=!0,V=new Je(rr(t),{telemetry:n});return T(null),C(null),L(null),N.current=!1,Z.current=!1,(async()=>{try{if(!e.trim())throw new M("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new M("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await V.getUnifiedCheckoutSession(e,r);if(!d)return;let R=D.data.session;if(!R||!er(R))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let O=R.vault;if(O?.html?.trim()||(O=await V.getVaultCapture(e,r)),!O.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;C(O),T(new Qe({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!d)return;let R=ve(D);N.current=!0,L(R),F(()=>K.current?.(R))}})(),()=>{d=!1,V.destroy()}},[t,r,e,n]),te(()=>{if(!p)return;let d=!1;_.current=!1,x.current=!1;let V=p.on("submitting",()=>{x.current=!0,B(null),m("processing")}),D=p.on("complete",v=>{N.current=!0,x.current=!1,m("success"),(async()=>(await new Promise(Q=>setTimeout(Q,600)),!_.current&&(_.current=!0,F(()=>{ie.current?.({status:"succeeded",sessionId:e,...v.paymentMethod?{paymentMethod:v.paymentMethod}:{}})}),d||m(null))))()}),R=p.on("decline",v=>{N.current=!0,x.current=!1,B(v.message??null),m("error"),F(()=>{ae.current?.({status:"declined",sessionId:e,...v.declineReason?{reason:v.declineReason}:{},...v.message?{message:v.message}:{}})}),(async()=>(await new Promise(Q=>setTimeout(Q,400)),d||m(null)))()}),O=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,V(),D(),R(),O()}},[p,e]),P?j("div",{role:"alert",children:P.message}):!p||!k?.html?j(Ee,{children:a}):nr(Ee,{children:[w&&j(ge,{status:w,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...S?{theme:S}:{}}),j(fe,{capture:p,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:H,containerStyle:q,onReady:()=>{F(()=>oe.current?.())},onValidation:d=>{F(()=>ue.current?.(d))},onError:d=>{if(!d)return;x.current&&(x.current=!1,B(d),m("error"),setTimeout(()=>m(null),400));let V=ve(new Error(d),{code:"card_setup_widget_failed",retryable:!0});F(()=>K.current?.(V))}})]})}export{le as a,me as b,F as c,ge as d,de as e,fe as f,cr as g,qe as h,Ke as i,xe as j,ne as k,ve as l,Pr as m};
|
package/dist/chunk-LIYRDFMO.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as De,b as Le,c as P,d as Oe,f as Ie,g as Be,j as xe,l as F}from"./chunk-AZRGKPW7.mjs";import{PaymentAPI as Ke,PciVaultCardCapture as lt}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as ut,resolveBillingApiUrl as ae,resolveTheme as ct}from"@flopay/shared";import dt,{Suspense as ze,useCallback as V,useEffect as oe,useMemo as B,useRef as m,useState as w}from"react";import{PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as tt}from"@flopay/shared";var rt=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),nt=new Set(["wallet","apm"]);function U(t){return typeof t=="string"&&t.trim().length>0}function at(t){if(typeof t!="object"||t===null)return!1;let o=t;return U(o.family)&&U(o.paymentMethodType)}function ot(t){let a=t.raw?.data?.currency;return U(a)?a.trim().toUpperCase():null}function Ne(t){let o=ot(t),a=t.data.session?.advertisedPaymentMethods;if(!Array.isArray(a))return{card:!0,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]};let i={card:!1,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]},c=new Set;for(let u of a){if(!at(u)||c.has(u.paymentMethodType))continue;let{family:d,paymentMethodType:f,providerType:x,publishableKey:_}=u;if(d==="card"){if(f!=="card")continue;i.card=!0}else if(nt.has(d)){if(x!=="stripe"||f==="card"||!U(_))continue;if(o===null){i.skippedForMissingCurrency.includes(f)||i.skippedForMissingCurrency.push(f);continue}i.stripe.push({method:f,publishableKey:_,currency:o})}else if(d==="paypal"){if(f!==tt||x!=="paypal"||!U(_))continue;i.paypal={clientId:_,...U(u.environment)?{environment:u.environment}:{}}}else continue;c.add(f)}return i.paypal&&(i.stripe=i.stripe.filter(u=>u.method!=="paypal")),i}function j(t){return[...t.card?["card"]:[],...t.stripe.map(o=>o.method),...t.paypal?["paypal"]:[]]}function Ye(t){return j(t).length>0}function K(t){return rt.has(t)?"wallet":"apm"}var st=["setup_intent","setup_intent_client_secret","redirect_status"];function We(){if(typeof window>"u")return null;let t=new URLSearchParams(window.location.search);return!t.has("setup_intent")||!t.has("redirect_status")?null:{failed:t.get("redirect_status")==="failed"}}function He(){if(typeof window>"u")return;let t=new URL(window.location.href),o=!1;for(let a of st)t.searchParams.has(a)&&(t.searchParams.delete(a),o=!0);o&&window.history.replaceState(window.history.state,"",t.toString())}function Ge(t){return t==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}import{Fragment as qe,jsx as y,jsxs as ie}from"react/jsx-runtime";var pt=15,mt=2e3;function yt(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function se(t){return new Promise(o=>setTimeout(o,t))}async function ft(t,o,a){if(!o.trim())throw new M("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new M("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let i=await t.getUnifiedCheckoutSession(o,a),c=i.data.session;if(!c||!ut(c))throw new M("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let u=Ne(i);if(!Ye(u)){let{skippedForMissingCurrency:d}=u,f=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 M(f,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:c,advertisement:u}}async function ht(t,o,a,i){let c=o.vault??null;if(c?.html?.trim()||(c=await t.getVaultCapture(a,i)),!c.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return c}var z=class extends dt.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(a){this.props.onFailed(a,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function kt({branches:{StripeSetupMethod:t,PayPalSetupMethod:o},sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,theme:d="modern-light",containerStyle:f,loading:x=null,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe}){let[q]=w(We),[N,$]=w(null),[$e,J]=w(!1),[g,me]=w(null),[D,ye]=w(null),[fe,he]=w(null),[Y,h]=w(null),[Q,X]=w(()=>new Set),R=m(Q),Z=m(null);Z.current=N;let v=m(!1),ee=m(!1),L=m(!1),te=m(!1),re=m(0),W=m(0),A=m(!1),S=B(()=>typeof d=="object"?void 0:ct(d),[d]),Je=B(()=>typeof d=="object"?d:S?xe({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,d]),Qe=B(()=>De(S?.buttonsLayout.cardFormContainer,f),[S,f]),Se=B(()=>S?Le(S):void 0,[S]),p=m({sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe});p.current={sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe},oe(()=>{A.current=!0;let e=re.current+1;return re.current=e,()=>{A.current=!1,W.current+=1,queueMicrotask(()=>{re.current===e&&(L.current||te.current||(te.current=!0,P(()=>{p.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let k=V((e,r)=>{L.current=!0,v.current=!1,h({status:"success",wording:e,message:null}),(async()=>(await se(600),!ee.current&&(ee.current=!0,P(()=>{p.current.onComplete?.({status:"succeeded",sessionId:p.current.sessionId,...r?{paymentMethod:r}:{}})}),A.current&&h(null))))()},[]),T=V((e,r)=>{L.current=!0,v.current=!1,h({status:"error",wording:e,message:r.message??null}),P(()=>{p.current.onDecline?.({status:"declined",sessionId:p.current.sessionId,...r.reason?{reason:r.reason}:{},...r.message?{message:r.message}:{}})}),(async()=>(await se(400),A.current&&h(null)))()},[]),C=V((e,r)=>{v.current?(v.current=!1,h({status:"error",wording:e,message:r.message}),setTimeout(()=>{A.current&&h(null)},400)):h(null),P(()=>p.current.onError?.(r))},[]),H=V(async e=>{let r=W.current+1;W.current=r;let s=()=>!A.current||r!==W.current;v.current=!0,h({status:"processing",wording:"payment_method",message:null});let l=new Ke(ae(p.current.billingApiUrl),{telemetry:p.current.telemetry});try{for(let n=0;n<pt;n+=1){if((n>0||e.waitFirst)&&await se(mt),s())return;let b=await l.getUnifiedCheckoutSession(p.current.sessionId,p.current.nonce);if(s())return;let E=b.data.session?.status;if(E==="complete"){J(!0),k("payment_method");return}if(E==="expired")throw new M("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new M("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(n){if(s())return;let b=n instanceof M&&n.code==="payment_method_setup_unverified";C("payment_method",F(n,b?{retryable:!0}:{}))}finally{l.destroy()}},[C,k]);oe(()=>{let e=!0,r=new Ke(ae(c),{telemetry:u});$(null),J(!1),me(null),ye(null),he(null);let s=new Set;return R.current=s,X(s),L.current=!1,te.current=!1,ee.current=!1,(async()=>{try{let{session:l,advertisement:n}=await ft(r,a,i);if(!e)return;let b={advertisement:n,customer:yt(l),...l.futureUse?{futureUse:l.futureUse}:{},...l.futureUseUnsupported?{futureUseUnsupported:l.futureUseUnsupported}:{}};if(q){if(He(),l.status==="complete"){J(!0),$(b),k("payment_method");return}q.failed?T("payment_method",{reason:"redirect_failed"}):H({waitFirst:!0})}let E=n.card?await ht(r,l,a,i):null;if(!e)return;$(b),E&&(ye(E),me(new lt({sessionId:a,operation:"card_setup",telemetry:u})))}catch(l){if(!e)return;let n=F(l);L.current=!0,he(n),P(()=>p.current.onError?.(n))}})(),()=>{e=!1,r.destroy()}},[c,i,q,T,k,a,u,H]),oe(()=>{if(!g)return;v.current=!1;let e=g.on("submitting",()=>{v.current=!0,h({status:"processing",wording:"card",message:null})}),r=g.on("complete",n=>{k("card",n.paymentMethod)}),s=g.on("decline",n=>{T("card",{...n.declineReason?{reason:n.declineReason}:{},...n.message?{message:n.message}:{}})}),l=g.on("challenge_dismissed",()=>{h(null)});return()=>{e(),r(),s(),l()}},[g,T,k]);let ge=V((e,r,s)=>{if(s.retryable){C("payment_method",F(r,s));return}if(R.current.has(e))return;let l=new Set(R.current);l.add(e),R.current=l,X(l);let n=Z.current?.advertisement,b=n?j(n).some(E=>!l.has(E)):!1;C("payment_method",F(r,{code:s.code,retryable:b}))},[C]),ve=B(()=>({onSubmitting:()=>{v.current=!0,h({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{H({waitFirst:!1})},onDeclined:e=>T("payment_method",e),onValidation:e=>{P(()=>p.current.onValidation?.(e))},onAbandoned:()=>{v.current=!1,h(null)}}),[T,H]),Pe=m(ge);Pe.current=ge;let Ce=m(new Map),G=e=>{let r=Ce.current.get(e);if(r)return r;let s=(l,n)=>Pe.current(e,l,n);return Ce.current.set(e,s),s},be=V(e=>{if(R.current.has(e))return;let r=new Set(R.current);r.add(e),R.current=r,X(r);let s=Z.current?.advertisement;s&&j(s).some(n=>!r.has(n))||C("payment_method",F(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[C]),we=m(be);we.current=be;let Me=m(new Map),_e=e=>{let r=Me.current.get(e);if(r)return r;let s=()=>we.current(e);return Me.current.set(e,s),s},Re=Y?y(Oe,{status:Y.status,errorMessage:Y.message,...Ge(Y.wording),successNote:null,...Se?{theme:Se}:{}}):null;if(fe)return y("div",{role:"alert",children:fe.message});if(!N||$e)return ie(qe,{children:[Re,N?null:x]});let{advertisement:O,customer:Xe,futureUse:Ee,futureUseUnsupported:Fe}=N,Ae=ae(c),ke=u===void 0?{}:{telemetry:u},ne=O.stripe.filter(({method:e})=>!Q.has(e)),I=Q.has("paypal")?null:O.paypal,Te=!!(O.card&&g&&D?.html),Ue=({method:e,publishableKey:r,currency:s})=>y("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:y(z,{onFailed:G(e),children:y(ze,{fallback:null,children:y(t,{method:e,category:K(e),publishableKey:r,currency:s,...Ee?{futureUse:Ee}:{},...Fe?{futureUseUnsupported:Fe}:{},sessionId:a,nonce:i,billingApiUrl:Ae,...ke,...S?{appearance:S.appearance,buttonsLayout:S.buttonsLayout}:{},...typeof d=="string"?{themeId:d}:{},...ve,onFailed:G(e),onUnavailable:_e(e)})})})},e),Ze=ne.filter(({method:e})=>K(e)==="wallet"),et=ne.filter(({method:e})=>K(e)!=="wallet"),Ve=ne.length>0||I!==null;return ie(qe,{children:[Re,Ve?ie("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ze.map(Ue),I?y("div",{"data-flopay-payment-method":"paypal",children:y(z,{onFailed:G("paypal"),children:y(ze,{fallback:null,children:y(o,{clientId:I.clientId,...I.environment?{environment:I.environment}:{},...O.currency?{currency:O.currency}:{},sessionId:a,nonce:i,billingApiUrl:Ae,customer:Xe,...ke,...ve,onFailed:G("paypal"),onUnavailable:_e("paypal")})})})}):null,et.map(Ue)]}):null,Te&&Ve?y(Be,{label:"or add a card"}):null,Te&&g&&D?.html?y("div",{"data-flopay-payment-method":"card",children:y(Ie,{capture:g,html:D.html,messageToken:D.messageToken,expectedOrigin:D.expectedOrigin,theme:Je,containerStyle:Qe,onReady:()=>{P(()=>p.current.onReady?.())},onValidation:e=>{P(()=>p.current.onValidation?.(e))},onError:e=>{e&&C("card",F(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{kt as a};
|