@flopay/react 1.10.0 → 1.10.2

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.
@@ -1,6 +1,6 @@
1
- "use strict";var Mt=Object.create;var de=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var At=Object.getOwnPropertyNames;var Tt=Object.getPrototypeOf,Bt=Object.prototype.hasOwnProperty;var pe=(e,t)=>()=>(e&&(t=e(e=0)),t);var Ee=(e,t)=>{for(var r in t)de(e,r,{get:t[r],enumerable:!0})},Ne=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of At(t))!Bt.call(e,o)&&o!==r&&de(e,o,{get:()=>t[o],enumerable:!(n=xt(t,o))||n.enumerable});return e};var Lt=(e,t,r)=>(r=e!=null?Mt(Tt(e)):{},Ne(t||!e||!e.__esModule?de(r,"default",{value:e,enumerable:!0}):r,e)),Ot=e=>Ne(de({},"__esModule",{value:!0}),e);function he(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 dt(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 se(e){if(typeof e!="string")return;let t=e.trim();return/^[a-z0-9_.-]{1,64}$/i.test(t)?t:void 0}function pt(e){if(typeof e!="object"||e===null)return;let t=e;return se(t.code)??se(t.type)??se(t.name)}function fr(e){if(!(typeof e!="object"||e===null))return se(e.decline_code)}function Fe(e){return typeof e!="object"||e===null?!1:se(e.type)?.toLowerCase()==="card_error"||fr(e)!==void 0}function mr(e){let t=dt(e)?.toLowerCase()??"",r=pt(e)?.toLowerCase()??"";return dr.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 yr(e){if(pt(e)?.toLowerCase()==="paypal_init_timeout")return!0;let r=dt(e)??"";return r.includes("No ack for postMessage init()")&&pr.some(n=>r.includes(n))&&r.includes("10000ms")}function Se(e,t){if(Fe(e))return{errorCode:"PROVIDER_RUNTIME_FAILED",popupBlocked:!1,providerDeclined:!0,terminalReason:"provider_declined"};let n=mr(e)||t.inAppBrowser&&!t.handoffObserved&&yr(e);return{errorCode:n?"POPUP_BLOCKED":"PROVIDER_RUNTIME_FAILED",popupBlocked:n,providerDeclined:!1,terminalReason:n?"popup_blocked":"provider_error"}}var dr,pr,Me=pe(()=>{"use strict";dr=new Set(["err_blocked_by_client","notallowederror","popup_blocked","popupblocked"]),pr=["https://www.paypal.com","https://www.sandbox.paypal.com"]});function be(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 ft(e,t,r=e.popupCapability){return e.inAppBrowser||r==="blocked"||t==="prefer_redirect"?"redirect":"popup"}var xe=pe(()=>{"use strict"});var ht={};Ee(ht,{StripeSetupMethod:()=>vr});function gr(e){let t=Ae.get(e);if(t)return t;let r=(0,yt.loadStripe)(e).catch(n=>{throw Ae.delete(e),n});return Ae.set(e,r),r}function Sr(e){return e?{theme:hr[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function br(e){return Fe(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Pr(e){return e==="paypal"?"PayPal":(0,Pe.getStripeMethodDisplayName)(e)}function Cr(){return typeof window>"u"?"":window.location.href}function vr(e){let{publishableKey:t,method:r,currency:n,appearance:o}=e,[a]=(0,V.useState)(()=>gr(t)),i=(0,V.useMemo)(()=>{let l=Sr(o);return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:gt[r]?.types??[r],...l?{appearance:l}:{}}},[o,n,r]);return(0,z.jsx)(U.Elements,{stripe:a,options:i,children:(0,z.jsx)(wr,{...e})})}function wr({method:e,category:t,sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onSubmitting:i,onConfirmed:l,onDeclined:c,onFailed:p,onValidation:d}){let y=(0,U.useStripe)(),h=(0,U.useElements)(),[A,w]=(0,V.useState)(!1),F=(0,V.useRef)(!1),[m]=(0,V.useState)(()=>be()),[T,D]=(0,V.useState)(!1),R=(0,V.useCallback)((f,v)=>{if(Se(f,{inAppBrowser:m.inAppBrowser,handoffObserved:!1}).popupBlocked){D(!0),p(new Error(he(Pr(e),!0,m.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}p(v.message===void 0?f:new Error(v.message),{code:v.code,retryable:!0})},[m.inAppBrowser,e,p]),S=(0,V.useCallback)(async()=>{if(!(!y||!h||F.current)){F.current=!0,w(!0);try{let f=await h.submit();if(f.error){d(f.error.message??null);return}i();let v=await new mt.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 Pe.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let P=await y.confirmSetup({elements:h,clientSecret:v.clientSecret,confirmParams:{return_url:Cr()},redirect:"if_required"});if(P.error){br(P.error)?c({...P.error.decline_code||P.error.code?{reason:P.error.decline_code??P.error.code}:{},...P.error.message?{message:P.error.message}:{}}):R(P.error,{code:"payment_method_setup_provider_failed",message:P.error.message??"The payment method could not be saved."});return}l()}catch(f){R(f,{code:"payment_method_setup_failed"})}finally{F.current=!1,w(!1)}}},[o,t,h,e,n,l,c,i,d,R,r,y,a]),L=gt[e]?.wallet,O=L==="paypal"&&ft(m,"auto",T?"blocked":m.popupCapability)==="redirect";if(t==="wallet"&&L&&!O){let f={applePay:"never",googlePay:"never",link:"never",paypal:"never",amazonPay:"never"};return f[L]="auto",(0,z.jsx)(U.ExpressCheckoutElement,{options:{paymentMethods:f},onConfirm:()=>{S()}})}return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U.PaymentElement,{onChange:f=>{f.complete&&d(null)}}),(0,z.jsx)("button",{type:"button","data-flopay-payment-method-save":e,disabled:!y||!h||A,onClick:()=>{S()},children:"Save payment method"})]})}var mt,Pe,U,yt,V,z,gt,Ae,hr,St=pe(()=>{"use strict";mt=require("@flopay/js/card-setup"),Pe=require("@flopay/shared"),U=require("@stripe/react-stripe-js"),yt=require("@stripe/stripe-js"),V=require("react");Me();xe();z=require("react/jsx-runtime"),gt={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"}},Ae=new Map;hr={night:"night",flat:"flat"}});var Ct={};Ee(Ct,{PayPalSetupMethod:()=>Er});function Er({clientId:e,environment:t,currency:r,sessionId:n,nonce:o,billingApiUrl:a,telemetry:i,customer:{userId:l,email:c},onSubmitting:p,onConfirmed:d,onFailed:y,onAbandoned:h}){let A=(0,K.useRef)(null),w=(0,K.useRef)({onSubmitting:p,onConfirmed:d,onFailed:y,onAbandoned:h});w.current={onSubmitting:p,onConfirmed:d,onFailed:y,onAbandoned:h};let[F]=(0,K.useState)(()=>be().inAppBrowser);return(0,K.useEffect)(()=>{let m=!0,T,D=new bt.PaymentAPI(a,{telemetry:i}),R={userId:l,email:c};return(async()=>{try{let S=await(0,Pt.loadScript)({clientId:e,currency:r.toUpperCase(),components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),L=A.current;if(!m||!L)return;if(!S?.Buttons)throw new H.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let O=S.Buttons({createVaultSetupToken:async()=>{w.current.onSubmitting();let f=await D.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:H.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(f.provider!=="paypal"||f.providerObjectType!=="setup_token")throw new H.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return f.providerObjectId},onApprove:async f=>{let v=f.vaultSetupToken;if(!v)throw new H.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let P=await D.processPayment(R.userId,{sessionId:n,nonce:o,paymentMethodCategory:"paypal",tokenizedData:{id:v,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:H.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:R});if(!P.ok)throw new H.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:P.status});m&&w.current.onConfirmed()},onCancel:()=>{m&&w.current.onAbandoned()},onError:f=>{if(!m)return;let{popupBlocked:v}=Se(f,{inAppBrowser:F,handoffObserved:!1});w.current.onFailed(v?new Error(he("PayPal",!0,F)):f,{code:v?"popup_blocked":"paypal_setup_failed",retryable:!0})}});T=()=>O.close(),await O.render(L)}catch(S){if(!m)return;w.current.onFailed(S,{code:"paypal_unavailable",retryable:!0})}})(),()=>{m=!1,T?.().catch(()=>{}),D.destroy()}},[a,e,r,c,t,F,o,n,i,l]),(0,vt.jsx)("div",{ref:A,"data-flopay-paypal-setup":""})}var bt,H,Pt,K,vt,wt=pe(()=>{"use strict";bt=require("@flopay/js/card-setup"),H=require("@flopay/shared"),Pt=require("@paypal/paypal-js"),K=require("react");Me();xe();vt=require("react/jsx-runtime")});var Rr={};Ee(Rr,{FloPayCardSetupError:()=>oe,FloPayPaymentMethodSetup:()=>Et});module.exports=Ot(Rr);var rt=require("@flopay/js/card-setup"),Q=require("@flopay/shared"),ye=require("react");function We(e,t){if(!e)return t;let r=t??{},n=Object.keys(r),o=n.some(i=>i.startsWith("background")),a={};for(let[i,l]of Object.entries(e))i in r||o&&i.startsWith("background")||(a[i]=l);for(let i of n)a[i]=r[i];return a}var It=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 Vt(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return It.has(t.charAt(0).toLowerCase()+t.slice(1))}function Dt(e,t){return typeof t=="number"&&t!==0&&!Vt(e)?`${t}px`:String(t).trim()}function ze(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]=Dt(r,n)}}}var Ue={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function Ge(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?Ue.dark:Ue.light,a=t.colorText??(n?"#F1F5F9":"#262833"),i=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:i?.color??a}}function G(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 b=require("react/jsx-runtime");var Nt={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function He({status:e,errorMessage:t,authorized:r=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:i="You will be automatically redirected, do not close or navigate away from this window.",theme:l=Nt}){let c={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,b.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,b.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,b.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,b.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,b.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,b.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,b.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,b.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,b.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,b.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,b.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,b.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,b.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,b.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,b.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"&&i!==null&&(0,b.jsx)("p",{style:c,children:i}),e==="error"&&t&&(0,b.jsx)("p",{style:c,children:t}),(0,b.jsx)("style",{children:`
1
+ "use strict";var zt=Object.create;var ge=Object.defineProperty;var Ut=Object.getOwnPropertyDescriptor;var Yt=Object.getOwnPropertyNames;var Ht=Object.getPrototypeOf,Gt=Object.prototype.hasOwnProperty;var he=(e,t)=>()=>(e&&(t=e(e=0)),t);var Fe=(e,t)=>{for(var r in t)ge(e,r,{get:t[r],enumerable:!0})},Xe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Yt(t))!Gt.call(e,o)&&o!==r&&ge(e,o,{get:()=>t[o],enumerable:!(n=Ut(t,o))||n.enumerable});return e};var $t=(e,t,r)=>(r=e!=null?zt(Ht(e)):{},Xe(t||!e||!e.__esModule?ge(r,"default",{value:e,enumerable:!0}):r,e)),jt=e=>Xe(ge({},"__esModule",{value:!0}),e);function ve(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 vt(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 ce(e){if(typeof e!="string")return;let t=e.trim();return/^[a-z0-9_.-]{1,64}$/i.test(t)?t:void 0}function wt(e){if(typeof e!="object"||e===null)return;let t=e;return ce(t.code)??ce(t.type)??ce(t.name)}function Mr(e){if(!(typeof e!="object"||e===null))return ce(e.decline_code)}function Le(e){return typeof e!="object"||e===null?!1:ce(e.type)?.toLowerCase()==="card_error"||Mr(e)!==void 0}function Fr(e){let t=vt(e)?.toLowerCase()??"",r=wt(e)?.toLowerCase()??"";return Rr.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 Ar(e){if(wt(e)?.toLowerCase()==="paypal_init_timeout")return!0;let r=vt(e)??"";return r.includes("No ack for postMessage init()")&&_r.some(n=>r.includes(n))&&r.includes("10000ms")}function we(e,t){if(Le(e))return{errorCode:"PROVIDER_RUNTIME_FAILED",popupBlocked:!1,providerDeclined:!0,terminalReason:"provider_declined"};let n=Fr(e)||t.inAppBrowser&&!t.handoffObserved&&Ar(e);return{errorCode:n?"POPUP_BLOCKED":"PROVIDER_RUNTIME_FAILED",popupBlocked:n,providerDeclined:!1,terminalReason:n?"popup_blocked":"provider_error"}}var Rr,_r,Oe=he(()=>{"use strict";Rr=new Set(["err_blocked_by_client","notallowederror","popup_blocked","popupblocked"]),_r=["https://www.paypal.com","https://www.sandbox.paypal.com"]});function Ee(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 Et(e,t,r=e.popupCapability){return e.inAppBrowser||r==="blocked"||t==="prefer_redirect"?"redirect":"popup"}var Ie=he(()=>{"use strict"});var Mt={};Fe(Mt,{StripeSetupMethod:()=>Vr});function Tr(e){let t=Ve.get(e);if(t)return t;let r=(0,Rt.loadStripe)(e).catch(n=>{throw Ve.delete(e),n});return Ve.set(e,r),r}function Br(e){return e?{theme:xr[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function Lr(e){return Le(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Or(e){return e==="paypal"?"PayPal":(0,ke.getStripeMethodDisplayName)(e)}function Ir(){return typeof window>"u"?"":window.location.href}function Vr(e){let{publishableKey:t,method:r,currency:n,appearance:o}=e,[a]=(0,V.useState)(()=>Tr(t)),s=(0,V.useMemo)(()=>{let i=Br(o);return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:_t[r]?.types??[r],...i?{appearance:i}:{}}},[o,n,r]);return(0,z.jsx)(U.Elements,{stripe:a,options:s,children:(0,z.jsx)(Dr,{...e})})}function Dr({method:e,category:t,sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onSubmitting:s,onConfirmed:i,onDeclined:c,onFailed:d,onValidation:p}){let h=(0,U.useStripe)(),S=(0,U.useElements)(),[x,E]=(0,V.useState)(!1),F=(0,V.useRef)(!1),[y]=(0,V.useState)(()=>Ee()),[B,D]=(0,V.useState)(!1),M=(0,V.useCallback)((m,w)=>{if(we(m,{inAppBrowser:y.inAppBrowser,handoffObserved:!1}).popupBlocked){D(!0),d(new Error(ve(Or(e),!0,y.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}d(w.message===void 0?m:new Error(w.message),{code:w.code,retryable:!0})},[y.inAppBrowser,e,d]),b=(0,V.useCallback)(async()=>{if(!(!h||!S||F.current)){F.current=!0,E(!0);try{let m=await S.submit();if(m.error){p(m.error.message??null);return}s();let w=await new kt.PaymentAPI(o,{telemetry:a}).createSessionIntent(r,n,{provider:"stripe",paymentMethodCategory:t,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(w.provider!=="stripe"||w.intentKind!=="setup")throw new ke.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let C=await h.confirmSetup({elements:S,clientSecret:w.clientSecret,confirmParams:{return_url:Ir()},redirect:"if_required"});if(C.error){Lr(C.error)?c({...C.error.decline_code||C.error.code?{reason:C.error.decline_code??C.error.code}:{},...C.error.message?{message:C.error.message}:{}}):M(C.error,{code:"payment_method_setup_provider_failed",message:C.error.message??"The payment method could not be saved."});return}i()}catch(m){M(m,{code:"payment_method_setup_failed"})}finally{F.current=!1,E(!1)}}},[o,t,S,e,n,i,c,s,p,M,r,h,a]),O=_t[e]?.wallet,I=O==="paypal"&&Et(y,"auto",B?"blocked":y.popupCapability)==="redirect";if(t==="wallet"&&O&&!I){let m={applePay:"never",googlePay:"never",link:"never",paypal:"never",amazonPay:"never"};return m[O]="auto",(0,z.jsx)(U.ExpressCheckoutElement,{options:{paymentMethods:m},onConfirm:()=>{b()}})}return(0,z.jsxs)(z.Fragment,{children:[(0,z.jsx)(U.PaymentElement,{onChange:m=>{m.complete&&p(null)}}),(0,z.jsx)("button",{type:"button","data-flopay-payment-method-save":e,disabled:!h||!S||x,onClick:()=>{b()},children:"Save payment method"})]})}var kt,ke,U,Rt,V,z,_t,Ve,xr,Ft=he(()=>{"use strict";kt=require("@flopay/js/card-setup"),ke=require("@flopay/shared"),U=require("@stripe/react-stripe-js"),Rt=require("@stripe/stripe-js"),V=require("react");Oe();Ie();z=require("react/jsx-runtime"),_t={apple_pay:{types:["card"],wallet:"applePay"},google_pay:{types:["card"],wallet:"googlePay"},link:{types:["link"],wallet:"link"},paypal:{types:["paypal"],wallet:"paypal"},amazon_pay:{types:["amazon_pay"],wallet:"amazonPay"}},Ve=new Map;xr={night:"night",flat:"flat"}});var xt={};Fe(xt,{PayPalSetupMethod:()=>Nr});function Nr({clientId:e,environment:t,currency:r,sessionId:n,nonce:o,billingApiUrl:a,telemetry:s,customer:{userId:i,email:c},onSubmitting:d,onConfirmed:p,onFailed:h,onAbandoned:S}){let x=(0,q.useRef)(null),E=(0,q.useRef)({onSubmitting:d,onConfirmed:p,onFailed:h,onAbandoned:S});E.current={onSubmitting:d,onConfirmed:p,onFailed:h,onAbandoned:S};let[F]=(0,q.useState)(()=>Ee().inAppBrowser);return(0,q.useEffect)(()=>{let y=!0,B,D=new At.PaymentAPI(a,{telemetry:s}),M={userId:i,email:c};return(async()=>{try{let b=await(0,Tt.loadScript)({clientId:e,...r?{currency:r.toUpperCase()}:{},components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),O=x.current;if(!y||!O)return;if(!b?.Buttons)throw new $.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let I=b.Buttons({createVaultSetupToken:async()=>{E.current.onSubmitting();let m=await D.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:$.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(m.provider!=="paypal"||m.providerObjectType!=="setup_token")throw new $.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return m.providerObjectId},onApprove:async m=>{let w=m.vaultSetupToken;if(!w)throw new $.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let C=await D.processPayment(M.userId,{sessionId:n,nonce:o,paymentMethodCategory:"paypal",tokenizedData:{id:w,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:$.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:M});if(!C.ok)throw new $.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:C.status});y&&E.current.onConfirmed()},onCancel:()=>{y&&E.current.onAbandoned()},onError:m=>{if(!y)return;let{popupBlocked:w}=we(m,{inAppBrowser:F,handoffObserved:!1});E.current.onFailed(w?new Error(ve("PayPal",!0,F)):m,{code:w?"popup_blocked":"paypal_setup_failed",retryable:!0})}});B=()=>I.close(),await I.render(O)}catch(b){if(!y)return;E.current.onFailed(b,{code:"paypal_unavailable",retryable:!0})}})(),()=>{y=!1,B?.().catch(()=>{}),D.destroy()}},[a,e,r,c,t,F,o,n,s,i]),(0,Bt.jsx)("div",{ref:x,"data-flopay-paypal-setup":""})}var At,$,Tt,q,Bt,Lt=he(()=>{"use strict";At=require("@flopay/js/card-setup"),$=require("@flopay/shared"),Tt=require("@paypal/paypal-js"),q=require("react");Oe();Ie();Bt=require("react/jsx-runtime")});var zr={};Fe(zr,{FloPayCardSetupError:()=>le,FloPayPaymentMethodSetup:()=>Ot});module.exports=jt(zr);var pt=require("@flopay/js/card-setup"),te=require("@flopay/shared"),Pe=require("react");function qe(e,t){if(!e)return t;let r=t??{},n=Object.keys(r),o=n.some(s=>s.startsWith("background")),a={};for(let[s,i]of Object.entries(e))s in r||o&&s.startsWith("background")||(a[s]=i);for(let s of n)a[s]=r[s];return a}var Kt=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 Xt(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Kt.has(t.charAt(0).toLowerCase()+t.slice(1))}function qt(e,t){return typeof t=="number"&&t!==0&&!Xt(e)?`${t}px`:String(t).trim()}function Ze(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]=qt(r,n)}}}var Je={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function Qe(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?Je.dark:Je.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 H(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 P=require("react/jsx-runtime");var Zt={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function et({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:i=Zt}){let c={fontSize:13,color:i.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,P.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,P.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...i.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,P.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,P.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,P.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:i.spinnerTrackColor,strokeWidth:"3"}),(0,P.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:i.spinnerAccentColor})]}),e==="success"&&(0,P.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,P.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,P.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,P.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,P.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,P.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,P.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,P.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,P.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:i.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(r?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&s!==null&&(0,P.jsx)("p",{style:c,children:s}),e==="error"&&t&&(0,P.jsx)("p",{style:c,children:t}),(0,P.jsx)("style",{children:`
2
2
  @keyframes flopay-spin { to { transform: rotate(360deg); } }
3
3
  @keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
4
4
  @keyframes flopay-draw { to { stroke-dashoffset: 0; } }
5
5
  @keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
6
- `})]})})}var B=require("react");var fe=require("react"),Ye=typeof window>"u"?fe.useEffect:fe.useLayoutEffect;var je=require("react/jsx-runtime"),ke=new WeakSet;function $e({capture:e,html:t,messageToken:r,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:i,onReady:l,onError:c,onValidation:p}){let d=(0,B.useRef)(null),y=(0,B.useRef)(l),h=(0,B.useRef)(c),A=(0,B.useRef)(p);y.current=l,h.current=c,A.current=p;let w=(0,B.useRef)(o);w.current=o;let F=(0,B.useRef)(null),m=a??void 0,T=(0,B.useRef)(m);T.current=m;let D=(0,B.useRef)(void 0);return(0,B.useEffect)(()=>{let R=d.current;if(!R)return;let S=!0,L=!1,O=()=>{!S||L||(L=!0,y.current?.())},f=e.on("ready",()=>{O()}),v=e.on("error",_=>{h.current?.(_.message??"There was a problem loading the secure card form.")}),P=e.on("validation",_=>{A.current?.(_.message??null)}),Y=T.current??(ke.has(e)?null:void 0),x={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...w.current?{theme:w.current}:{},...Y===void 0?{}:{submitLabel:Y}};return F.current=w.current??null,D.current=T.current,T.current!==void 0&&ke.add(e),e.mount(R,x).then(()=>{O()}).catch(_=>{S&&h.current?.(_ instanceof Error?_.message:"Failed to load the secure card form.")}),()=>{S=!1,f(),v(),P(),e.unmount()}},[e,t,r,n]),Ye(()=>{let R=d.current;R&&ze(R,i)},[i]),(0,B.useEffect)(()=>{o!==void 0&&(o===null&&F.current===null||(F.current=o,e.applyTheme?.(o)))},[e,o]),(0,B.useEffect)(()=>{m!==D.current&&(D.current=m,m!==void 0&&ke.add(e),e.setSubmitLabel?.(m??null))},[e,m]),(0,je.jsx)("div",{ref:d,"data-testid":"flopay-vault-card-fields"})}var Xe=/^#([0-9a-f]{6})$/i,Wt=/^#([0-9a-f]{3})$/i,qe=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ze=/^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,zt=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Ut=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Gt=/^(-?\d+(?:\.\d+)?)em$/,Ht=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Yt=/^[a-z][a-z0-9 -]{0,31}$/i,$t=new Set(["none","uppercase","lowercase","capitalize"]);function Je(e){if(typeof e!="string")return null;let t=e.trim(),r=Xe.exec(t);if(r){let d=Number.parseInt(r[1],16);return{r:d>>16&255,g:d>>8&255,b:d&255,a:null}}let n=Wt.exec(t);if(n){let[d,y,h]=n[1].split("").map(A=>Number.parseInt(A+A,16));return{r:d,g:y,b:h,a:null}}let o=qe.exec(t),a=o?null:Ze.exec(t),i=o??a;if(!i)return null;let l=Number(i[1]),c=Number(i[2]),p=Number(i[3]);return l>255||c>255||p>255?null:{r:l,g:c,b:p,a:a?Number(a[4]):null}}function Qe({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 re(e){if(typeof e!="string")return;let t=e.trim();if(Xe.test(t)||qe.test(t))return t;let r=Ze.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=Je(t);return n?Qe(n):void 0}function me(e,t=.12){let r=Je(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return Qe({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function ne(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 j(e,t,r){if(typeof e!="number"&&typeof e!="string")return;let n=Ut.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function jt(e,t,r){if(typeof e!="string")return;let n=Gt.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Kt(e){let t=ne(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=ne(o," "),i=re(a[0]);if(!i)return;let l=n/(t.length-1)*100,c=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),p=r[r.length-1]?.position??-1;if(!Number.isFinite(c)||c<0||c>100||c<p)return;r.push({color:i,position:c})}return{type:"linearGradient",angle:0,stops:r}}function Xt(e){if(typeof e!="string")return;let t=e.trim(),r=re(t);if(r)return{type:"solid",color:r};let n=zt.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Kt(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function qt(e){return e.type==="solid"?{type:"solid",color:me(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:me(t.color)}))}}function Zt(e){let t=!1,r,n=[];for(let c of ne(e," ")){if(c.toLowerCase()==="inset"){t=!0;continue}let p=re(c);if(p){r=p;continue}let d=j(c,-128,128);if(d===void 0)return;n.push(d)}if(!r||n.length<2||n.length>4)return;let[o,a,i=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||i>128||Math.abs(l)>32))return{color:r,inset:t,offsetX:o,offsetY:a,blur:i,spread:l}}function Jt(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=ne(t,",").map(Zt);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function Ke(e){if(typeof e!="string")return;let t=ne(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>Yt.test(r)).slice(0,4);return t.length>0?t:void 0}function Qt(e){let t=typeof e=="string"?e.trim().split(/\s+/):[e],r=j(t[0],0,64),n=j(t[1]??t[0],0,64);if(!(r===void 0||n===void 0))return{paddingBlock:r,paddingInline:n}}function er(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=Xt(n.background??n.backgroundColor),i=re(o?.colorPrimaryHover),l=i?{type:"solid",color:i}:a&&qt(a),c={fontFamilies:Ke(n.fontFamily)??Ke(r),fontSize:j(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:er(n.fontWeight)??600,letterSpacing:jt(n.letterSpacing,-.1,.5)??.01,lineHeight:j(n.lineHeight,.8,2)??1,textTransform:$t.has(String(n.textTransform))?n.textTransform:"uppercase"},p=Qt(n.padding),d=Jt(n.boxShadow),y=j(n.borderRadius,0,9999),h=typeof n.backdropFilter=="string"?j(Ht.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:re(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:c,...p?{spacing:p}:{},...d?{shadow:d}:{},...y===void 0?{}:{borderRadius:y},disabledOpacity:e?.theme==="night"?.8:.6,...h===void 0?{}:{backdropBlur:h}}}function tr(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)?me(n,t):e}function rr(e){if(typeof e=="number"||typeof e=="string")return e}function tt({appearance:e,buttonsStyles:t,layout:r="default"}){let n=e?.variables,o=y=>typeof y=="string"&&y?y:void 0,a=t.submitButton,i=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=r==="buttons",c=t.nameInput,p=o(c?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",d=et({appearance:e,buttonsStyles:t,fontFamily:p});return{primaryColor:i,primaryHoverColor:o(n?.colorPrimaryHover)??tr(i,.12),inputBackgroundColor:o(t.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(t.cardInputColor)??o(c?.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(rr(c?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...d?{submitButton:d}:{}}}var Re=require("react/jsx-runtime"),oe=class extends Q.FloPayError{constructor(t,r,n){super(t,r,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ae(e,t={}){let r=e instanceof Q.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 oe(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 Te=require("react");var ie=require("@flopay/js/card-setup"),k=require("@flopay/shared"),s=Lt(require("react"),1);var nr=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]);function nt(e){let t=e.data.stripe,r=Array.from(new Set(t?.enabledPaymentMethods??[])),n=e.data.paypal,o=n?.publishableKey?{clientId:n.publishableKey,...n.environment?{environment:String(n.environment)}:{}}:null,a=r.filter(i=>i!=="card"&&!(o&&i==="paypal"));return{card:r.includes("card"),stripe:t?.publishableKey&&a.length>0?{publishableKey:t.publishableKey,methods:a}:null,paypal:o}}function ot(e){return e.card||e.stripe!==null||e.paypal!==null}function at(e){return nr.has(e)?"wallet":"apm"}var or=["setup_intent","setup_intent_client_secret","redirect_status"];function it(){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 st(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of or)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 C=require("react/jsx-runtime"),ir=15,sr=2e3;function lr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function _e(e){return new Promise(t=>setTimeout(t,e))}async function ur(e,t,r){if(!t.trim())throw new k.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new k.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,k.isCardSetupCheckoutSession)(o))throw new k.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=nt(n);if(!ot(a))throw new k.FloPayError("FloPay: this setup session advertises no payment method.","validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"});return{session:o,advertisement:a}}async function cr(e,t,r,n){let o=t.vault??null;if(o?.html?.trim()||(o=await e.getVaultCapture(r,n)),!o.html?.trim())throw new k.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var ge=class extends s.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 ct({branches:{StripeSetupMethod:e,PayPalSetupMethod:t},sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,theme:i="modern-light",containerStyle:l,loading:c=null,onReady:p,onComplete:d,onDecline:y,onCancel:h,onValidation:A,onError:w}){let[F]=(0,s.useState)(it),[m,T]=(0,s.useState)(null),[D,R]=(0,s.useState)(!1),[S,L]=(0,s.useState)(null),[O,f]=(0,s.useState)(null),[v,P]=(0,s.useState)(null),[Y,x]=(0,s.useState)(null),_=(0,s.useRef)(!1),Ce=(0,s.useRef)(!1),ee=(0,s.useRef)(!1),ve=(0,s.useRef)(!1),we=(0,s.useRef)(0),le=(0,s.useRef)(0),X=(0,s.useRef)(!1),N=(0,s.useMemo)(()=>typeof i=="object"?void 0:(0,k.resolveTheme)(i),[i]),Rt=(0,s.useMemo)(()=>typeof i=="object"?i:N?tt({appearance:N.appearance,buttonsStyles:N.buttonsLayout,layout:"default"}):null,[N,i]),_t=(0,s.useMemo)(()=>We(N?.buttonsLayout.cardFormContainer,l),[N,l]),Be=(0,s.useMemo)(()=>N?Ge(N):void 0,[N]),M=(0,s.useRef)({sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:d,onDecline:y,onCancel:h,onValidation:A,onError:w});M.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:d,onDecline:y,onCancel:h,onValidation:A,onError:w},(0,s.useEffect)(()=>{X.current=!0;let u=we.current+1;return we.current=u,()=>{X.current=!1,le.current+=1,queueMicrotask(()=>{we.current===u&&(ee.current||ve.current||(ve.current=!0,G(()=>{M.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let q=(0,s.useCallback)((u,g)=>{ee.current=!0,_.current=!1,x({status:"success",wording:u,message:null}),(async()=>(await _e(600),!Ce.current&&(Ce.current=!0,G(()=>{M.current.onComplete?.({status:"succeeded",sessionId:M.current.sessionId,...g?{paymentMethod:g}:{}})}),X.current&&x(null))))()},[]),Z=(0,s.useCallback)((u,g)=>{ee.current=!0,_.current=!1,x({status:"error",wording:u,message:g.message??null}),G(()=>{M.current.onDecline?.({status:"declined",sessionId:M.current.sessionId,...g.reason?{reason:g.reason}:{},...g.message?{message:g.message}:{}})}),(async()=>(await _e(400),X.current&&x(null)))()},[]),te=(0,s.useCallback)((u,g)=>{_.current?(_.current=!1,x({status:"error",wording:u,message:g.message}),setTimeout(()=>{X.current&&x(null)},400)):x(null),G(()=>M.current.onError?.(g))},[]),ue=(0,s.useCallback)(async u=>{let g=le.current+1;le.current=g;let I=()=>!X.current||g!==le.current;_.current=!0,x({status:"processing",wording:"payment_method",message:null});let W=new ie.PaymentAPI((0,k.resolveBillingApiUrl)(M.current.billingApiUrl),{telemetry:M.current.telemetry});try{for(let E=0;E<ir;E+=1){if((E>0||u.waitFirst)&&await _e(sr),I())return;let J=await W.getUnifiedCheckoutSession(M.current.sessionId,M.current.nonce);if(I())return;let De=J.data.session?.status;if(De==="complete"){R(!0),q("payment_method");return}if(De==="expired")throw new k.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new k.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(E){if(I())return;let J=E instanceof k.FloPayError&&E.code==="payment_method_setup_unverified";te("payment_method",ae(E,J?{retryable:!0}:{}))}finally{W.destroy()}},[te,q]);(0,s.useEffect)(()=>{let u=!0,g=new ie.PaymentAPI((0,k.resolveBillingApiUrl)(o),{telemetry:a});return T(null),R(!1),L(null),f(null),P(null),ee.current=!1,ve.current=!1,Ce.current=!1,(async()=>{try{let{session:I,advertisement:W}=await ur(g,r,n);if(!u)return;let E={advertisement:W,currency:I.currency,customer:lr(I)};if(F){if(st(),I.status==="complete"){R(!0),T(E),q("payment_method");return}F.failed?Z("payment_method",{reason:"redirect_failed"}):ue({waitFirst:!0})}let J=W.card?await cr(g,I,r,n):null;if(!u)return;T(E),J&&(f(J),L(new ie.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(I){if(!u)return;let W=ae(I);ee.current=!0,P(W),G(()=>M.current.onError?.(W))}})(),()=>{u=!1,g.destroy()}},[o,n,F,Z,q,r,a,ue]),(0,s.useEffect)(()=>{if(!S)return;_.current=!1;let u=S.on("submitting",()=>{_.current=!0,x({status:"processing",wording:"card",message:null})}),g=S.on("complete",E=>{q("card",E.paymentMethod)}),I=S.on("decline",E=>{Z("card",{...E.declineReason?{reason:E.declineReason}:{},...E.message?{message:E.message}:{}})}),W=S.on("challenge_dismissed",()=>{x(null)});return()=>{u(),g(),I(),W()}},[S,Z,q]);let ce=(0,s.useMemo)(()=>({onSubmitting:()=>{_.current=!0,x({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{ue({waitFirst:!1})},onDeclined:u=>Z("payment_method",u),onFailed:(u,g)=>{te("payment_method",ae(u,g))},onValidation:u=>{G(()=>M.current.onValidation?.(u))},onAbandoned:()=>{_.current=!1,x(null)}}),[Z,te,ue]),Le=Y?(0,C.jsx)(He,{status:Y.status,errorMessage:Y.message,...lt(Y.wording),successNote:null,...Be?{theme:Be}:{}}):null;if(v)return(0,C.jsx)("div",{role:"alert",children:v.message});if(!m||D)return(0,C.jsxs)(C.Fragment,{children:[Le,m?null:c]});let{advertisement:$,currency:Oe,customer:Ft}=m,Ie=(0,k.resolveBillingApiUrl)(o),Ve=a===void 0?{}:{telemetry:a};return(0,C.jsxs)(C.Fragment,{children:[Le,$.card&&S&&O?.html?(0,C.jsx)("div",{"data-flopay-payment-method":"card",children:(0,C.jsx)($e,{capture:S,html:O.html,messageToken:O.messageToken,expectedOrigin:O.expectedOrigin,theme:Rt,containerStyle:_t,onReady:()=>{G(()=>M.current.onReady?.())},onValidation:u=>{G(()=>M.current.onValidation?.(u))},onError:u=>{u&&te("card",ae(new Error(u),{code:"card_setup_widget_failed",retryable:!0}))}})}):null,$.stripe?.methods.map(u=>(0,C.jsx)("div",{"data-flopay-payment-method":u,children:(0,C.jsx)(ge,{onFailed:ce.onFailed,children:(0,C.jsx)(s.Suspense,{fallback:null,children:(0,C.jsx)(e,{method:u,category:at(u),publishableKey:$.stripe?.publishableKey??"",currency:Oe,sessionId:r,nonce:n,billingApiUrl:Ie,...Ve,...N?{appearance:N.appearance}:{},...ce})})})},u)),$.paypal?(0,C.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,C.jsx)(ge,{onFailed:ce.onFailed,children:(0,C.jsx)(s.Suspense,{fallback:null,children:(0,C.jsx)(t,{clientId:$.paypal.clientId,...$.paypal.environment?{environment:$.paypal.environment}:{},currency:Oe,sessionId:r,nonce:n,billingApiUrl:Ie,customer:Ft,...Ve,...ce})})})}):null]})}var kt=require("react/jsx-runtime"),kr={StripeSetupMethod:(0,Te.lazy)(()=>Promise.resolve().then(()=>(St(),ht)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,Te.lazy)(()=>Promise.resolve().then(()=>(wt(),Ct)).then(e=>({default:e.PayPalSetupMethod})))};function Et(e){return(0,kt.jsx)(ct,{...e,branches:kr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
6
+ `})]})})}var L=require("react");var Se=require("react"),tt=typeof window>"u"?Se.useEffect:Se.useLayoutEffect;var nt=require("react/jsx-runtime"),Ae=new WeakSet;function rt({capture:e,html:t,messageToken:r,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:s,onReady:i,onError:c,onValidation:d}){let p=(0,L.useRef)(null),h=(0,L.useRef)(i),S=(0,L.useRef)(c),x=(0,L.useRef)(d);h.current=i,S.current=c,x.current=d;let E=(0,L.useRef)(o);E.current=o;let F=(0,L.useRef)(null),y=a??void 0,B=(0,L.useRef)(y);B.current=y;let D=(0,L.useRef)(void 0);return(0,L.useEffect)(()=>{let M=p.current;if(!M)return;let b=!0,O=!1,I=()=>{!b||O||(O=!0,h.current?.())},m=e.on("ready",()=>{I()}),w=e.on("error",W=>{S.current?.(W.message??"There was a problem loading the secure card form.")}),C=e.on("validation",W=>{x.current?.(W.message??null)}),j=B.current??(Ae.has(e)?null:void 0),T={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...E.current?{theme:E.current}:{},...j===void 0?{}:{submitLabel:j}};return F.current=E.current??null,D.current=B.current,B.current!==void 0&&Ae.add(e),e.mount(M,T).then(()=>{I()}).catch(W=>{b&&S.current?.(W instanceof Error?W.message:"Failed to load the secure card form.")}),()=>{b=!1,m(),w(),C(),e.unmount()}},[e,t,r,n]),tt(()=>{let M=p.current;M&&Ze(M,s)},[s]),(0,L.useEffect)(()=>{o!==void 0&&(o===null&&F.current===null||(F.current=o,e.applyTheme?.(o)))},[e,o]),(0,L.useEffect)(()=>{y!==D.current&&(D.current=y,y!==void 0&&Ae.add(e),e.setSubmitLabel?.(y??null))},[e,y]),(0,nt.jsx)("div",{ref:p,"data-testid":"flopay-vault-card-fields"})}var at=/^#([0-9a-f]{6})$/i,Jt=/^#([0-9a-f]{3})$/i,st=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,it=/^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,Qt=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,er=/^(-?\d+(?:\.\d+)?)(?:px)?$/,tr=/^(-?\d+(?:\.\d+)?)em$/,rr=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,nr=/^[a-z][a-z0-9 -]{0,31}$/i,or=new Set(["none","uppercase","lowercase","capitalize"]);function lt(e){if(typeof e!="string")return null;let t=e.trim(),r=at.exec(t);if(r){let p=Number.parseInt(r[1],16);return{r:p>>16&255,g:p>>8&255,b:p&255,a:null}}let n=Jt.exec(t);if(n){let[p,h,S]=n[1].split("").map(x=>Number.parseInt(x+x,16));return{r:p,g:h,b:S,a:null}}let o=st.exec(t),a=o?null:it.exec(t),s=o??a;if(!s)return null;let i=Number(s[1]),c=Number(s[2]),d=Number(s[3]);return i>255||c>255||d>255?null:{r:i,g:c,b:d,a:a?Number(a[4]):null}}function ut({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 se(e){if(typeof e!="string")return;let t=e.trim();if(at.test(t)||st.test(t))return t;let r=it.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=lt(t);return n?ut(n):void 0}function be(e,t=.12){let r=lt(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return ut({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function ie(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 X(e,t,r){if(typeof e!="number"&&typeof e!="string")return;let n=er.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=tr.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function sr(e){let t=ie(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=ie(o," "),s=se(a[0]);if(!s)return;let i=n/(t.length-1)*100,c=a[1]===void 0?i:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),d=r[r.length-1]?.position??-1;if(!Number.isFinite(c)||c<0||c>100||c<d)return;r.push({color:s,position:c})}return{type:"linearGradient",angle:0,stops:r}}function ir(e){if(typeof e!="string")return;let t=e.trim(),r=se(t);if(r)return{type:"solid",color:r};let n=Qt.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=sr(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function lr(e){return e.type==="solid"?{type:"solid",color:be(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:be(t.color)}))}}function ur(e){let t=!1,r,n=[];for(let c of ie(e," ")){if(c.toLowerCase()==="inset"){t=!0;continue}let d=se(c);if(d){r=d;continue}let p=X(c,-128,128);if(p===void 0)return;n.push(p)}if(!r||n.length<2||n.length>4)return;let[o,a,s=0,i=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||s>128||Math.abs(i)>32))return{color:r,inset:t,offsetX:o,offsetY:a,blur:s,spread:i}}function cr(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=ie(t,",").map(ur);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function ot(e){if(typeof e!="string")return;let t=ie(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>nr.test(r)).slice(0,4);return t.length>0?t:void 0}function dr(e){let t=typeof e=="string"?e.trim().split(/\s+/):[e],r=X(t[0],0,64),n=X(t[1]??t[0],0,64);if(!(r===void 0||n===void 0))return{paddingBlock:r,paddingInline:n}}function pr(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 ct({appearance:e,buttonsStyles:t,fontFamily:r}){let n=t.submitButton;if(!n)return;let o=e?.variables,a=ir(n.background??n.backgroundColor),s=se(o?.colorPrimaryHover),i=s?{type:"solid",color:s}:a&&lr(a),c={fontFamilies:ot(n.fontFamily)??ot(r),fontSize:X(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:pr(n.fontWeight)??600,letterSpacing:ar(n.letterSpacing,-.1,.5)??.01,lineHeight:X(n.lineHeight,.8,2)??1,textTransform:or.has(String(n.textTransform))?n.textTransform:"uppercase"},d=dr(n.padding),p=cr(n.boxShadow),h=X(n.borderRadius,0,9999),S=typeof n.backdropFilter=="string"?X(rr.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:se(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...i?{hoverBackground:i}:{},typography:c,...d?{spacing:d}:{},...p?{shadow:p}:{},...h===void 0?{}:{borderRadius:h},disabledOpacity:e?.theme==="night"?.8:.6,...S===void 0?{}:{backdropBlur:S}}}function fr(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)?be(n,t):e}function mr(e){if(typeof e=="number"||typeof e=="string")return e}function dt({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",i=r==="buttons",c=t.nameInput,d=o(c?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",p=ct({appearance:e,buttonsStyles:t,fontFamily:d});return{primaryColor:s,primaryHoverColor:o(n?.colorPrimaryHover)??fr(s,.12),inputBackgroundColor:o(t.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(t.cardInputColor)??o(c?.color)??o(n?.colorText)??"#262833",borderColor:o(t.cardInputBorder)??(i?"#e5e7eb":"#A4A4FF"),placeholderColor:o(t.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:d,fontSize:o(t.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(mr(c?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...p?{submitButton:p}:{}}}var Te=require("react/jsx-runtime"),le=class extends te.FloPayError{constructor(t,r,n){super(t,r,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function re(e,t={}){let r=e instanceof te.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 le(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 De=require("react");var ue=require("@flopay/js/card-setup"),_=require("@flopay/shared"),l=$t(require("react"),1);var ft=require("@flopay/shared"),yr=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),gr=new Set(["wallet","apm"]);function ne(e){return typeof e=="string"&&e.trim().length>0}function hr(e){if(typeof e!="object"||e===null)return!1;let t=e;return ne(t.family)&&ne(t.paymentMethodType)}function Sr(e){let r=e.raw?.data?.currency;return ne(r)?r.trim().toUpperCase():null}function mt(e){let t=Sr(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(!hr(a)||o.has(a.paymentMethodType))continue;let{family:s,paymentMethodType:i,providerType:c,publishableKey:d}=a;if(s==="card"){if(i!=="card")continue;n.card=!0}else if(gr.has(s)){if(c!=="stripe"||i==="card"||!ne(d))continue;if(t===null){n.skippedForMissingCurrency.includes(i)||n.skippedForMissingCurrency.push(i);continue}n.stripe.push({method:i,publishableKey:d,currency:t})}else if(s==="paypal"){if(i!==ft.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE||c!=="paypal"||!ne(d))continue;n.paypal={clientId:d,...ne(a.environment)?{environment:a.environment}:{}}}else continue;o.add(i)}return n.paypal&&(n.stripe=n.stripe.filter(a=>a.method!=="paypal")),n}function xe(e){return[...e.card?["card"]:[],...e.stripe.map(t=>t.method),...e.paypal?["paypal"]:[]]}function yt(e){return xe(e).length>0}function gt(e){return yr.has(e)?"wallet":"apm"}var br=["setup_intent","setup_intent_client_secret","redirect_status"];function ht(){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 St(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of br)e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0);t&&window.history.replaceState(window.history.state,"",e.toString())}function bt(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"),Cr=15,vr=2e3;function wr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Be(e){return new Promise(t=>setTimeout(t,e))}async function Er(e,t,r){if(!t.trim())throw new _.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new _.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,_.isCardSetupCheckoutSession)(o))throw new _.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=mt(n);if(!yt(a)){let{skippedForMissingCurrency:s}=a,i=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 _.FloPayError(i,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:o,advertisement:a}}async function kr(e,t,r,n){let o=t.vault??null;if(o?.html?.trim()||(o=await e.getVaultCapture(r,n)),!o.html?.trim())throw new _.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var Ce=class extends l.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 Ct({branches:{StripeSetupMethod:e,PayPalSetupMethod:t},sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,theme:s="modern-light",containerStyle:i,loading:c=null,onReady:d,onComplete:p,onDecline:h,onCancel:S,onValidation:x,onError:E}){let[F]=(0,l.useState)(ht),[y,B]=(0,l.useState)(null),[D,M]=(0,l.useState)(!1),[b,O]=(0,l.useState)(null),[I,m]=(0,l.useState)(null),[w,C]=(0,l.useState)(null),[j,T]=(0,l.useState)(null),[W,Ne]=(0,l.useState)(()=>new Set),de=(0,l.useRef)(W),We=(0,l.useRef)(null);We.current=y;let Y=(0,l.useRef)(!1),Re=(0,l.useRef)(!1),oe=(0,l.useRef)(!1),_e=(0,l.useRef)(!1),Me=(0,l.useRef)(0),pe=(0,l.useRef)(0),Z=(0,l.useRef)(!1),N=(0,l.useMemo)(()=>typeof s=="object"?void 0:(0,_.resolveTheme)(s),[s]),Vt=(0,l.useMemo)(()=>typeof s=="object"?s:N?dt({appearance:N.appearance,buttonsStyles:N.buttonsLayout,layout:"default"}):null,[N,s]),Dt=(0,l.useMemo)(()=>qe(N?.buttonsLayout.cardFormContainer,i),[N,i]),ze=(0,l.useMemo)(()=>N?Qe(N):void 0,[N]),A=(0,l.useRef)({sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:d,onComplete:p,onDecline:h,onCancel:S,onValidation:x,onError:E});A.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:d,onComplete:p,onDecline:h,onCancel:S,onValidation:x,onError:E},(0,l.useEffect)(()=>{Z.current=!0;let u=Me.current+1;return Me.current=u,()=>{Z.current=!1,pe.current+=1,queueMicrotask(()=>{Me.current===u&&(oe.current||_e.current||(_e.current=!0,H(()=>{A.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let J=(0,l.useCallback)((u,f)=>{oe.current=!0,Y.current=!1,T({status:"success",wording:u,message:null}),(async()=>(await Be(600),!Re.current&&(Re.current=!0,H(()=>{A.current.onComplete?.({status:"succeeded",sessionId:A.current.sessionId,...f?{paymentMethod:f}:{}})}),Z.current&&T(null))))()},[]),Q=(0,l.useCallback)((u,f)=>{oe.current=!0,Y.current=!1,T({status:"error",wording:u,message:f.message??null}),H(()=>{A.current.onDecline?.({status:"declined",sessionId:A.current.sessionId,...f.reason?{reason:f.reason}:{},...f.message?{message:f.message}:{}})}),(async()=>(await Be(400),Z.current&&T(null)))()},[]),ee=(0,l.useCallback)((u,f)=>{Y.current?(Y.current=!1,T({status:"error",wording:u,message:f.message}),setTimeout(()=>{Z.current&&T(null)},400)):T(null),H(()=>A.current.onError?.(f))},[]),fe=(0,l.useCallback)(async u=>{let f=pe.current+1;pe.current=f;let k=()=>!Z.current||f!==pe.current;Y.current=!0,T({status:"processing",wording:"payment_method",message:null});let R=new ue.PaymentAPI((0,_.resolveBillingApiUrl)(A.current.billingApiUrl),{telemetry:A.current.telemetry});try{for(let g=0;g<Cr;g+=1){if((g>0||u.waitFirst)&&await Be(vr),k())return;let G=await R.getUnifiedCheckoutSession(A.current.sessionId,A.current.nonce);if(k())return;let K=G.data.session?.status;if(K==="complete"){M(!0),J("payment_method");return}if(K==="expired")throw new _.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new _.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(g){if(k())return;let G=g instanceof _.FloPayError&&g.code==="payment_method_setup_unverified";ee("payment_method",re(g,G?{retryable:!0}:{}))}finally{R.destroy()}},[ee,J]);(0,l.useEffect)(()=>{let u=!0,f=new ue.PaymentAPI((0,_.resolveBillingApiUrl)(o),{telemetry:a});B(null),M(!1),O(null),m(null),C(null);let k=new Set;return de.current=k,Ne(k),oe.current=!1,_e.current=!1,Re.current=!1,(async()=>{try{let{session:R,advertisement:g}=await Er(f,r,n);if(!u)return;let G={advertisement:g,customer:wr(R)};if(F){if(St(),R.status==="complete"){M(!0),B(G),J("payment_method");return}F.failed?Q("payment_method",{reason:"redirect_failed"}):fe({waitFirst:!0})}let K=g.card?await kr(f,R,r,n):null;if(!u)return;B(G),K&&(m(K),O(new ue.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(R){if(!u)return;let g=re(R);oe.current=!0,C(g),H(()=>A.current.onError?.(g))}})(),()=>{u=!1,f.destroy()}},[o,n,F,Q,J,r,a,fe]),(0,l.useEffect)(()=>{if(!b)return;Y.current=!1;let u=b.on("submitting",()=>{Y.current=!0,T({status:"processing",wording:"card",message:null})}),f=b.on("complete",g=>{J("card",g.paymentMethod)}),k=b.on("decline",g=>{Q("card",{...g.declineReason?{reason:g.declineReason}:{},...g.message?{message:g.message}:{}})}),R=b.on("challenge_dismissed",()=>{T(null)});return()=>{u(),f(),k(),R()}},[b,Q,J]);let Ue=(0,l.useCallback)((u,f,k)=>{if(k.retryable){ee("payment_method",re(f,k));return}if(de.current.has(u))return;let R=new Set(de.current);R.add(u),de.current=R,Ne(R);let g=We.current?.advertisement,G=g?xe(g).some(K=>!R.has(K)):!1;ee("payment_method",re(f,{code:k.code,retryable:G}))},[ee]),Ye=(0,l.useMemo)(()=>({onSubmitting:()=>{Y.current=!0,T({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{fe({waitFirst:!1})},onDeclined:u=>Q("payment_method",u),onValidation:u=>{H(()=>A.current.onValidation?.(u))},onAbandoned:()=>{Y.current=!1,T(null)}}),[Q,fe]),He=(0,l.useRef)(Ue);He.current=Ue;let Ge=(0,l.useRef)(new Map),me=u=>{let f=Ge.current.get(u);if(f)return f;let k=(R,g)=>He.current(u,R,g);return Ge.current.set(u,k),k},$e=j?(0,v.jsx)(et,{status:j.status,errorMessage:j.message,...bt(j.wording),successNote:null,...ze?{theme:ze}:{}}):null;if(w)return(0,v.jsx)("div",{role:"alert",children:w.message});if(!y||D)return(0,v.jsxs)(v.Fragment,{children:[$e,y?null:c]});let{advertisement:ae,customer:Nt}=y,je=(0,_.resolveBillingApiUrl)(o),Ke=a===void 0?{}:{telemetry:a},Wt=ae.stripe.filter(({method:u})=>!W.has(u)),ye=W.has("paypal")?null:ae.paypal;return(0,v.jsxs)(v.Fragment,{children:[$e,ae.card&&b&&I?.html?(0,v.jsx)("div",{"data-flopay-payment-method":"card",children:(0,v.jsx)(rt,{capture:b,html:I.html,messageToken:I.messageToken,expectedOrigin:I.expectedOrigin,theme:Vt,containerStyle:Dt,onReady:()=>{H(()=>A.current.onReady?.())},onValidation:u=>{H(()=>A.current.onValidation?.(u))},onError:u=>{u&&ee("card",re(new Error(u),{code:"card_setup_widget_failed",retryable:!0}))}})}):null,Wt.map(({method:u,publishableKey:f,currency:k})=>(0,v.jsx)("div",{"data-flopay-payment-method":u,children:(0,v.jsx)(Ce,{onFailed:me(u),children:(0,v.jsx)(l.Suspense,{fallback:null,children:(0,v.jsx)(e,{method:u,category:gt(u),publishableKey:f,currency:k,sessionId:r,nonce:n,billingApiUrl:je,...Ke,...N?{appearance:N.appearance}:{},...Ye,onFailed:me(u)})})})},u)),ye?(0,v.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,v.jsx)(Ce,{onFailed:me("paypal"),children:(0,v.jsx)(l.Suspense,{fallback:null,children:(0,v.jsx)(t,{clientId:ye.clientId,...ye.environment?{environment:ye.environment}:{},...ae.currency?{currency:ae.currency}:{},sessionId:r,nonce:n,billingApiUrl:je,customer:Nt,...Ke,...Ye,onFailed:me("paypal")})})})}):null]})}var It=require("react/jsx-runtime"),Wr={StripeSetupMethod:(0,De.lazy)(()=>Promise.resolve().then(()=>(Ft(),Mt)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,De.lazy)(()=>Promise.resolve().then(()=>(Lt(),xt)).then(e=>({default:e.PayPalSetupMethod})))};function Ot(e){return(0,It.jsx)(Ct,{...e,branches:Wr})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
@@ -1 +1 @@
1
- import{a as t}from"./chunk-R73QOXY5.mjs";import{j as a}from"./chunk-I4TPZWBS.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-NCEEB7GN.mjs").then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:o(()=>import("./payment-method-setup-paypal-MWDJVYVO.mjs").then(e=>({default:e.PayPalSetupMethod})))};function y(e){return P(t,{...e,branches:p})}export{a as FloPayCardSetupError,y as FloPayPaymentMethodSetup};
1
+ import{a as t}from"./chunk-JUUKXJQQ.mjs";import{j as a}from"./chunk-I4TPZWBS.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-NCEEB7GN.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};
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-YSFYLEHB.mjs";import"./chunk-M7R46EDF.mjs";export{a as PayPalSetupMethod};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/react",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -39,8 +39,8 @@
39
39
  "@paypal/paypal-js": "^10.0.0",
40
40
  "@stripe/react-stripe-js": "^6.6.0",
41
41
  "@stripe/stripe-js": "^9.8.0",
42
- "@flopay/js": "1.10.0",
43
- "@flopay/shared": "1.10.0"
42
+ "@flopay/shared": "1.10.2",
43
+ "@flopay/js": "1.10.2"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "react": ">=18.0.0",
@@ -1 +0,0 @@
1
- import{a as ce,b as pe,c as h,d as me,f as ye,i as fe,k as F}from"./chunk-I4TPZWBS.mjs";import{PaymentAPI as _e,PciVaultCardCapture as Ie}from"@flopay/js/card-setup";import{FloPayError as P,isCardSetupCheckoutSession as Le,resolveBillingApiUrl as H,resolveTheme as xe}from"@flopay/shared";import Ne,{Suspense as we,useCallback as L,useEffect as j,useMemo as T,useRef as g,useState as b}from"react";var Ve=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]);function Se(t){let i=t.data.stripe,r=Array.from(new Set(i?.enabledPaymentMethods??[])),a=t.data.paypal,o=a?.publishableKey?{clientId:a.publishableKey,...a.environment?{environment:String(a.environment)}:{}}:null,u=r.filter(f=>f!=="card"&&!(o&&f==="paypal"));return{card:r.includes("card"),stripe:i?.publishableKey&&u.length>0?{publishableKey:i.publishableKey,methods:u}:null,paypal:o}}function he(t){return t.card||t.stripe!==null||t.paypal!==null}function ve(t){return Ve.has(t)?"wallet":"apm"}var Oe=["setup_intent","setup_intent_client_secret","redirect_status"];function ge(){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 Pe(){if(typeof window>"u")return;let t=new URL(window.location.href),i=!1;for(let r of Oe)t.searchParams.has(r)&&(t.searchParams.delete(r),i=!0);i&&window.history.replaceState(window.history.state,"",t.toString())}function Ce(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 Ee,jsx as p,jsxs as Re}from"react/jsx-runtime";var Be=15,Ue=2e3;function Ye(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function q(t){return new Promise(i=>setTimeout(i,t))}async function Ge(t,i,r){if(!i.trim())throw new P("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new P("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let a=await t.getUnifiedCheckoutSession(i,r),o=a.data.session;if(!o||!Le(o))throw new P("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let u=Se(a);if(!he(u))throw new P("FloPay: this setup session advertises no payment method.","validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"});return{session:o,advertisement:u}}async function Ke(t,i,r,a){let o=i.vault??null;if(o?.html?.trim()||(o=await t.getVaultCapture(r,a)),!o.html?.trim())throw new P("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var x=class extends Ne.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 rt({branches:{StripeSetupMethod:t,PayPalSetupMethod:i},sessionId:r,nonce:a,billingApiUrl:o,telemetry:u,theme:f="modern-light",containerStyle:z,loading:Me=null,onReady:J,onComplete:Q,onDecline:X,onCancel:Z,onValidation:$,onError:ee}){let[N]=b(ge),[B,U]=b(null),[Ae,Y]=b(!1),[v,te]=b(null),[k,re]=b(null),[ne,ae]=b(null),[V,d]=b(null),S=g(!1),G=g(!1),M=g(!1),K=g(!1),W=g(0),O=g(0),_=g(!1),m=T(()=>typeof f=="object"?void 0:xe(f),[f]),Fe=T(()=>typeof f=="object"?f:m?fe({appearance:m.appearance,buttonsStyles:m.buttonsLayout,layout:"default"}):null,[m,f]),Te=T(()=>ce(m?.buttonsLayout.cardFormContainer,z),[m,z]),oe=T(()=>m?pe(m):void 0,[m]),l=g({sessionId:r,nonce:a,billingApiUrl:o,telemetry:u,onReady:J,onComplete:Q,onDecline:X,onCancel:Z,onValidation:$,onError:ee});l.current={sessionId:r,nonce:a,billingApiUrl:o,telemetry:u,onReady:J,onComplete:Q,onDecline:X,onCancel:Z,onValidation:$,onError:ee},j(()=>{_.current=!0;let e=W.current+1;return W.current=e,()=>{_.current=!1,O.current+=1,queueMicrotask(()=>{W.current===e&&(M.current||K.current||(K.current=!0,h(()=>{l.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let w=L((e,n)=>{M.current=!0,S.current=!1,d({status:"success",wording:e,message:null}),(async()=>(await q(600),!G.current&&(G.current=!0,h(()=>{l.current.onComplete?.({status:"succeeded",sessionId:l.current.sessionId,...n?{paymentMethod:n}:{}})}),_.current&&d(null))))()},[]),E=L((e,n)=>{M.current=!0,S.current=!1,d({status:"error",wording:e,message:n.message??null}),h(()=>{l.current.onDecline?.({status:"declined",sessionId:l.current.sessionId,...n.reason?{reason:n.reason}:{},...n.message?{message:n.message}:{}})}),(async()=>(await q(400),_.current&&d(null)))()},[]),A=L((e,n)=>{S.current?(S.current=!1,d({status:"error",wording:e,message:n.message}),setTimeout(()=>{_.current&&d(null)},400)):d(null),h(()=>l.current.onError?.(n))},[]),D=L(async e=>{let n=O.current+1;O.current=n;let c=()=>!_.current||n!==O.current;S.current=!0,d({status:"processing",wording:"payment_method",message:null});let y=new _e(H(l.current.billingApiUrl),{telemetry:l.current.telemetry});try{for(let s=0;s<Be;s+=1){if((s>0||e.waitFirst)&&await q(Ue),c())return;let R=await y.getUnifiedCheckoutSession(l.current.sessionId,l.current.nonce);if(c())return;let de=R.data.session?.status;if(de==="complete"){Y(!0),w("payment_method");return}if(de==="expired")throw new P("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new P("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(s){if(c())return;let R=s instanceof P&&s.code==="payment_method_setup_unverified";A("payment_method",F(s,R?{retryable:!0}:{}))}finally{y.destroy()}},[A,w]);j(()=>{let e=!0,n=new _e(H(o),{telemetry:u});return U(null),Y(!1),te(null),re(null),ae(null),M.current=!1,K.current=!1,G.current=!1,(async()=>{try{let{session:c,advertisement:y}=await Ge(n,r,a);if(!e)return;let s={advertisement:y,currency:c.currency,customer:Ye(c)};if(N){if(Pe(),c.status==="complete"){Y(!0),U(s),w("payment_method");return}N.failed?E("payment_method",{reason:"redirect_failed"}):D({waitFirst:!0})}let R=y.card?await Ke(n,c,r,a):null;if(!e)return;U(s),R&&(re(R),te(new Ie({sessionId:r,operation:"card_setup",telemetry:u})))}catch(c){if(!e)return;let y=F(c);M.current=!0,ae(y),h(()=>l.current.onError?.(y))}})(),()=>{e=!1,n.destroy()}},[o,a,N,E,w,r,u,D]),j(()=>{if(!v)return;S.current=!1;let e=v.on("submitting",()=>{S.current=!0,d({status:"processing",wording:"card",message:null})}),n=v.on("complete",s=>{w("card",s.paymentMethod)}),c=v.on("decline",s=>{E("card",{...s.declineReason?{reason:s.declineReason}:{},...s.message?{message:s.message}:{}})}),y=v.on("challenge_dismissed",()=>{d(null)});return()=>{e(),n(),c(),y()}},[v,E,w]);let I=T(()=>({onSubmitting:()=>{S.current=!0,d({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{D({waitFirst:!1})},onDeclined:e=>E("payment_method",e),onFailed:(e,n)=>{A("payment_method",F(e,n))},onValidation:e=>{h(()=>l.current.onValidation?.(e))},onAbandoned:()=>{S.current=!1,d(null)}}),[E,A,D]),se=V?p(me,{status:V.status,errorMessage:V.message,...Ce(V.wording),successNote:null,...oe?{theme:oe}:{}}):null;if(ne)return p("div",{role:"alert",children:ne.message});if(!B||Ae)return Re(Ee,{children:[se,B?null:Me]});let{advertisement:C,currency:ie,customer:ke}=B,le=H(o),ue=u===void 0?{}:{telemetry:u};return Re(Ee,{children:[se,C.card&&v&&k?.html?p("div",{"data-flopay-payment-method":"card",children:p(ye,{capture:v,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:Fe,containerStyle:Te,onReady:()=>{h(()=>l.current.onReady?.())},onValidation:e=>{h(()=>l.current.onValidation?.(e))},onError:e=>{e&&A("card",F(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null,C.stripe?.methods.map(e=>p("div",{"data-flopay-payment-method":e,children:p(x,{onFailed:I.onFailed,children:p(we,{fallback:null,children:p(t,{method:e,category:ve(e),publishableKey:C.stripe?.publishableKey??"",currency:ie,sessionId:r,nonce:a,billingApiUrl:le,...ue,...m?{appearance:m.appearance}:{},...I})})})},e)),C.paypal?p("div",{"data-flopay-payment-method":"paypal",children:p(x,{onFailed:I.onFailed,children:p(we,{fallback:null,children:p(i,{clientId:C.paypal.clientId,...C.paypal.environment?{environment:C.paypal.environment}:{},currency:ie,sessionId:r,nonce:a,billingApiUrl:le,customer:ke,...ue,...I})})})}):null]})}export{rt as a};
@@ -1 +0,0 @@
1
- import{a as T,g as A,i as R}from"./chunk-M7R46EDF.mjs";import{PaymentAPI as I}from"@flopay/js/card-setup";import{FloPayError as p,PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as B}from"@flopay/shared";import{loadScript as x}from"@paypal/paypal-js";import{useEffect as D,useRef as C,useState as O}from"react";import{jsx as F}from"react/jsx-runtime";function z({clientId:u,environment:o,currency:d,sessionId:s,nonce:i,billingApiUrl:y,telemetry:f,customer:{userId:m,email:P},onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b}){let w=C(null),t=C({onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b});t.current={onSubmitting:h,onConfirmed:_,onFailed:v,onAbandoned:b};let[l]=O(()=>R().inAppBrowser);return D(()=>{let a=!0,k,c=new I(y,{telemetry:f}),g={userId:m,email:P};return(async()=>{try{let n=await x({clientId:u,currency:d.toUpperCase(),components:"buttons",...o==="sandbox"||o==="production"?{environment:o}:{}}),M=w.current;if(!a||!M)return;if(!n?.Buttons)throw new p("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let E=n.Buttons({createVaultSetupToken:async()=>{t.current.onSubmitting();let e=await c.createSessionIntent(s,i,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:B,paymentMethodId:null,intentKind:"setup"});if(e.provider!=="paypal"||e.providerObjectType!=="setup_token")throw new p("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return e.providerObjectId},onApprove:async e=>{let r=e.vaultSetupToken;if(!r)throw new p("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let S=await c.processPayment(g.userId,{sessionId:s,nonce:i,paymentMethodCategory:"paypal",tokenizedData:{id:r,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:B},accountData:g});if(!S.ok)throw new p("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:S.status});a&&t.current.onConfirmed()},onCancel:()=>{a&&t.current.onAbandoned()},onError:e=>{if(!a)return;let{popupBlocked:r}=A(e,{inAppBrowser:l,handoffObserved:!1});t.current.onFailed(r?new Error(T("PayPal",!0,l)):e,{code:r?"popup_blocked":"paypal_setup_failed",retryable:!0})}});k=()=>E.close(),await E.render(M)}catch(n){if(!a)return;t.current.onFailed(n,{code:"paypal_unavailable",retryable:!0})}})(),()=>{a=!1,k?.().catch(()=>{}),c.destroy()}},[y,u,d,P,o,l,i,s,f,m]),F("div",{ref:w,"data-flopay-paypal-setup":""})}export{z as a};
@@ -1 +0,0 @@
1
- import{a}from"./chunk-U3PMJDD4.mjs";import"./chunk-M7R46EDF.mjs";export{a as PayPalSetupMethod};