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