@flopay/react 1.10.3 → 1.10.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/card-setup-entry.cjs +2 -2
- package/dist/card-setup-entry.mjs +1 -1
- package/dist/chunk-AZRGKPW7.mjs +6 -0
- package/dist/chunk-TGSZFVTH.mjs +1 -0
- package/dist/chunk-X3EOIUVN.mjs +22 -0
- package/dist/index.cjs +9 -9
- package/dist/index.mjs +6 -27
- package/dist/payment-method-setup-entry.cjs +23 -2
- package/dist/payment-method-setup-entry.mjs +1 -1
- package/dist/payment-method-setup-stripe-VJZMWIHC.mjs +1 -0
- package/package.json +3 -3
- package/dist/chunk-I4TPZWBS.mjs +0 -6
- package/dist/chunk-JUUKXJQQ.mjs +0 -1
- package/dist/chunk-OYOJA6FI.mjs +0 -1
- package/dist/payment-method-setup-stripe-NCEEB7GN.mjs +0 -1
|
@@ -1,6 +1,27 @@
|
|
|
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:`
|
|
1
|
+
"use strict";var pr=Object.create;var Ee=Object.defineProperty;var fr=Object.getOwnPropertyDescriptor;var mr=Object.getOwnPropertyNames;var yr=Object.getPrototypeOf,gr=Object.prototype.hasOwnProperty;var fe=(e,t)=>()=>(e&&(t=e(e=0)),t);var De=(e,t)=>{for(var r in t)Ee(e,r,{get:t[r],enumerable:!0})},it=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of mr(t))!gr.call(e,o)&&o!==r&&Ee(e,o,{get:()=>t[o],enumerable:!(n=fr(t,o))||n.enumerable});return e};var hr=(e,t,r)=>(r=e!=null?pr(yr(e)):{},it(t||!e||!e.__esModule?Ee(r,"default",{value:e,enumerable:!0}):r,e)),Sr=e=>it(Ee({},"__esModule",{value:!0}),e);function Ae(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 Lt(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 Pe(e){if(typeof e!="string")return;let t=e.trim();return/^[a-z0-9_.-]{1,64}$/i.test(t)?t:void 0}function Bt(e){if(typeof e!="object"||e===null)return;let t=e;return Pe(t.code)??Pe(t.type)??Pe(t.name)}function Qr(e){if(!(typeof e!="object"||e===null))return Pe(e.decline_code)}function He(e){return typeof e!="object"||e===null?!1:Pe(e.type)?.toLowerCase()==="card_error"||Qr(e)!==void 0}function en(e){let t=Lt(e)?.toLowerCase()??"",r=Bt(e)?.toLowerCase()??"";return Zr.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 tn(e){if(Bt(e)?.toLowerCase()==="paypal_init_timeout")return!0;let r=Lt(e)??"";return r.includes("No ack for postMessage init()")&&Jr.some(n=>r.includes(n))&&r.includes("10000ms")}function Le(e,t){if(He(e))return{errorCode:"PROVIDER_RUNTIME_FAILED",popupBlocked:!1,providerDeclined:!0,terminalReason:"provider_declined"};let n=en(e)||t.inAppBrowser&&!t.handoffObserved&&tn(e);return{errorCode:n?"POPUP_BLOCKED":"PROVIDER_RUNTIME_FAILED",popupBlocked:n,providerDeclined:!1,terminalReason:n?"popup_blocked":"provider_error"}}var Zr,Jr,We=fe(()=>{"use strict";Zr=new Set(["err_blocked_by_client","notallowederror","popup_blocked","popupblocked"]),Jr=["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 Ot(e,t,r=e.popupCapability){return e.inAppBrowser||r==="blocked"||t==="prefer_redirect"?"redirect":"popup"}var Ye=fe(()=>{"use strict"});var It,Dt=fe(()=>{"use strict";It={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 Nt(){return(0,x.jsx)("style",{children:rn})}function Ut(e,t){let r=e.availablePaymentMethods;return r&&t.some(n=>r[n])?"ready":"unavailable"}function Ht({state:e,placeholderTestId:t,borderRadius:r=8,children:n}){return e==="unavailable"||e==="load_error"?null:(0,x.jsxs)("div",{style:{position:"relative",minHeight:44},children:[(0,x.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,x.jsx)("div",{style:{minHeight:44,opacity:e==="ready"?1:0,transform:e==="ready"?"translateY(0)":"translateY(2px)",transition:"opacity 140ms ease-out, transform 140ms ease-out",pointerEvents:e==="ready"?"auto":"none"},children:n})]})}function Wt({method:e,themeId:t,submitting:r=!1,disabled:n=!1,highlighted:o=!1,hasNextStep:a=!1,onClick:s,backgroundColor:l,borderColor:d,textColor:p,borderRadius:f,fontFamily:S}){let g=(0,Z.resolveStripeMethodBrandVariant)(e,t),w=It[e],[C,k]=(0,Vt.useState)(!1),m=!!w&&!C,_=g?.backgroundColor??l??"#ffffff",D=g?.borderColor??d??"#d1d5db",M=g?.textColor??p??"#262833";return(0,x.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:nn,padding:"0 1rem",backgroundColor:_,color:M,border:`1px solid ${D}`,borderRadius:f??8,fontSize:"0.95rem",fontWeight:600,fontFamily:S,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,x.jsx)("span",{style:{margin:"0 auto"},children:`Connecting to ${(0,Z.getStripeMethodDisplayName)(e)}\u2026`}):(0,x.jsxs)(x.Fragment,{children:[(0,x.jsxs)("span",{style:{display:"inline-flex",alignItems:"center",gap:(0,Z.hasVendoredStripeMethodLogo)(e)?8:0},children:[m?(0,x.jsx)("img",{src:w,alt:"","aria-hidden":"true",onError:()=>k(!0),loading:"lazy",decoding:"async",width:30,height:20,style:{width:30,height:20,flexShrink:0,borderRadius:3,objectFit:"contain",display:"inline-flex"}}):null,!m&&g?.logoSvg?(0,x.jsx)("span",{"aria-hidden":"true",style:{width:30,height:20,flexShrink:0,display:"inline-flex",borderRadius:3,overflow:"hidden"},dangerouslySetInnerHTML:{__html:g.logoSvg}}):null,(0,x.jsx)("span",{children:(0,Z.getStripeMethodDisplayName)(e)})]}),a&&(0,x.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:M,strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{position:"absolute",right:"1rem",top:"50%",transform:"translateY(-50%)",flexShrink:0,opacity:.7},"aria-hidden":"true",children:(0,x.jsx)("path",{d:"M9 18l6-6-6-6"})})]})})}function Yt(e){let t=new Set(e.map(Z.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 Gt({testId:e,attributes:t,disabled:r,onClick:n,color:o,borderRadius:a,style:s,children:l}){return(0,x.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 Z,Vt,x,rn,nn,zt,$t,jt=fe(()=>{"use strict";Z=require("@flopay/shared"),Vt=require("react");Dt();x=require("react/jsx-runtime"),rn=`
|
|
2
|
+
.paypal-buttons { margin: 0 !important; vertical-align: top !important; }
|
|
3
|
+
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
4
|
+
@keyframes flopay-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }
|
|
5
|
+
@keyframes flopay-fade-in { 0% { opacity: 0; } 100% { opacity: 1; } }
|
|
6
|
+
@keyframes flopay-buttons-enter {
|
|
7
|
+
0% { opacity: 0; transform: translateX(-16px) scale(0.97); }
|
|
8
|
+
100% { opacity: 1; transform: translateX(0) scale(1); }
|
|
9
|
+
}
|
|
10
|
+
@keyframes flopay-buttons-exit {
|
|
11
|
+
0% { opacity: 1; transform: translateX(0) scale(1); }
|
|
12
|
+
100% { opacity: 0; transform: translateX(-16px) scale(0.97); }
|
|
13
|
+
}
|
|
14
|
+
@keyframes flopay-card-enter {
|
|
15
|
+
0% { opacity: 0; transform: translateX(16px) scale(0.97); }
|
|
16
|
+
100% { opacity: 1; transform: translateX(0) scale(1); }
|
|
17
|
+
}
|
|
18
|
+
@keyframes flopay-card-exit {
|
|
19
|
+
0% { opacity: 1; transform: translateX(0) scale(1); }
|
|
20
|
+
100% { opacity: 0; transform: translateX(16px) scale(0.97); }
|
|
21
|
+
}
|
|
22
|
+
`,nn=44;zt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},$t={type:"accordion",defaultCollapsed:!1,radios:"never"}});var Jt={};De(Jt,{StripeSetupMethod:()=>cn});function on(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 sn(e){return e?{theme:an[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function ln(e){return He(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Kt(e){return e==="paypal"?"PayPal":(0,Oe.getStripeMethodDisplayName)(e)}function un(){return typeof window>"u"?"":window.location.href}function cn(e){let{publishableKey:t,method:r,currency:n,appearance:o}=e,[a]=(0,I.useState)(()=>on(t)),s=(0,I.useMemo)(()=>{let l=sn(o);return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:Zt[r]?.types??[r],...l?{appearance:l}:{}}},[o,n,r]);return(0,B.jsx)(X.Elements,{stripe:a,options:s,children:(0,B.jsx)(pn,{...e})})}function pn({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:w,onUnavailable:C}){let k=(0,X.useStripe)(),m=(0,X.useElements)(),[_,D]=(0,I.useState)(!1),[M,b]=(0,I.useState)("loading"),[j,N]=(0,I.useState)(!1),[E,W]=(0,I.useState)(!1),$=(0,I.useRef)(!1),[U]=(0,I.useState)(()=>Be()),[A,Y]=(0,I.useState)(!1),te=(0,I.useCallback)((T,V)=>{if(Le(T,{inAppBrowser:U.inAppBrowser,handoffObserved:!1}).popupBlocked){Y(!0),g(new Error(Ae(Kt(e),!0,U.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}g(V.message===void 0?T:new Error(V.message),{code:V.code,retryable:!0})},[U.inAppBrowser,e,g]),K=(0,I.useCallback)(async()=>{if(!(!k||!m||$.current)){$.current=!0,D(!0);try{let T=await m.submit();if(T.error){w(T.error.message??null);return}p();let V=await new Xt.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 Oe.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let L=await k.confirmSetup({elements:m,clientSecret:V.clientSecret,confirmParams:{return_url:un()},redirect:"if_required"});if(L.error){ln(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(T){te(T,{code:"payment_method_setup_failed"})}finally{$.current=!1,D(!1)}}},[o,t,m,e,n,f,S,p,w,te,r,k,a]),re=Zt[e]?.wallet,G=re==="paypal"&&Ot(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)(Nt,{}),(0,B.jsx)(Ht,{state:M,borderRadius:ue,children:(0,B.jsx)(X.ExpressCheckoutElement,{options:{...zt,paymentMethods:Yt([e])},onReady:T=>{let V=Ut(T,[re]);b(V),V==="unavailable"&&C()},onLoadError:()=>{b("load_error"),C()},onConfirm:()=>{K()}})})]});let ne=Kt(e);return(0,B.jsxs)(B.Fragment,{children:[j?(0,B.jsx)(Wt,{method:e,themeId:l,hasNextStep:!0,highlighted:E,disabled:_,onClick:()=>W(T=>!T),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":!E,style:E?{display:"flex",flexDirection:"column"}:dn,children:[(0,B.jsx)(X.PaymentElement,{options:{layout:$t},onReady:()=>N(!0),onLoadError:()=>C(),onChange:T=>{T.complete&&w(null)}}),(0,B.jsx)(Gt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!k||!m||_||!E,onClick:()=>{K()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:_?"Saving\u2026":`Save ${ne}`})]})]})}var Xt,Oe,X,qt,I,B,Zt,ze,an,dn,Qt=fe(()=>{"use strict";Xt=require("@flopay/js/card-setup"),Oe=require("@flopay/shared"),X=require("@stripe/react-stripe-js"),qt=require("@stripe/stripe-js"),I=require("react");We();Ye();jt();B=require("react/jsx-runtime"),Zt={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;an={night:"night",flat:"flat"};dn={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var rr={};De(rr,{PayPalSetupMethod:()=>fn});function fn({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 w=(0,le.useRef)(null),C=(0,le.useRef)({onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g});C.current={onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g};let[k]=(0,le.useState)(()=>Be().inAppBrowser);return(0,le.useEffect)(()=>{let m=!0,_,D=new er.PaymentAPI(a,{telemetry:s}),M={userId:l,email:d};return(async()=>{try{let b=await(0,tr.loadScript)({clientId:e,...r?{currency:r.toUpperCase()}:{},components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),j=w.current;if(!m||!j)return;if(!b?.Buttons)throw new ee.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=b.Buttons({createVaultSetupToken:async()=>{C.current.onSubmitting();let E=await D.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(E.provider!=="paypal"||E.providerObjectType!=="setup_token")throw new ee.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return E.providerObjectId},onApprove:async E=>{let W=E.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&&C.current.onConfirmed()},onCancel:()=>{m&&C.current.onAbandoned()},onError:E=>{if(!m)return;let{popupBlocked:W}=Le(E,{inAppBrowser:k,handoffObserved:!1});C.current.onFailed(W?new Error(Ae("PayPal",!0,k)):E,{code:W?"popup_blocked":"paypal_setup_failed",retryable:!0})}});_=()=>N.close(),await N.render(j)}catch(b){if(!m)return;C.current.onFailed(b,{code:"paypal_unavailable",retryable:!0})}})(),()=>{m=!1,_?.().catch(()=>{}),D.destroy()}},[a,e,r,d,t,k,o,n,s,l]),(0,nr.jsx)("div",{ref:w,"data-flopay-paypal-setup":""})}var er,ee,tr,le,nr,or=fe(()=>{"use strict";er=require("@flopay/js/card-setup"),ee=require("@flopay/shared"),tr=require("@paypal/paypal-js"),le=require("react");We();Ye();nr=require("react/jsx-runtime")});var yn={};De(yn,{FloPayCardSetupError:()=>ve,FloPayPaymentMethodSetup:()=>ar});module.exports=Sr(yn);var kt=require("@flopay/js/card-setup"),me=require("@flopay/shared"),_e=require("react");function lt(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 br=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 vr(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return br.has(t.charAt(0).toLowerCase()+t.slice(1))}function Cr(e,t){return typeof t=="number"&&t!==0&&!vr(e)?`${t}px`:String(t).trim()}function ut(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]=Cr(r,n)}}}var dt={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ct(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?dt.dark:dt.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 P=require("react/jsx-runtime");var Pr={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function pt({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=Pr}){let d={fontSize:13,color:l.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)",...l.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:l.spinnerTrackColor,strokeWidth:"3"}),(0,P.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.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:l.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:d,children:s}),e==="error"&&t&&(0,P.jsx)("p",{style:d,children:t}),(0,P.jsx)("style",{children:`
|
|
2
23
|
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
24
|
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
25
|
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
26
|
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
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});
|
|
27
|
+
`})]})})}var H=require("react");var Re=require("react"),ft=typeof window>"u"?Re.useEffect:Re.useLayoutEffect;var ae=require("react/jsx-runtime"),Ve=new WeakSet;function mt({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),w=(0,H.useRef)(p);S.current=l,g.current=d,w.current=p;let C=(0,H.useRef)(o);C.current=o;let k=(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 b=!0,j=!1,N=()=>{!b||j||(j=!0,S.current?.())},E=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=>{w.current?.(Y.message??null)}),U=_.current??(Ve.has(e)?null:void 0),A={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...C.current?{theme:C.current}:{},...U===void 0?{}:{submitLabel:U}};return k.current=C.current??null,D.current=_.current,_.current!==void 0&&Ve.add(e),e.mount(M,A).then(()=>{N()}).catch(Y=>{b&&g.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{b=!1,E(),W(),$(),e.unmount()}},[e,t,r,n]),ft(()=>{let M=f.current;M&&ut(M,s)},[s]),(0,H.useEffect)(()=>{o!==void 0&&(o===null&&k.current===null||(k.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 yt({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 ht=/^#([0-9a-f]{6})$/i,wr=/^#([0-9a-f]{3})$/i,St=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,bt=/^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,kr=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Er=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Rr=/^(-?\d+(?:\.\d+)?)em$/,xr=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,_r=/^[a-z][a-z0-9 -]{0,31}$/i,Mr=new Set(["none","uppercase","lowercase","capitalize"]);function vt(e){if(typeof e!="string")return null;let t=e.trim(),r=ht.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=wr.exec(t);if(n){let[f,S,g]=n[1].split("").map(w=>Number.parseInt(w+w,16));return{r:f,g:S,b:g,a:null}}let o=St.exec(t),a=o?null:bt.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 Ct({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(ht.test(t)||St.test(t))return t;let r=bt.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=vt(t);return n?Ct(n):void 0}function xe(e,t=.12){let r=vt(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return Ct({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function be(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=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 Tr(e,t,r){if(typeof e!="string")return;let n=Rr.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Fr(e){let t=be(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=be(o," "),s=Se(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 Ar(e){if(typeof e!="string")return;let t=e.trim(),r=Se(t);if(r)return{type:"solid",color:r};let n=kr.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Fr(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Lr(e){return e.type==="solid"?{type:"solid",color:xe(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:xe(t.color)}))}}function Br(e){let t=!1,r,n=[];for(let d of be(e," ")){if(d.toLowerCase()==="inset"){t=!0;continue}let p=Se(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 Or(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=be(t,",").map(Br);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function gt(e){if(typeof e!="string")return;let t=be(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>_r.test(r)).slice(0,4);return t.length>0?t:void 0}function Ir(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 Dr(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 Pt({appearance:e,buttonsStyles:t,fontFamily:r}){let n=t.submitButton;if(!n)return;let o=e?.variables,a=Ar(n.background??n.backgroundColor),s=Se(o?.colorPrimaryHover),l=s?{type:"solid",color:s}:a&&Lr(a),d={fontFamilies:gt(n.fontFamily)??gt(r),fontSize:se(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:Dr(n.fontWeight)??600,letterSpacing:Tr(n.letterSpacing,-.1,.5)??.01,lineHeight:se(n.lineHeight,.8,2)??1,textTransform:Mr.has(String(n.textTransform))?n.textTransform:"uppercase"},p=Ir(n.padding),f=Or(n.boxShadow),S=se(n.borderRadius,0,9999),g=typeof n.backdropFilter=="string"?se(xr.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:Se(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 Vr(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)?xe(n,t):e}function Nr(e){if(typeof e=="number"||typeof e=="string")return e}function wt({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=Pt({appearance:e,buttonsStyles:t,fontFamily:p});return{primaryColor:s,primaryHoverColor:o(n?.colorPrimaryHover)??Vr(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(Nr(d?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...f?{submitButton:f}:{}}}var Ne=require("react/jsx-runtime"),ve=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 ve(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 Ce=require("@flopay/js/card-setup"),F=require("@flopay/shared"),u=hr(require("react"),1);var Et=require("@flopay/shared"),Ur=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),Hr=new Set(["wallet","apm"]);function ye(e){return typeof e=="string"&&e.trim().length>0}function Wr(e){if(typeof e!="object"||e===null)return!1;let t=e;return ye(t.family)&&ye(t.paymentMethodType)}function Yr(e){let r=e.raw?.data?.currency;return ye(r)?r.trim().toUpperCase():null}function Rt(e){let t=Yr(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(!Wr(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(Hr.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!==Et.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 Me(e){return[...e.card?["card"]:[],...e.stripe.map(t=>t.method),...e.paypal?["paypal"]:[]]}function xt(e){return Me(e).length>0}function Te(e){return Ur.has(e)?"wallet":"apm"}var zr=["setup_intent","setup_intent_client_secret","redirect_status"];function _t(){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 Mt(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of zr)e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0);t&&window.history.replaceState(window.history.state,"",e.toString())}function Tt(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"),Gr=15,jr=2e3;function Kr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(t=>setTimeout(t,e))}async function Xr(e,t,r){if(!t.trim())throw new F.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new F.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,F.isCardSetupCheckoutSession)(o))throw new F.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=Rt(n);if(!xt(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 F.FloPayError(l,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:o,advertisement:a}}async function qr(e,t,r,n){let o=t.vault??null;if(o?.html?.trim()||(o=await e.getVaultCapture(r,n)),!o.html?.trim())throw new F.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var Fe=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 At({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:w,onError:C}){let[k]=(0,u.useState)(_t),[m,_]=(0,u.useState)(null),[D,M]=(0,u.useState)(!1),[b,j]=(0,u.useState)(null),[N,E]=(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),T=(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,F.resolveTheme)(s),[s]),ir=(0,u.useMemo)(()=>typeof s=="object"?s:z?wt({appearance:z.appearance,buttonsStyles:z.buttonsLayout,layout:"default"}):null,[z,s]),lr=(0,u.useMemo)(()=>lt(z?.buttonsLayout.cardFormContainer,l),[z,l]),Ge=(0,u.useMemo)(()=>z?ct(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:w,onError:C});O.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:w,onError:C},(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||T.current||(T.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))},[]),we=(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 R=new Ce.PaymentAPI((0,F.resolveBillingApiUrl)(O.current.billingApiUrl),{telemetry:O.current.telemetry});try{for(let y=0;y<Gr;y+=1){if((y>0||i.waitFirst)&&await Ue(jr),h())return;let Q=await R.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 F.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new F.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 F.FloPayError&&y.code==="payment_method_setup_unverified";J("payment_method",ie(y,Q?{retryable:!0}:{}))}finally{R.destroy()}},[J,ce]);(0,u.useEffect)(()=>{let i=!0,c=new Ce.PaymentAPI((0,F.resolveBillingApiUrl)(o),{telemetry:a});_(null),M(!1),j(null),E(null),$(null);let h=new Set;return K.current=h,te(h),ne.current=!1,T.current=!1,ue.current=!1,(async()=>{try{let{session:R,advertisement:y}=await Xr(c,r,n);if(!i)return;let Q={advertisement:y,customer:Kr(R)};if(k){if(Mt(),R.status==="complete"){M(!0),_(Q),ce("payment_method");return}k.failed?pe("payment_method",{reason:"redirect_failed"}):we({waitFirst:!0})}let oe=y.card?await qr(c,R,r,n):null;if(!i)return;_(Q),oe&&(E(oe),j(new Ce.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(R){if(!i)return;let y=ie(R);ne.current=!0,$(y),q(()=>O.current.onError?.(y))}})(),()=>{i=!1,c.destroy()}},[o,n,k,pe,ce,r,a,we]),(0,u.useEffect)(()=>{if(!b)return;G.current=!1;let i=b.on("submitting",()=>{G.current=!0,A({status:"processing",wording:"card",message:null})}),c=b.on("complete",y=>{ce("card",y.paymentMethod)}),h=b.on("decline",y=>{pe("card",{...y.declineReason?{reason:y.declineReason}:{},...y.message?{message:y.message}:{}})}),R=b.on("challenge_dismissed",()=>{A(null)});return()=>{i(),c(),h(),R()}},[b,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 R=new Set(K.current);R.add(i),K.current=R,te(R);let y=re.current?.advertisement,Q=y?Me(y).some(oe=>!R.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:()=>{we({waitFirst:!1})},onDeclined:i=>pe("payment_method",i),onValidation:i=>{q(()=>O.current.onValidation?.(i))},onAbandoned:()=>{G.current=!1,A(null)}}),[pe,we]),Xe=(0,u.useRef)(je);Xe.current=je;let qe=(0,u.useRef)(new Map),ke=i=>{let c=qe.current.get(i);if(c)return c;let h=(R,y)=>Xe.current(i,R,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&&Me(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,v.jsx)(pt,{status:U.status,errorMessage:U.message,...Tt(U.wording),successNote:null,...Ge?{theme:Ge}:{}}):null;if(W)return(0,v.jsx)("div",{role:"alert",children:W.message});if(!m||D)return(0,v.jsxs)(v.Fragment,{children:[tt,m?null:d]});let{advertisement:ge,customer:ur}=m,rt=(0,F.resolveBillingApiUrl)(o),nt=a===void 0?{}:{telemetry:a},Ie=ge.stripe.filter(({method:i})=>!Y.has(i)),he=Y.has("paypal")?null:ge.paypal,ot=!!(ge.card&&b&&N?.html),at=({method:i,publishableKey:c,currency:h})=>(0,v.jsx)("div",{"data-flopay-payment-method":i,style:{display:"contents"},children:(0,v.jsx)(Fe,{onFailed:ke(i),children:(0,v.jsx)(u.Suspense,{fallback:null,children:(0,v.jsx)(e,{method:i,category:Te(i),publishableKey:c,currency:h,sessionId:r,nonce:n,billingApiUrl:rt,...nt,...z?{appearance:z.appearance,buttonsLayout:z.buttonsLayout}:{},...typeof s=="string"?{themeId:s}:{},...Ke,onFailed:ke(i),onUnavailable:et(i)})})})},i),dr=Ie.filter(({method:i})=>Te(i)==="wallet"),cr=Ie.filter(({method:i})=>Te(i)!=="wallet"),st=Ie.length>0||he!==null;return(0,v.jsxs)(v.Fragment,{children:[tt,st?(0,v.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[dr.map(at),he?(0,v.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,v.jsx)(Fe,{onFailed:ke("paypal"),children:(0,v.jsx)(u.Suspense,{fallback:null,children:(0,v.jsx)(t,{clientId:he.clientId,...he.environment?{environment:he.environment}:{},...ge.currency?{currency:ge.currency}:{},sessionId:r,nonce:n,billingApiUrl:rt,customer:ur,...nt,...Ke,onFailed:ke("paypal"),onUnavailable:et("paypal")})})})}):null,cr.map(at)]}):null,ot&&st?(0,v.jsx)(yt,{label:"or add a card"}):null,ot&&b&&N?.html?(0,v.jsx)("div",{"data-flopay-payment-method":"card",children:(0,v.jsx)(mt,{capture:b,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,theme:ir,containerStyle:lr,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 sr=require("react/jsx-runtime"),mn={StripeSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(Qt(),Jt)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(or(),rr)).then(e=>({default:e.PayPalSetupMethod})))};function ar(e){return(0,sr.jsx)(At,{...e,branches:mn})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as t}from"./chunk-
|
|
1
|
+
import{a as t}from"./chunk-TGSZFVTH.mjs";import{k as a}from"./chunk-AZRGKPW7.mjs";import{lazy as o}from"react";import{jsx as P}from"react/jsx-runtime";var p={StripeSetupMethod:o(()=>import("./payment-method-setup-stripe-VJZMWIHC.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{k as a}from"./chunk-X3EOIUVN.mjs";import"./chunk-M7R46EDF.mjs";export{a as StripeSetupMethod};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopay/react",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.4",
|
|
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.
|
|
43
|
-
"@flopay/shared": "1.10.
|
|
42
|
+
"@flopay/js": "1.10.4",
|
|
43
|
+
"@flopay/shared": "1.10.4"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"react": ">=18.0.0",
|
package/dist/chunk-I4TPZWBS.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{useEffect as Q,useRef as F}from"react";function ue(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 Ee(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Fe.has(r.charAt(0).toLowerCase()+r.slice(1))}function Te(e,r){return typeof r=="number"&&r!==0&&!Ee(e)?`${r}px`:String(r).trim()}function le(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]=Te(t,n)}}}import{useEffect as Pe,useLayoutEffect as Ve}from"react";var ce=typeof window>"u"?Pe:Ve;import{jsx as Ae}from"react/jsx-runtime";var ee=new WeakSet;function de({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:i,containerStyle:a,onReady:u,onError:s,onValidation:c}){let l=F(null),f=F(u),y=F(s),p=F(c);f.current=u,y.current=s,p.current=c;let T=F(o);T.current=o;let k=F(null),C=i??void 0,P=F(C);P.current=C;let L=F(void 0);return Q(()=>{let w=l.current;if(!w)return;let m=!0,G=!1,B=()=>{!m||G||(G=!0,f.current?.())},R=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??(ee.has(e)?null:void 0),j={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&&ee.add(e),e.mount(w,j).then(()=>{B()}).catch(S=>{m&&y.current?.(S instanceof Error?S.message:"Failed to load the secure card form.")}),()=>{m=!1,R(),_(),b(),e.unmount()}},[e,r,t,n]),ce(()=>{let w=l.current;w&&le(w,a)},[a]),Q(()=>{o!==void 0&&(o===null&&k.current===null||(k.current=o,e.applyTheme?.(o)))},[e,o]),Q(()=>{C!==L.current&&(L.current=C,C!==void 0&&ee.add(e),e.setSubmitLabel?.(C??null))},[e,C]),Ae("div",{ref:l,"data-testid":"flopay-vault-card-fields"})}import{PaymentAPI as Ze,PciVaultCardCapture as Je}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as Qe,resolveBillingApiUrl as er,resolveTheme as rr}from"@flopay/shared";import{useEffect as re,useMemo as U,useRef as h,useState as $}from"react";var fe={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function pe(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?fe.dark:fe.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 E(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 Le={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function me({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=Le}){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 ye=/^#([0-9a-f]{6})$/i,Be=/^#([0-9a-f]{3})$/i,be=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,he=/^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,Oe=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Ie=/^(-?\d+(?:\.\d+)?)(?:px)?$/,Me=/^(-?\d+(?:\.\d+)?)em$/,_e=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Ne=/^[a-z][a-z0-9 -]{0,31}$/i,De=new Set(["none","uppercase","lowercase","capitalize"]);function Ce(e){if(typeof e!="string")return null;let r=e.trim(),t=ye.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=Be.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=be.exec(r),i=o?null:he.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 Se({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(ye.test(r)||be.test(r))return r;let t=he.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Ce(r);return n?Se(n):void 0}function Y(e,r=.12){let t=Ce(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return Se({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=Ie.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function ze(e,r,t){if(typeof e!="string")return;let n=Me.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(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 $e(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Oe.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=We(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function Ge(e){return e.type==="solid"?{type:"solid",color:Y(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:Y(r.color)}))}}function He(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 Ye(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(He);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ge(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>Ne.test(t)).slice(0,4);return r.length>0?r:void 0}function Ue(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 Xe(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 ke({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=$e(n.background??n.backgroundColor),a=z(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&Ge(i),s={fontFamilies:ge(n.fontFamily)??ge(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:Xe(n.fontWeight)??600,letterSpacing:ze(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:De.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Ue(n.padding),l=Ye(n.boxShadow),f=A(n.borderRadius,0,9999),y=typeof n.backdropFilter=="string"?A(_e.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 je(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)?Y(n,r):e}function qe(e){if(typeof e=="number"||typeof e=="string")return e}function we({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=ke({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??je(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(qe(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as ve,jsx as X,jsxs as tr}from"react/jsx-runtime";var te=class extends M{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function xe(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 te(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 Er({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),R=h(!1),_=h(!1),b=U(()=>typeof o=="object"?void 0:rr(o),[o]),H=U(()=>typeof o=="object"?o:b?we({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),j=U(()=>ue(b?.buttonsLayout.cardFormContainer,i),[b,i]),S=U(()=>b?pe(b):void 0,[b]),ne=h(u),q=h(y),oe=h(s),ie=h(c),ae=h(l),se=h(f),N=h(!1),K=h(!1),Z=h(0);return ne.current=u,q.current=y,oe.current=s,ie.current=c,ae.current=l,se.current=f,re(()=>{let d=Z.current+1;return Z.current=d,()=>{queueMicrotask(()=>{Z.current===d&&(N.current||K.current||(K.current=!0,E(()=>{ae.current?.({status:"cancelled",sessionId:e})})))})}},[e]),re(()=>{let d=!0,V=new Ze(er(t),{telemetry:n});return T(null),C(null),L(null),N.current=!1,K.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 x=D.data.session;if(!x||!Qe(x))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let O=x.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 Je({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!d)return;let x=xe(D);N.current=!0,L(x),E(()=>q.current?.(x))}})(),()=>{d=!1,V.destroy()}},[t,r,e,n]),re(()=>{if(!p)return;let d=!1;_.current=!1,R.current=!1;let V=p.on("submitting",()=>{R.current=!0,B(null),m("processing")}),D=p.on("complete",v=>{N.current=!0,R.current=!1,m("success"),(async()=>(await new Promise(J=>setTimeout(J,600)),!_.current&&(_.current=!0,E(()=>{oe.current?.({status:"succeeded",sessionId:e,...v.paymentMethod?{paymentMethod:v.paymentMethod}:{}})}),d||m(null))))()}),x=p.on("decline",v=>{N.current=!0,R.current=!1,B(v.message??null),m("error"),E(()=>{ie.current?.({status:"declined",sessionId:e,...v.declineReason?{reason:v.declineReason}:{},...v.message?{message:v.message}:{}})}),(async()=>(await new Promise(J=>setTimeout(J,400)),d||m(null)))()}),O=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,V(),D(),x(),O()}},[p,e]),P?X("div",{role:"alert",children:P.message}):!p||!k?.html?X(ve,{children:a}):tr(ve,{children:[w&&X(me,{status:w,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...S?{theme:S}:{}}),X(de,{capture:p,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:H,containerStyle:j,onReady:()=>{E(()=>ne.current?.())},onValidation:d=>{E(()=>se.current?.(d))},onError:d=>{if(!d)return;R.current&&(R.current=!1,B(d),m("error"),setTimeout(()=>m(null),400));let V=xe(new Error(d),{code:"card_setup_widget_failed",retryable:!0});E(()=>q.current?.(V))}})]})}export{ue as a,pe as b,E as c,me as d,ce as e,de as f,je as g,qe as h,we as i,te as j,xe as k,Er as l};
|
package/dist/chunk-JUUKXJQQ.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as we,b as Me,c as v,d as be,f as _e,i as Ee,k}from"./chunk-I4TPZWBS.mjs";import{PaymentAPI as De,PciVaultCardCapture as Je}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as Qe,resolveBillingApiUrl as ee,resolveTheme as Xe}from"@flopay/shared";import Ze,{Suspense as Le,useCallback as D,useEffect as te,useMemo as L,useRef as f,useState as w}from"react";import{PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as Ge}from"@flopay/shared";var He=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),je=new Set(["wallet","apm"]);function T(t){return typeof t=="string"&&t.trim().length>0}function Ke(t){if(typeof t!="object"||t===null)return!1;let o=t;return T(o.family)&&T(o.paymentMethodType)}function ze(t){let n=t.raw?.data?.currency;return T(n)?n.trim().toUpperCase():null}function Re(t){let o=ze(t),n=t.data.session?.advertisedPaymentMethods;if(!Array.isArray(n))return{card:!0,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]};let s={card:!1,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]},l=new Set;for(let i of n){if(!Ke(i)||l.has(i.paymentMethodType))continue;let{family:p,paymentMethodType:m,providerType:I,publishableKey:b}=i;if(p==="card"){if(m!=="card")continue;s.card=!0}else if(je.has(p)){if(I!=="stripe"||m==="card"||!T(b))continue;if(o===null){s.skippedForMissingCurrency.includes(m)||s.skippedForMissingCurrency.push(m);continue}s.stripe.push({method:m,publishableKey:b,currency:o})}else if(p==="paypal"){if(m!==Ge||I!=="paypal"||!T(b))continue;s.paypal={clientId:b,...T(i.environment)?{environment:i.environment}:{}}}else continue;l.add(m)}return s.paypal&&(s.stripe=s.stripe.filter(i=>i.method!=="paypal")),s}function Z(t){return[...t.card?["card"]:[],...t.stripe.map(o=>o.method),...t.paypal?["paypal"]:[]]}function Fe(t){return Z(t).length>0}function Ae(t){return He.has(t)?"wallet":"apm"}var qe=["setup_intent","setup_intent_client_secret","redirect_status"];function ke(){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 Te(){if(typeof window>"u")return;let t=new URL(window.location.href),o=!1;for(let n of qe)t.searchParams.has(n)&&(t.searchParams.delete(n),o=!0);o&&window.history.replaceState(window.history.state,"",t.toString())}function Ve(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 Ie,jsx as h,jsxs as xe}from"react/jsx-runtime";var et=15,tt=2e3;function rt(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function re(t){return new Promise(o=>setTimeout(o,t))}async function nt(t,o,n){if(!o.trim())throw new M("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!n.trim())throw new M("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let s=await t.getUnifiedCheckoutSession(o,n),l=s.data.session;if(!l||!Qe(l))throw new M("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let i=Re(s);if(!Fe(i)){let{skippedForMissingCurrency:p}=i,m=p.length>0?`FloPay: this setup session advertises only Stripe methods (${p.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(m,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:l,advertisement:i}}async function at(t,o,n,s){let l=o.vault??null;if(l?.html?.trim()||(l=await t.getVaultCapture(n,s)),!l.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return l}var j=class extends Ze.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(n){this.props.onFailed(n,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function gt({branches:{StripeSetupMethod:t,PayPalSetupMethod:o},sessionId:n,nonce:s,billingApiUrl:l,telemetry:i,theme:p="modern-light",containerStyle:m,loading:I=null,onReady:b,onComplete:ne,onDecline:ae,onCancel:oe,onValidation:se,onError:ie}){let[K]=w(ke),[x,z]=w(null),[Be,q]=w(!1),[P,le]=w(null),[B,ue]=w(null),[ce,de]=w(null),[N,y]=w(null),[$,pe]=w(()=>new Set),U=f($),me=f(null);me.current=x;let g=f(!1),J=f(!1),V=f(!1),Q=f(!1),X=f(0),Y=f(0),E=f(!1),S=L(()=>typeof p=="object"?void 0:Xe(p),[p]),Ne=L(()=>typeof p=="object"?p:S?Ee({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,p]),Ue=L(()=>we(S?.buttonsLayout.cardFormContainer,m),[S,m]),ye=L(()=>S?Me(S):void 0,[S]),d=f({sessionId:n,nonce:s,billingApiUrl:l,telemetry:i,onReady:b,onComplete:ne,onDecline:ae,onCancel:oe,onValidation:se,onError:ie});d.current={sessionId:n,nonce:s,billingApiUrl:l,telemetry:i,onReady:b,onComplete:ne,onDecline:ae,onCancel:oe,onValidation:se,onError:ie},te(()=>{E.current=!0;let e=X.current+1;return X.current=e,()=>{E.current=!1,Y.current+=1,queueMicrotask(()=>{X.current===e&&(V.current||Q.current||(Q.current=!0,v(()=>{d.current.onCancel?.({status:"cancelled",sessionId:n})})))})}},[n]);let R=D((e,r)=>{V.current=!0,g.current=!1,y({status:"success",wording:e,message:null}),(async()=>(await re(600),!J.current&&(J.current=!0,v(()=>{d.current.onComplete?.({status:"succeeded",sessionId:d.current.sessionId,...r?{paymentMethod:r}:{}})}),E.current&&y(null))))()},[]),F=D((e,r)=>{V.current=!0,g.current=!1,y({status:"error",wording:e,message:r.message??null}),v(()=>{d.current.onDecline?.({status:"declined",sessionId:d.current.sessionId,...r.reason?{reason:r.reason}:{},...r.message?{message:r.message}:{}})}),(async()=>(await re(400),E.current&&y(null)))()},[]),A=D((e,r)=>{g.current?(g.current=!1,y({status:"error",wording:e,message:r.message}),setTimeout(()=>{E.current&&y(null)},400)):y(null),v(()=>d.current.onError?.(r))},[]),W=D(async e=>{let r=Y.current+1;Y.current=r;let u=()=>!E.current||r!==Y.current;g.current=!0,y({status:"processing",wording:"payment_method",message:null});let c=new De(ee(d.current.billingApiUrl),{telemetry:d.current.telemetry});try{for(let a=0;a<et;a+=1){if((a>0||e.waitFirst)&&await re(tt),u())return;let C=await c.getUnifiedCheckoutSession(d.current.sessionId,d.current.nonce);if(u())return;let _=C.data.session?.status;if(_==="complete"){q(!0),R("payment_method");return}if(_==="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(a){if(u())return;let C=a instanceof M&&a.code==="payment_method_setup_unverified";A("payment_method",k(a,C?{retryable:!0}:{}))}finally{c.destroy()}},[A,R]);te(()=>{let e=!0,r=new De(ee(l),{telemetry:i});z(null),q(!1),le(null),ue(null),de(null);let u=new Set;return U.current=u,pe(u),V.current=!1,Q.current=!1,J.current=!1,(async()=>{try{let{session:c,advertisement:a}=await nt(r,n,s);if(!e)return;let C={advertisement:a,customer:rt(c)};if(K){if(Te(),c.status==="complete"){q(!0),z(C),R("payment_method");return}K.failed?F("payment_method",{reason:"redirect_failed"}):W({waitFirst:!0})}let _=a.card?await at(r,c,n,s):null;if(!e)return;z(C),_&&(ue(_),le(new Je({sessionId:n,operation:"card_setup",telemetry:i})))}catch(c){if(!e)return;let a=k(c);V.current=!0,de(a),v(()=>d.current.onError?.(a))}})(),()=>{e=!1,r.destroy()}},[l,s,K,F,R,n,i,W]),te(()=>{if(!P)return;g.current=!1;let e=P.on("submitting",()=>{g.current=!0,y({status:"processing",wording:"card",message:null})}),r=P.on("complete",a=>{R("card",a.paymentMethod)}),u=P.on("decline",a=>{F("card",{...a.declineReason?{reason:a.declineReason}:{},...a.message?{message:a.message}:{}})}),c=P.on("challenge_dismissed",()=>{y(null)});return()=>{e(),r(),u(),c()}},[P,F,R]);let fe=D((e,r,u)=>{if(u.retryable){A("payment_method",k(r,u));return}if(U.current.has(e))return;let c=new Set(U.current);c.add(e),U.current=c,pe(c);let a=me.current?.advertisement,C=a?Z(a).some(_=>!c.has(_)):!1;A("payment_method",k(r,{code:u.code,retryable:C}))},[A]),he=L(()=>({onSubmitting:()=>{g.current=!0,y({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{W({waitFirst:!1})},onDeclined:e=>F("payment_method",e),onValidation:e=>{v(()=>d.current.onValidation?.(e))},onAbandoned:()=>{g.current=!1,y(null)}}),[F,W]),Se=f(fe);Se.current=fe;let ge=f(new Map),G=e=>{let r=ge.current.get(e);if(r)return r;let u=(c,a)=>Se.current(e,c,a);return ge.current.set(e,u),u},ve=N?h(be,{status:N.status,errorMessage:N.message,...Ve(N.wording),successNote:null,...ye?{theme:ye}:{}}):null;if(ce)return h("div",{role:"alert",children:ce.message});if(!x||Be)return xe(Ie,{children:[ve,x?null:I]});let{advertisement:O,customer:Ye}=x,Pe=ee(l),Ce=i===void 0?{}:{telemetry:i},We=O.stripe.filter(({method:e})=>!$.has(e)),H=$.has("paypal")?null:O.paypal;return xe(Ie,{children:[ve,O.card&&P&&B?.html?h("div",{"data-flopay-payment-method":"card",children:h(_e,{capture:P,html:B.html,messageToken:B.messageToken,expectedOrigin:B.expectedOrigin,theme:Ne,containerStyle:Ue,onReady:()=>{v(()=>d.current.onReady?.())},onValidation:e=>{v(()=>d.current.onValidation?.(e))},onError:e=>{e&&A("card",k(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null,We.map(({method:e,publishableKey:r,currency:u})=>h("div",{"data-flopay-payment-method":e,children:h(j,{onFailed:G(e),children:h(Le,{fallback:null,children:h(t,{method:e,category:Ae(e),publishableKey:r,currency:u,sessionId:n,nonce:s,billingApiUrl:Pe,...Ce,...S?{appearance:S.appearance}:{},...he,onFailed:G(e)})})})},e)),H?h("div",{"data-flopay-payment-method":"paypal",children:h(j,{onFailed:G("paypal"),children:h(Le,{fallback:null,children:h(o,{clientId:H.clientId,...H.environment?{environment:H.environment}:{},...O.currency?{currency:O.currency}:{},sessionId:n,nonce:s,billingApiUrl:Pe,customer:Ye,...Ce,...he,onFailed:G("paypal")})})})}):null]})}export{gt as a};
|
package/dist/chunk-OYOJA6FI.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as M,e as k,g as A,i as R,j as B}from"./chunk-M7R46EDF.mjs";import{PaymentAPI as L}from"@flopay/js/card-setup";import{FloPayError as W,getStripeMethodDisplayName as D}from"@flopay/shared";import{Elements as N,ExpressCheckoutElement as j,PaymentElement as q,useElements as H,useStripe as K}from"@stripe/react-stripe-js";import{loadStripe as O}from"@stripe/stripe-js";import{useCallback as C,useMemo as U,useRef as X,useState as f}from"react";import{Fragment as ee,jsx as u,jsxs as te}from"react/jsx-runtime";var x={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"}},v=new Map;function G(e){let n=v.get(e);if(n)return n;let o=O(e).catch(a=>{throw v.delete(e),a});return v.set(e,o),o}var J={night:"night",flat:"flat"};function Q(e){return e?{theme:J[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function Y(e){return k(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function Z(e){return e==="paypal"?"PayPal":D(e)}function $(){return typeof window>"u"?"":window.location.href}function le(e){let{publishableKey:n,method:o,currency:a,appearance:p}=e,[d]=f(()=>G(n)),m=U(()=>{let i=Q(p);return{mode:"setup",currency:a.toLowerCase(),paymentMethodTypes:x[o]?.types??[o],...i?{appearance:i}:{}}},[p,a,o]);return u(N,{stripe:d,options:m,children:u(V,{...e})})}function V({method:e,category:n,sessionId:o,nonce:a,billingApiUrl:p,telemetry:d,onSubmitting:m,onConfirmed:i,onDeclined:E,onFailed:g,onValidation:h}){let y=K(),l=H(),[I,_]=f(!1),P=X(!1),[c]=f(()=>R()),[T,F]=f(!1),S=C((t,s)=>{if(A(t,{inAppBrowser:c.inAppBrowser,handoffObserved:!1}).popupBlocked){F(!0),g(new Error(M(Z(e),!0,c.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}g(s.message===void 0?t:new Error(s.message),{code:s.code,retryable:!0})},[c.inAppBrowser,e,g]),b=C(async()=>{if(!(!y||!l||P.current)){P.current=!0,_(!0);try{let t=await l.submit();if(t.error){h(t.error.message??null);return}m();let s=await new L(p,{telemetry:d}).createSessionIntent(o,a,{provider:"stripe",paymentMethodCategory:n,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(s.provider!=="stripe"||s.intentKind!=="setup")throw new W("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let r=await y.confirmSetup({elements:l,clientSecret:s.clientSecret,confirmParams:{return_url:$()},redirect:"if_required"});if(r.error){Y(r.error)?E({...r.error.decline_code||r.error.code?{reason:r.error.decline_code??r.error.code}:{},...r.error.message?{message:r.error.message}:{}}):S(r.error,{code:"payment_method_setup_provider_failed",message:r.error.message??"The payment method could not be saved."});return}i()}catch(t){S(t,{code:"payment_method_setup_failed"})}finally{P.current=!1,_(!1)}}},[p,n,l,e,a,i,E,m,h,S,o,y,d]),w=x[e]?.wallet,z=w==="paypal"&&B(c,"auto",T?"blocked":c.popupCapability)==="redirect";if(n==="wallet"&&w&&!z){let t={applePay:"never",googlePay:"never",link:"never",paypal:"never",amazonPay:"never"};return t[w]="auto",u(j,{options:{paymentMethods:t},onConfirm:()=>{b()}})}return te(ee,{children:[u(q,{onChange:t=>{t.complete&&h(null)}}),u("button",{type:"button","data-flopay-payment-method-save":e,disabled:!y||!l||I,onClick:()=>{b()},children:"Save payment method"})]})}export{le as a};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a}from"./chunk-OYOJA6FI.mjs";import"./chunk-M7R46EDF.mjs";export{a as StripeSetupMethod};
|