@flopay/react 1.11.4 → 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.d.cts +8 -1
- package/dist/index.d.ts +8 -1
- 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-AZRGKPW7.mjs +0 -6
- package/dist/chunk-LIYRDFMO.mjs +0 -1
- 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
|
-
`,an=44;Gt={buttonType:{applePay:"plain",googlePay:"plain"},layout:{maxColumns:1,overflow:"never"}},jt={type:"accordion",defaultCollapsed:!1,radios:"never"}});var er={};De(er,{StripeSetupMethod:()=>fn});function sn(e){let t=ze.get(e);if(t)return t;let r=(0,Jt.loadStripe)(e).catch(n=>{throw ze.delete(e),n});return ze.set(e,r),r}function un(e){return e?{theme:ln[e.theme??"default"]??"stripe",...e.variables?{variables:e.variables}:{},...e.rules?{rules:e.rules}:{}}:void 0}function dn(e){return He(e)||e.code==="setup_intent_authentication_failure"||e.code==="payment_method_provider_decline"}function qt(e){return e==="paypal"?"PayPal":(0,ge.getStripeMethodDisplayName)(e)}function cn(){return typeof window>"u"?"":window.location.href}function fn(e){let{publishableKey:t,method:r,currency:n,futureUse:o,futureUseUnsupported:a,appearance:s}=e,[l]=(0,I.useState)(()=>sn(t)),d=(0,I.useMemo)(()=>{let p=un(s),f=(0,ge.resolveSetupFutureUsage)({futureUse:o,futureUseUnsupported:a},r,"setup");return{mode:"setup",currency:n.toLowerCase(),paymentMethodTypes:Qt[r]?.types??[r],...f?{setupFutureUsage:f}:{},...p?{appearance:p}:{}}},[s,n,o,a,r]);return(0,B.jsx)(X.Elements,{stripe:l,options:d,children:(0,B.jsx)(mn,{...e})})}function mn({method:e,category:t,sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,appearance:s,themeId:l,buttonsLayout:d,onSubmitting:p,onConfirmed:f,onDeclined:S,onFailed:g,onValidation:k,onUnavailable:P}){let E=(0,X.useStripe)(),m=(0,X.useElements)(),[_,D]=(0,I.useState)(!1),[M,v]=(0,I.useState)("loading"),[j,N]=(0,I.useState)(!1),[R,W]=(0,I.useState)(!1),$=(0,I.useRef)(!1),[U]=(0,I.useState)(()=>Oe()),[A,Y]=(0,I.useState)(!1),te=(0,I.useCallback)((F,V)=>{if(Be(F,{inAppBrowser:U.inAppBrowser,handoffObserved:!1}).popupBlocked){Y(!0),g(new Error(Le(qt(e),!0,U.inAppBrowser)),{code:"popup_blocked",retryable:!0});return}g(V.message===void 0?F:new Error(V.message),{code:V.code,retryable:!0})},[U.inAppBrowser,e,g]),K=(0,I.useCallback)(async()=>{if(!(!E||!m||$.current)){$.current=!0,D(!0);try{let F=await m.submit();if(F.error){k(F.error.message??null);return}p();let V=await new Zt.PaymentAPI(o,{telemetry:a}).createSessionIntent(r,n,{provider:"stripe",paymentMethodCategory:t,paymentMethodType:e,paymentMethodId:null,intentKind:"setup"});if(V.provider!=="stripe"||V.intentKind!=="setup")throw new ge.FloPayError("The billing API returned a non-setup intent.","api_error",{code:"InvalidSessionIntentResponse"});let L=await E.confirmSetup({elements:m,clientSecret:V.clientSecret,confirmParams:{return_url:cn()},redirect:"if_required"});if(L.error){dn(L.error)?S({...L.error.decline_code||L.error.code?{reason:L.error.decline_code??L.error.code}:{},...L.error.message?{message:L.error.message}:{}}):te(L.error,{code:"payment_method_setup_provider_failed",message:L.error.message??"The payment method could not be saved."});return}f()}catch(F){te(F,{code:"payment_method_setup_failed"})}finally{$.current=!1,D(!1)}}},[o,t,m,e,n,f,S,p,k,te,r,E,a]),re=Qt[e]?.wallet,G=re==="paypal"&&Dt(U,"auto",A?"blocked":U.popupCapability)==="redirect",ue=s?.variables?.borderRadius??d?.cardButton?.borderRadius??8;if(t==="wallet"&&re&&!G)return(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)(Ht,{}),(0,B.jsx)(Yt,{state:M,borderRadius:ue,children:(0,B.jsx)(X.ExpressCheckoutElement,{options:{...Gt,paymentMethods:$t([e])},onReady:F=>{let V=Wt(F,[re]);v(V),V==="unavailable"&&P()},onLoadError:()=>{v("load_error"),P()},onConfirm:()=>{K()}})})]});let ne=qt(e);return(0,B.jsxs)(B.Fragment,{children:[j?(0,B.jsx)(zt,{method:e,themeId:l,hasNextStep:!0,highlighted:R,disabled:_,onClick:()=>W(F=>!F),backgroundColor:d?.cardButton?.backgroundColor,borderColor:d?.cardInputBorder,textColor:d?.cardButton?.color,borderRadius:ue}):null,(0,B.jsxs)("div",{"data-testid":`flopay-stripe-method-form-${e}`,"aria-hidden":!R,style:R?{display:"flex",flexDirection:"column"}:pn,children:[(0,B.jsx)(X.PaymentElement,{options:{layout:jt},onReady:()=>N(!0),onLoadError:()=>P(),onChange:F=>{F.complete&&k(null)}}),(0,B.jsx)(Kt,{testId:`flopay-payment-method-save-${e}`,attributes:{"data-flopay-payment-method-save":e},disabled:!E||!m||_||!R,onClick:()=>{K()},color:s?.variables?.colorPrimary??"#4A49FF",borderRadius:s?.variables?.borderRadius??"8px",style:d?.submitButton,children:_?"Saving\u2026":`Save ${ne}`})]})]})}var Zt,ge,X,Jt,I,B,Qt,ze,ln,pn,tr=fe(()=>{"use strict";Zt=require("@flopay/js/card-setup"),ge=require("@flopay/shared"),X=require("@stripe/react-stripe-js"),Jt=require("@stripe/stripe-js"),I=require("react");We();Ye();Xt();B=require("react/jsx-runtime"),Qt={apple_pay:{types:["card"],wallet:"applePay"},google_pay:{types:["card"],wallet:"googlePay"},link:{types:["link"],wallet:"link"},paypal:{types:["paypal"],wallet:"paypal"},amazon_pay:{types:["amazon_pay"],wallet:"amazonPay"}},ze=new Map;ln={night:"night",flat:"flat"};pn={position:"absolute",width:"100%",height:0,overflow:"hidden",visibility:"hidden",pointerEvents:"none"}});var or={};De(or,{PayPalSetupMethod:()=>yn});function yn({clientId:e,environment:t,currency:r,sessionId:n,nonce:o,billingApiUrl:a,telemetry:s,customer:{userId:l,email:d},onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g}){let k=(0,le.useRef)(null),P=(0,le.useRef)({onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g});P.current={onSubmitting:p,onConfirmed:f,onFailed:S,onAbandoned:g};let[E]=(0,le.useState)(()=>Oe().inAppBrowser);return(0,le.useEffect)(()=>{let m=!0,_,D=new rr.PaymentAPI(a,{telemetry:s}),M={userId:l,email:d};return(async()=>{try{let v=await(0,nr.loadScript)({clientId:e,...r?{currency:r.toUpperCase()}:{},components:"buttons",...t==="sandbox"||t==="production"?{environment:t}:{}}),j=k.current;if(!m||!j)return;if(!v?.Buttons)throw new ee.FloPayError("PayPal could not be loaded.","api_error",{code:"paypal_unavailable"});let N=v.Buttons({createVaultSetupToken:async()=>{P.current.onSubmitting();let R=await D.createSessionIntent(n,o,{provider:"paypal",paymentMethodCategory:"wallet",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE,paymentMethodId:null,intentKind:"setup"});if(R.provider!=="paypal"||R.providerObjectType!=="setup_token")throw new ee.FloPayError("The billing API did not return a PayPal setup token.","api_error",{code:"InvalidSessionIntentResponse"});return R.providerObjectId},onApprove:async R=>{let W=R.vaultSetupToken;if(!W)throw new ee.FloPayError("PayPal approved without a setup token.","api_error",{code:"paypal_setup_token_missing"});let $=await D.processPayment(M.userId,{sessionId:n,nonce:o,paymentMethodCategory:"paypal",tokenizedData:{id:W,type:"paypal_setup_token",isPaypal:!0,gateway:"paypal",paymentMethodType:ee.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE},accountData:M});if(!$.ok)throw new ee.FloPayError("PayPal could not be saved.","api_error",{code:"paypal_setup_failed",statusCode:$.status});m&&P.current.onConfirmed()},onCancel:()=>{m&&P.current.onAbandoned()},onError:R=>{if(!m)return;let{popupBlocked:W}=Be(R,{inAppBrowser:E,handoffObserved:!1});P.current.onFailed(W?new Error(Le("PayPal",!0,E)):R,{code:W?"popup_blocked":"paypal_setup_failed",retryable:!0})}});_=()=>N.close(),await N.render(j)}catch(v){if(!m)return;P.current.onFailed(v,{code:"paypal_unavailable",retryable:!0})}})(),()=>{m=!1,_?.().catch(()=>{}),D.destroy()}},[a,e,r,d,t,E,o,n,s,l]),(0,ar.jsx)("div",{ref:k,"data-flopay-paypal-setup":""})}var rr,ee,nr,le,ar,sr=fe(()=>{"use strict";rr=require("@flopay/js/card-setup"),ee=require("@flopay/shared"),nr=require("@paypal/paypal-js"),le=require("react");We();Ye();ar=require("react/jsx-runtime")});var hn={};De(hn,{FloPayCardSetupError:()=>Ce,FloPayPaymentMethodSetup:()=>ir});module.exports=vr(hn);var Rt=require("@flopay/js/card-setup"),me=require("@flopay/shared"),Me=require("react");function dt(e,t){if(!e)return t;let r=t??{},n=Object.keys(r),o=n.some(s=>s.startsWith("background")),a={};for(let[s,l]of Object.entries(e))s in r||o&&s.startsWith("background")||(a[s]=l);for(let s of n)a[s]=r[s];return a}var Cr=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Pr(e){let t=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Cr.has(t.charAt(0).toLowerCase()+t.slice(1))}function wr(e,t){return typeof t=="number"&&t!==0&&!Pr(e)?`${t}px`:String(t).trim()}function ct(e,t){if(e.style.cssText="",!!t){for(let[r,n]of Object.entries(t))if(!(n==null||n==="")){if(r.startsWith("--")){e.style.setProperty(r,String(n));continue}e.style[r]=wr(r,n)}}}var pt={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function ft(e){let t=e.appearance.variables??{},r=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?pt.dark:pt.light,a=t.colorText??(n?"#F1F5F9":"#262833"),s=e.appearance.rules?.[".Label"];return{panel:{...r.background===void 0?{}:{background:r.background},...r.backgroundColor===void 0?{}:{backgroundColor:r.backgroundColor},...r.border===void 0?{}:{border:r.border},...r.borderRadius===void 0?{}:{borderRadius:r.borderRadius},...r.boxShadow===void 0?{}:{boxShadow:r.boxShadow},color:a,...t.fontFamily?{fontFamily:t.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:t.colorPrimary??"#4A49FF",labelColors:{processing:a,success:o.success,error:o.error},noteColor:s?.color??a}}function q(e){if(!e)return;let t=r=>{console.error("[FloPay] Merchant callback failed; checkout continued.",r)};try{Promise.resolve(e()).catch(t)}catch(r){t(r)}}var w=require("react/jsx-runtime");var kr={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function mt({status:e,errorMessage:t,authorized:r=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:a="PAYMENT FAILED",successNote:s="You will be automatically redirected, do not close or navigate away from this window.",theme:l=kr}){let d={fontSize:13,color:l.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,w.jsx)("div",{"data-testid":"flopay-processing-overlay","data-status":e,role:"dialog","aria-modal":"true",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(2px)"},children:(0,w.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...l.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,w.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,w.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{animation:"flopay-spin 0.8s linear infinite"},children:[(0,w.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:l.spinnerTrackColor,strokeWidth:"3"}),(0,w.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:l.spinnerAccentColor})]}),e==="success"&&(0,w.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,w.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,w.jsx)("path",{d:"M7 12.5l3 3 7-7",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:20,strokeDashoffset:20,animation:"flopay-draw 0.4s 0.15s ease forwards"}})]})}),e==="error"&&(0,w.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,w.jsxs)("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[(0,w.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,w.jsx)("path",{d:"M8 8l8 8M16 8l-8 8",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",style:{strokeDasharray:12,strokeDashoffset:12,animation:"flopay-draw 0.3s 0.1s ease forwards"}})]})})]}),(0,w.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:l.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(r?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&a]}),e==="success"&&s!==null&&(0,w.jsx)("p",{style:d,children:s}),e==="error"&&t&&(0,w.jsx)("p",{style:d,children:t}),(0,w.jsx)("style",{children:`
|
|
22
|
+
`,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"),yt=typeof window>"u"?xe.useEffect:xe.useLayoutEffect;var ae=require("react/jsx-runtime"),Ve=new WeakSet;function gt({capture:e,html:t,messageToken:r,expectedOrigin:n,theme:o,submitLabel:a,containerStyle:s,onReady:l,onError:d,onValidation:p}){let f=(0,H.useRef)(null),S=(0,H.useRef)(l),g=(0,H.useRef)(d),k=(0,H.useRef)(p);S.current=l,g.current=d,k.current=p;let P=(0,H.useRef)(o);P.current=o;let E=(0,H.useRef)(null),m=a??void 0,_=(0,H.useRef)(m);_.current=m;let D=(0,H.useRef)(void 0);return(0,H.useEffect)(()=>{let M=f.current;if(!M)return;let v=!0,j=!1,N=()=>{!v||j||(j=!0,S.current?.())},R=e.on("ready",()=>{N()}),W=e.on("error",Y=>{g.current?.(Y.message??"There was a problem loading the secure card form.")}),$=e.on("validation",Y=>{k.current?.(Y.message??null)}),U=_.current??(Ve.has(e)?null:void 0),A={html:t,...r?{messageToken:r}:{},...n?{expectedOrigin:n}:{},...P.current?{theme:P.current}:{},...U===void 0?{}:{submitLabel:U}};return E.current=P.current??null,D.current=_.current,_.current!==void 0&&Ve.add(e),e.mount(M,A).then(()=>{N()}).catch(Y=>{v&&g.current?.(Y instanceof Error?Y.message:"Failed to load the secure card form.")}),()=>{v=!1,R(),W(),$(),e.unmount()}},[e,t,r,n]),yt(()=>{let M=f.current;M&&ct(M,s)},[s]),(0,H.useEffect)(()=>{o!==void 0&&(o===null&&E.current===null||(E.current=o,e.applyTheme?.(o)))},[e,o]),(0,H.useEffect)(()=>{m!==D.current&&(D.current=m,m!==void 0&&Ve.add(e),e.setSubmitLabel?.(m??null))},[e,m]),(0,ae.jsx)("div",{ref:f,"data-testid":"flopay-vault-card-fields"})}function ht({label:e}){return(0,ae.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),(0,ae.jsx)("span",{children:e}),(0,ae.jsx)("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}var bt=/^#([0-9a-f]{6})$/i,Er=/^#([0-9a-f]{3})$/i,vt=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ct=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Rr=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,xr=/^(-?\d+(?:\.\d+)?)(?:px)?$/,_r=/^(-?\d+(?:\.\d+)?)em$/,Mr=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,Fr=/^[a-z][a-z0-9 -]{0,31}$/i,Tr=new Set(["none","uppercase","lowercase","capitalize"]);function Pt(e){if(typeof e!="string")return null;let t=e.trim(),r=bt.exec(t);if(r){let f=Number.parseInt(r[1],16);return{r:f>>16&255,g:f>>8&255,b:f&255,a:null}}let n=Er.exec(t);if(n){let[f,S,g]=n[1].split("").map(k=>Number.parseInt(k+k,16));return{r:f,g:S,b:g,a:null}}let o=vt.exec(t),a=o?null:Ct.exec(t),s=o??a;if(!s)return null;let l=Number(s[1]),d=Number(s[2]),p=Number(s[3]);return l>255||d>255||p>255?null:{r:l,g:d,b:p,a:a?Number(a[4]):null}}function wt({r:e,g:t,b:r,a:n}){return n===null?`#${(1<<24|e<<16|t<<8|r).toString(16).slice(1)}`:`rgba(${e},${t},${r},${n})`}function be(e){if(typeof e!="string")return;let t=e.trim();if(bt.test(t)||vt.test(t))return t;let r=Ct.exec(t);if(r&&/^\d/.test(r[4]))return t;let n=Pt(t);return n?wt(n):void 0}function _e(e,t=.12){let r=Pt(e);if(!r)return e;let n=Math.max(0,Math.min(1,1-t));return wt({r:Math.round(r.r*n),g:Math.round(r.g*n),b:Math.round(r.b*n),a:r.a})}function ve(e,t){let r=[],n=0,o="";for(let a of e){if(a==="("&&(n+=1),a===")"&&(n-=1),a===t&&n===0){o.trim()&&r.push(o.trim()),o="";continue}o+=a}return o.trim()&&r.push(o.trim()),r}function se(e,t,r){if(typeof e!="number"&&typeof e!="string")return;let n=xr.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Ar(e,t,r){if(typeof e!="string")return;let n=_r.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=t&&o<=r?o:void 0}function Lr(e){let t=ve(e,",");if(t.length<2||t.length>5)return;let r=[];for(let[n,o]of t.entries()){let a=ve(o," "),s=be(a[0]);if(!s)return;let l=n/(t.length-1)*100,d=a[1]===void 0?l:Number(/^(\d+(?:\.\d+)?)%$/.exec(a[1])?.[1]),p=r[r.length-1]?.position??-1;if(!Number.isFinite(d)||d<0||d>100||d<p)return;r.push({color:s,position:d})}return{type:"linearGradient",angle:0,stops:r}}function Br(e){if(typeof e!="string")return;let t=e.trim(),r=be(t);if(r)return{type:"solid",color:r};let n=Rr.exec(t);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let a=Lr(n[2]);return a&&a.type==="linearGradient"?{...a,angle:o}:void 0}function Or(e){return e.type==="solid"?{type:"solid",color:_e(e.color)}:{...e,stops:e.stops.map(t=>({...t,color:_e(t.color)}))}}function Ir(e){let t=!1,r,n=[];for(let d of ve(e," ")){if(d.toLowerCase()==="inset"){t=!0;continue}let p=be(d);if(p){r=p;continue}let f=se(d,-128,128);if(f===void 0)return;n.push(f)}if(!r||n.length<2||n.length>4)return;let[o,a,s=0,l=0]=n;if(!(Math.abs(o)>64||Math.abs(a)>64||s>128||Math.abs(l)>32))return{color:r,inset:t,offsetX:o,offsetY:a,blur:s,spread:l}}function Dr(e){if(typeof e!="string")return;let t=e.trim();if(t.toLowerCase()==="none")return[];let r=ve(t,",").map(Ir);if(!(r.length===0||r.length>4))return r.every(n=>n!==void 0)?r:void 0}function St(e){if(typeof e!="string")return;let t=ve(e,",").map(r=>r.replace(/^['"]|['"]$/g,"").trim()).filter(r=>Fr.test(r)).slice(0,4);return t.length>0?t:void 0}function Vr(e){let t=typeof e=="string"?e.trim().split(/\s+/):[e],r=se(t[0],0,64),n=se(t[1]??t[0],0,64);if(!(r===void 0||n===void 0))return{paddingBlock:r,paddingInline:n}}function Nr(e){if(e==="bold")return 700;if(e==="normal")return 400;let t=Number(e);return Number.isInteger(t)&&t>=100&&t<=900?t:void 0}function kt({appearance:e,buttonsStyles:t,fontFamily:r}){let n=t.submitButton;if(!n)return;let o=e?.variables,a=Br(n.background??n.backgroundColor),s=be(o?.colorPrimaryHover),l=s?{type:"solid",color:s}:a&&Or(a),d={fontFamilies:St(n.fontFamily)??St(r),fontSize:se(n.fontSize??t.submitButtonFontSize,10,32)??16,fontWeight:Nr(n.fontWeight)??600,letterSpacing:Ar(n.letterSpacing,-.1,.5)??.01,lineHeight:se(n.lineHeight,.8,2)??1,textTransform:Tr.has(String(n.textTransform))?n.textTransform:"uppercase"},p=Vr(n.padding),f=Dr(n.boxShadow),S=se(n.borderRadius,0,9999),g=typeof n.backdropFilter=="string"?se(Mr.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:be(n.color)??"#FFFFFF",...a?{background:a,disabledBackground:a}:{},...l?{hoverBackground:l}:{},typography:d,...p?{spacing:p}:{},...f?{shadow:f}:{},...S===void 0?{}:{borderRadius:S},disabledOpacity:e?.theme==="night"?.8:.6,...g===void 0?{}:{backdropBlur:g}}}function Ur(e,t=.12){let r=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(r)?`#${r}`:r;return/^#[0-9a-fA-F]{6}$/.test(n)?_e(n,t):e}function Hr(e){if(typeof e=="number"||typeof e=="string")return e}function Et({appearance:e,buttonsStyles:t,layout:r="default"}){let n=e?.variables,o=S=>typeof S=="string"&&S?S:void 0,a=t.submitButton,s=o(n?.colorPrimary)??o(a?.backgroundColor)??"#4A49FF",l=r==="buttons",d=t.nameInput,p=o(d?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",f=kt({appearance:e,buttonsStyles:t,fontFamily:p});return{primaryColor:s,primaryHoverColor:o(n?.colorPrimaryHover)??Ur(s,.12),inputBackgroundColor:o(t.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(t.cardInputColor)??o(d?.color)??o(n?.colorText)??"#262833",borderColor:o(t.cardInputBorder)??(l?"#e5e7eb":"#A4A4FF"),placeholderColor:o(t.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:p,fontSize:o(t.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Hr(d?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...f?{submitButton:f}:{}}}var Ne=require("react/jsx-runtime"),Ce=class extends me.FloPayError{constructor(t,r,n){super(t,r,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ie(e,t={}){let r=e instanceof me.FloPayError?e:void 0,n=r?.statusCode,o=t.retryable??(r?.type==="network_error"||r?.type==="rate_limit_error"||typeof n=="number"&&n>=500||r?.code==="vault_capture_timeout"||!r);return new Ce(r?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),r?.type??"api_error",{code:t.code??r?.code??"card_setup_load_failed",retryable:o,...r?.param?{param:r.param}:{},...n===void 0?{}:{statusCode:n}})}var $e=require("react");var Pe=require("@flopay/js/card-setup"),T=require("@flopay/shared"),u=br(require("react"),1);var xt=require("@flopay/shared"),Wr=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),Yr=new Set(["wallet","apm"]);function ye(e){return typeof e=="string"&&e.trim().length>0}function zr(e){if(typeof e!="object"||e===null)return!1;let t=e;return ye(t.family)&&ye(t.paymentMethodType)}function $r(e){let r=e.raw?.data?.currency;return ye(r)?r.trim().toUpperCase():null}function _t(e){let t=$r(e),r=e.data.session?.advertisedPaymentMethods;if(!Array.isArray(r))return{card:!0,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]};let n={card:!1,stripe:[],paypal:null,currency:t,skippedForMissingCurrency:[]},o=new Set;for(let a of r){if(!zr(a)||o.has(a.paymentMethodType))continue;let{family:s,paymentMethodType:l,providerType:d,publishableKey:p}=a;if(s==="card"){if(l!=="card")continue;n.card=!0}else if(Yr.has(s)){if(d!=="stripe"||l==="card"||!ye(p))continue;if(t===null){n.skippedForMissingCurrency.includes(l)||n.skippedForMissingCurrency.push(l);continue}n.stripe.push({method:l,publishableKey:p,currency:t})}else if(s==="paypal"){if(l!==xt.PAYPAL_VAULTED_PAYMENT_METHOD_TYPE||d!=="paypal"||!ye(p))continue;n.paypal={clientId:p,...ye(a.environment)?{environment:a.environment}:{}}}else continue;o.add(l)}return n.paypal&&(n.stripe=n.stripe.filter(a=>a.method!=="paypal")),n}function Fe(e){return[...e.card?["card"]:[],...e.stripe.map(t=>t.method),...e.paypal?["paypal"]:[]]}function Mt(e){return Fe(e).length>0}function Te(e){return Wr.has(e)?"wallet":"apm"}var Gr=["setup_intent","setup_intent_client_secret","redirect_status"];function Ft(){if(typeof window>"u")return null;let e=new URLSearchParams(window.location.search);return!e.has("setup_intent")||!e.has("redirect_status")?null:{failed:e.get("redirect_status")==="failed"}}function Tt(){if(typeof window>"u")return;let e=new URL(window.location.href),t=!1;for(let r of Gr)e.searchParams.has(r)&&(e.searchParams.delete(r),t=!0);t&&window.history.replaceState(window.history.state,"",e.toString())}function At(e){return e==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}var C=require("react/jsx-runtime"),Kr=15,Xr=2e3;function qr(e){return{userId:e.customer?.id??"",email:e.customer?.email??""}}function Ue(e){return new Promise(t=>setTimeout(t,e))}async function Zr(e,t,r){if(!t.trim())throw new T.FloPayError("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new T.FloPayError("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let n=await e.getUnifiedCheckoutSession(t,r),o=n.data.session;if(!o||!(0,T.isCardSetupCheckoutSession)(o))throw new T.FloPayError("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let a=_t(n);if(!Mt(a)){let{skippedForMissingCurrency:s}=a,l=s.length>0?`FloPay: this setup session advertises only Stripe methods (${s.join(", ")}), and they need the session's currency, which the setup-session read did not carry.`:"FloPay: this setup session advertises no payment method.";throw new T.FloPayError(l,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:o,advertisement:a}}async function Jr(e,t,r,n){let o=t.vault??null;if(o?.html?.trim()||(o=await e.getVaultCapture(r,n)),!o.html?.trim())throw new T.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return o}var Ae=class extends u.default.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(r){this.props.onFailed(r,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function Bt({branches:{StripeSetupMethod:e,PayPalSetupMethod:t},sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,theme:s="modern-light",containerStyle:l,loading:d=null,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P}){let[E]=(0,u.useState)(Ft),[m,_]=(0,u.useState)(null),[D,M]=(0,u.useState)(!1),[v,j]=(0,u.useState)(null),[N,R]=(0,u.useState)(null),[W,$]=(0,u.useState)(null),[U,A]=(0,u.useState)(null),[Y,te]=(0,u.useState)(()=>new Set),K=(0,u.useRef)(Y),re=(0,u.useRef)(null);re.current=m;let G=(0,u.useRef)(!1),ue=(0,u.useRef)(!1),ne=(0,u.useRef)(!1),F=(0,u.useRef)(!1),V=(0,u.useRef)(0),L=(0,u.useRef)(0),de=(0,u.useRef)(!1),z=(0,u.useMemo)(()=>typeof s=="object"?void 0:(0,T.resolveTheme)(s),[s]),ur=(0,u.useMemo)(()=>typeof s=="object"?s:z?Et({appearance:z.appearance,buttonsStyles:z.buttonsLayout,layout:"default"}):null,[z,s]),dr=(0,u.useMemo)(()=>dt(z?.buttonsLayout.cardFormContainer,l),[z,l]),Ge=(0,u.useMemo)(()=>z?ft(z):void 0,[z]),O=(0,u.useRef)({sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P});O.current={sessionId:r,nonce:n,billingApiUrl:o,telemetry:a,onReady:p,onComplete:f,onDecline:S,onCancel:g,onValidation:k,onError:P},(0,u.useEffect)(()=>{de.current=!0;let i=V.current+1;return V.current=i,()=>{de.current=!1,L.current+=1,queueMicrotask(()=>{V.current===i&&(ne.current||F.current||(F.current=!0,q(()=>{O.current.onCancel?.({status:"cancelled",sessionId:r})})))})}},[r]);let ce=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"success",wording:i,message:null}),(async()=>(await Ue(600),!ue.current&&(ue.current=!0,q(()=>{O.current.onComplete?.({status:"succeeded",sessionId:O.current.sessionId,...c?{paymentMethod:c}:{}})}),de.current&&A(null))))()},[]),pe=(0,u.useCallback)((i,c)=>{ne.current=!0,G.current=!1,A({status:"error",wording:i,message:c.message??null}),q(()=>{O.current.onDecline?.({status:"declined",sessionId:O.current.sessionId,...c.reason?{reason:c.reason}:{},...c.message?{message:c.message}:{}})}),(async()=>(await Ue(400),de.current&&A(null)))()},[]),J=(0,u.useCallback)((i,c)=>{G.current?(G.current=!1,A({status:"error",wording:i,message:c.message}),setTimeout(()=>{de.current&&A(null)},400)):A(null),q(()=>O.current.onError?.(c))},[]),ke=(0,u.useCallback)(async i=>{let c=L.current+1;L.current=c;let h=()=>!de.current||c!==L.current;G.current=!0,A({status:"processing",wording:"payment_method",message:null});let b=new Pe.PaymentAPI((0,T.resolveBillingApiUrl)(O.current.billingApiUrl),{telemetry:O.current.telemetry});try{for(let y=0;y<Kr;y+=1){if((y>0||i.waitFirst)&&await Ue(Xr),h())return;let Q=await b.getUnifiedCheckoutSession(O.current.sessionId,O.current.nonce);if(h())return;let oe=Q.data.session?.status;if(oe==="complete"){M(!0),ce("payment_method");return}if(oe==="expired")throw new T.FloPayError("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new T.FloPayError("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(y){if(h())return;let Q=y instanceof T.FloPayError&&y.code==="payment_method_setup_unverified";J("payment_method",ie(y,Q?{retryable:!0}:{}))}finally{b.destroy()}},[J,ce]);(0,u.useEffect)(()=>{let i=!0,c=new Pe.PaymentAPI((0,T.resolveBillingApiUrl)(o),{telemetry:a});_(null),M(!1),j(null),R(null),$(null);let h=new Set;return K.current=h,te(h),ne.current=!1,F.current=!1,ue.current=!1,(async()=>{try{let{session:b,advertisement:y}=await Zr(c,r,n);if(!i)return;let Q={advertisement:y,customer:qr(b),...b.futureUse?{futureUse:b.futureUse}:{},...b.futureUseUnsupported?{futureUseUnsupported:b.futureUseUnsupported}:{}};if(E){if(Tt(),b.status==="complete"){M(!0),_(Q),ce("payment_method");return}E.failed?pe("payment_method",{reason:"redirect_failed"}):ke({waitFirst:!0})}let oe=y.card?await Jr(c,b,r,n):null;if(!i)return;_(Q),oe&&(R(oe),j(new Pe.PciVaultCardCapture({sessionId:r,operation:"card_setup",telemetry:a})))}catch(b){if(!i)return;let y=ie(b);ne.current=!0,$(y),q(()=>O.current.onError?.(y))}})(),()=>{i=!1,c.destroy()}},[o,n,E,pe,ce,r,a,ke]),(0,u.useEffect)(()=>{if(!v)return;G.current=!1;let i=v.on("submitting",()=>{G.current=!0,A({status:"processing",wording:"card",message:null})}),c=v.on("complete",y=>{ce("card",y.paymentMethod)}),h=v.on("decline",y=>{pe("card",{...y.declineReason?{reason:y.declineReason}:{},...y.message?{message:y.message}:{}})}),b=v.on("challenge_dismissed",()=>{A(null)});return()=>{i(),c(),h(),b()}},[v,pe,ce]);let je=(0,u.useCallback)((i,c,h)=>{if(h.retryable){J("payment_method",ie(c,h));return}if(K.current.has(i))return;let b=new Set(K.current);b.add(i),K.current=b,te(b);let y=re.current?.advertisement,Q=y?Fe(y).some(oe=>!b.has(oe)):!1;J("payment_method",ie(c,{code:h.code,retryable:Q}))},[J]),Ke=(0,u.useMemo)(()=>({onSubmitting:()=>{G.current=!0,A({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{ke({waitFirst:!1})},onDeclined:i=>pe("payment_method",i),onValidation:i=>{q(()=>O.current.onValidation?.(i))},onAbandoned:()=>{G.current=!1,A(null)}}),[pe,ke]),Xe=(0,u.useRef)(je);Xe.current=je;let qe=(0,u.useRef)(new Map),Ee=i=>{let c=qe.current.get(i);if(c)return c;let h=(b,y)=>Xe.current(i,b,y);return qe.current.set(i,h),h},Ze=(0,u.useCallback)(i=>{if(K.current.has(i))return;let c=new Set(K.current);c.add(i),K.current=c,te(c);let h=re.current?.advertisement;h&&Fe(h).some(y=>!c.has(y))||J("payment_method",ie(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[J]),Je=(0,u.useRef)(Ze);Je.current=Ze;let Qe=(0,u.useRef)(new Map),et=i=>{let c=Qe.current.get(i);if(c)return c;let h=()=>Je.current(i);return Qe.current.set(i,h),h},tt=U?(0,C.jsx)(mt,{status:U.status,errorMessage:U.message,...At(U.wording),successNote:null,...Ge?{theme:Ge}:{}}):null;if(W)return(0,C.jsx)("div",{role:"alert",children:W.message});if(!m||D)return(0,C.jsxs)(C.Fragment,{children:[tt,m?null:d]});let{advertisement:he,customer:cr,futureUse:rt,futureUseUnsupported:nt}=m,ot=(0,T.resolveBillingApiUrl)(o),at=a===void 0?{}:{telemetry:a},Ie=he.stripe.filter(({method:i})=>!Y.has(i)),Se=Y.has("paypal")?null:he.paypal,st=!!(he.card&&v&&N?.html),it=({method:i,publishableKey:c,currency:h})=>(0,C.jsx)("div",{"data-flopay-payment-method":i,style:{display:"contents"},children:(0,C.jsx)(Ae,{onFailed:Ee(i),children:(0,C.jsx)(u.Suspense,{fallback:null,children:(0,C.jsx)(e,{method:i,category:Te(i),publishableKey:c,currency:h,...rt?{futureUse:rt}:{},...nt?{futureUseUnsupported:nt}:{},sessionId:r,nonce:n,billingApiUrl:ot,...at,...z?{appearance:z.appearance,buttonsLayout:z.buttonsLayout}:{},...typeof s=="string"?{themeId:s}:{},...Ke,onFailed:Ee(i),onUnavailable:et(i)})})})},i),pr=Ie.filter(({method:i})=>Te(i)==="wallet"),fr=Ie.filter(({method:i})=>Te(i)!=="wallet"),lt=Ie.length>0||Se!==null;return(0,C.jsxs)(C.Fragment,{children:[tt,lt?(0,C.jsxs)("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[pr.map(it),Se?(0,C.jsx)("div",{"data-flopay-payment-method":"paypal",children:(0,C.jsx)(Ae,{onFailed:Ee("paypal"),children:(0,C.jsx)(u.Suspense,{fallback:null,children:(0,C.jsx)(t,{clientId:Se.clientId,...Se.environment?{environment:Se.environment}:{},...he.currency?{currency:he.currency}:{},sessionId:r,nonce:n,billingApiUrl:ot,customer:cr,...at,...Ke,onFailed:Ee("paypal"),onUnavailable:et("paypal")})})})}):null,fr.map(it)]}):null,st&<?(0,C.jsx)(ht,{label:"or add a card"}):null,st&&v&&N?.html?(0,C.jsx)("div",{"data-flopay-payment-method":"card",children:(0,C.jsx)(gt,{capture:v,html:N.html,messageToken:N.messageToken,expectedOrigin:N.expectedOrigin,theme:ur,containerStyle:dr,onReady:()=>{q(()=>O.current.onReady?.())},onValidation:i=>{q(()=>O.current.onValidation?.(i))},onError:i=>{i&&J("card",ie(new Error(i),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}var lr=require("react/jsx-runtime"),gn={StripeSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(tr(),er)).then(e=>({default:e.StripeSetupMethod}))),PayPalSetupMethod:(0,$e.lazy)(()=>Promise.resolve().then(()=>(sr(),or)).then(e=>({default:e.PayPalSetupMethod})))};function ir(e){return(0,lr.jsx)(Bt,{...e,branches:gn})}0&&(module.exports={FloPayCardSetupError,FloPayPaymentMethodSetup});
|
|
27
|
+
`})]})})}var 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-AZRGKPW7.mjs
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{useEffect as ee,useRef as E}from"react";function le(e,r){if(!e)return r;let t=r??{},n=Object.keys(t),o=n.some(a=>a.startsWith("background")),i={};for(let[a,u]of Object.entries(e))a in t||o&&a.startsWith("background")||(i[a]=u);for(let a of n)i[a]=t[a];return i}var Fe=new Set(["animationIterationCount","aspectRatio","borderImageOutset","borderImageSlice","borderImageWidth","boxFlex","boxFlexGroup","boxOrdinalGroup","columnCount","columns","flex","flexGrow","flexPositive","flexShrink","flexNegative","flexOrder","gridArea","gridRow","gridRowEnd","gridRowSpan","gridRowStart","gridColumn","gridColumnEnd","gridColumnSpan","gridColumnStart","fontWeight","lineClamp","lineHeight","opacity","order","orphans","scale","tabSize","widows","zIndex","zoom","fillOpacity","floodOpacity","stopOpacity","strokeDasharray","strokeDashoffset","strokeMiterlimit","strokeOpacity","strokeWidth"]);function Te(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Fe.has(r.charAt(0).toLowerCase()+r.slice(1))}function Pe(e,r){return typeof r=="number"&&r!==0&&!Te(e)?`${r}px`:String(r).trim()}function ce(e,r){if(e.style.cssText="",!!r){for(let[t,n]of Object.entries(r))if(!(n==null||n==="")){if(t.startsWith("--")){e.style.setProperty(t,String(n));continue}e.style[t]=Pe(t,n)}}}import{useEffect as Ve,useLayoutEffect as Ae}from"react";var de=typeof window>"u"?Ve:Ae;import{jsx as Y,jsxs as Le}from"react/jsx-runtime";var re=new WeakSet;function fe({capture:e,html:r,messageToken:t,expectedOrigin:n,theme:o,submitLabel:i,containerStyle:a,onReady:u,onError:s,onValidation:c}){let l=E(null),f=E(u),y=E(s),p=E(c);f.current=u,y.current=s,p.current=c;let T=E(o);T.current=o;let k=E(null),C=i??void 0,P=E(C);P.current=C;let L=E(void 0);return ee(()=>{let w=l.current;if(!w)return;let m=!0,G=!1,B=()=>{!m||G||(G=!0,f.current?.())},x=e.on("ready",()=>{B()}),_=e.on("error",S=>{y.current?.(S.message??"There was a problem loading the secure card form.")}),b=e.on("validation",S=>{p.current?.(S.message??null)}),H=P.current??(re.has(e)?null:void 0),q={html:r,...t?{messageToken:t}:{},...n?{expectedOrigin:n}:{},...T.current?{theme:T.current}:{},...H===void 0?{}:{submitLabel:H}};return k.current=T.current??null,L.current=P.current,P.current!==void 0&&re.add(e),e.mount(w,q).then(()=>{B()}).catch(S=>{m&&y.current?.(S instanceof Error?S.message:"Failed to load the secure card form.")}),()=>{m=!1,x(),_(),b(),e.unmount()}},[e,r,t,n]),de(()=>{let w=l.current;w&&ce(w,a)},[a]),ee(()=>{o!==void 0&&(o===null&&k.current===null||(k.current=o,e.applyTheme?.(o)))},[e,o]),ee(()=>{C!==L.current&&(L.current=C,C!==void 0&&re.add(e),e.setSubmitLabel?.(C??null))},[e,C]),Y("div",{ref:l,"data-testid":"flopay-vault-card-fields"})}function cr({label:e}){return Le("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[Y("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),Y("span",{children:e}),Y("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}import{PaymentAPI as Je,PciVaultCardCapture as Qe}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as er,resolveBillingApiUrl as rr,resolveTheme as tr}from"@flopay/shared";import{useEffect as te,useMemo as X,useRef as h,useState as $}from"react";var pe={light:{success:"#166534",error:"#991B1B"},dark:{success:"#4ADE80",error:"#FCA5A5"}};function me(e){let r=e.appearance.variables??{},t=e.buttonsLayout.cardFormContainer??{},n=e.appearance.theme==="night",o=n?pe.dark:pe.light,i=r.colorText??(n?"#F1F5F9":"#262833"),a=e.appearance.rules?.[".Label"];return{panel:{...t.background===void 0?{}:{background:t.background},...t.backgroundColor===void 0?{}:{backgroundColor:t.backgroundColor},...t.border===void 0?{}:{border:t.border},...t.borderRadius===void 0?{}:{borderRadius:t.borderRadius},...t.boxShadow===void 0?{}:{boxShadow:t.boxShadow},color:i,...r.fontFamily?{fontFamily:r.fontFamily}:{}},spinnerTrackColor:e.buttonsLayout.cardInputBorder??(n?"#374151":"#e5e7eb"),spinnerAccentColor:r.colorPrimary??"#4A49FF",labelColors:{processing:i,success:o.success,error:o.error},noteColor:a?.color??i}}function F(e){if(!e)return;let r=t=>{console.error("[FloPay] Merchant callback failed; checkout continued.",t)};try{Promise.resolve(e()).catch(r)}catch(t){r(t)}}import{jsx as g,jsxs as I}from"react/jsx-runtime";var Be={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ge({status:e,errorMessage:r,authorized:t=!1,processingLabel:n="PROCESSING...",successLabel:o,errorLabel:i="PAYMENT FAILED",successNote:a="You will be automatically redirected, do not close or navigate away from this window.",theme:u=Be}){let s={fontSize:13,color:u.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return g("div",{"data-testid":"flopay-processing-overlay","data-status":e,role:"dialog","aria-modal":"true",style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.35)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:1e3,backdropFilter:"blur(2px)"},children:I("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...u.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[I("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&I("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:{animation:"flopay-spin 0.8s linear infinite"},children:[g("circle",{cx:"12",cy:"12",r:"10",stroke:u.spinnerTrackColor,strokeWidth:"3"}),g("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:u.spinnerAccentColor})]}),e==="success"&&g("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:I("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),g("path",{d:"M7 12.5l3 3 7-7",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",style:{strokeDasharray:20,strokeDashoffset:20,animation:"flopay-draw 0.4s 0.15s ease forwards"}})]})}),e==="error"&&g("div",{style:{animation:"flopay-shake 0.4s ease"},children:I("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[g("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),g("path",{d:"M8 8l8 8M16 8l-8 8",stroke:"white",strokeWidth:"2.5",strokeLinecap:"round",style:{strokeDasharray:12,strokeDashoffset:12,animation:"flopay-draw 0.3s 0.1s ease forwards"}})]})})]}),I("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:u.labelColors[e]},children:[e==="processing"&&n,e==="success"&&(o??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&i]}),e==="success"&&a!==null&&g("p",{style:s,children:a}),e==="error"&&r&&g("p",{style:s,children:r}),g("style",{children:`
|
|
2
|
-
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
|
-
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
|
-
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
|
-
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}var be=/^#([0-9a-f]{6})$/i,Oe=/^#([0-9a-f]{3})$/i,he=/^rgb\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*\)$/i,Ce=/^rgba\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(0|1|0?\.\d+|1\.0+)\s*\)$/i,Ie=/^linear-gradient\(\s*(-?\d+(?:\.\d+)?)deg\s*,\s*(.+)\)$/i,Me=/^(-?\d+(?:\.\d+)?)(?:px)?$/,_e=/^(-?\d+(?:\.\d+)?)em$/,Ne=/^blur\(\s*(\d+(?:\.\d+)?)(?:px)?\s*\)$/i,De=/^[a-z][a-z0-9 -]{0,31}$/i,ze=new Set(["none","uppercase","lowercase","capitalize"]);function Se(e){if(typeof e!="string")return null;let r=e.trim(),t=be.exec(r);if(t){let l=Number.parseInt(t[1],16);return{r:l>>16&255,g:l>>8&255,b:l&255,a:null}}let n=Oe.exec(r);if(n){let[l,f,y]=n[1].split("").map(p=>Number.parseInt(p+p,16));return{r:l,g:f,b:y,a:null}}let o=he.exec(r),i=o?null:Ce.exec(r),a=o??i;if(!a)return null;let u=Number(a[1]),s=Number(a[2]),c=Number(a[3]);return u>255||s>255||c>255?null:{r:u,g:s,b:c,a:i?Number(i[4]):null}}function ke({r:e,g:r,b:t,a:n}){return n===null?`#${(1<<24|e<<16|r<<8|t).toString(16).slice(1)}`:`rgba(${e},${r},${t},${n})`}function z(e){if(typeof e!="string")return;let r=e.trim();if(be.test(r)||he.test(r))return r;let t=Ce.exec(r);if(t&&/^\d/.test(t[4]))return r;let n=Se(r);return n?ke(n):void 0}function U(e,r=.12){let t=Se(e);if(!t)return e;let n=Math.max(0,Math.min(1,1-r));return ke({r:Math.round(t.r*n),g:Math.round(t.g*n),b:Math.round(t.b*n),a:t.a})}function W(e,r){let t=[],n=0,o="";for(let i of e){if(i==="("&&(n+=1),i===")"&&(n-=1),i===r&&n===0){o.trim()&&t.push(o.trim()),o="";continue}o+=i}return o.trim()&&t.push(o.trim()),t}function A(e,r,t){if(typeof e!="number"&&typeof e!="string")return;let n=Me.exec(String(e).trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function We(e,r,t){if(typeof e!="string")return;let n=_e.exec(e.trim());if(!n)return;let o=Number(n[1]);return Number.isFinite(o)&&o>=r&&o<=t?o:void 0}function $e(e){let r=W(e,",");if(r.length<2||r.length>5)return;let t=[];for(let[n,o]of r.entries()){let i=W(o," "),a=z(i[0]);if(!a)return;let u=n/(r.length-1)*100,s=i[1]===void 0?u:Number(/^(\d+(?:\.\d+)?)%$/.exec(i[1])?.[1]),c=t[t.length-1]?.position??-1;if(!Number.isFinite(s)||s<0||s>100||s<c)return;t.push({color:a,position:s})}return{type:"linearGradient",angle:0,stops:t}}function Ge(e){if(typeof e!="string")return;let r=e.trim(),t=z(r);if(t)return{type:"solid",color:t};let n=Ie.exec(r);if(!n)return;let o=Number(n[1]);if(!Number.isFinite(o)||o<0||o>360)return;let i=$e(n[2]);return i&&i.type==="linearGradient"?{...i,angle:o}:void 0}function He(e){return e.type==="solid"?{type:"solid",color:U(e.color)}:{...e,stops:e.stops.map(r=>({...r,color:U(r.color)}))}}function Ye(e){let r=!1,t,n=[];for(let s of W(e," ")){if(s.toLowerCase()==="inset"){r=!0;continue}let c=z(s);if(c){t=c;continue}let l=A(s,-128,128);if(l===void 0)return;n.push(l)}if(!t||n.length<2||n.length>4)return;let[o,i,a=0,u=0]=n;if(!(Math.abs(o)>64||Math.abs(i)>64||a>128||Math.abs(u)>32))return{color:t,inset:r,offsetX:o,offsetY:i,blur:a,spread:u}}function Ue(e){if(typeof e!="string")return;let r=e.trim();if(r.toLowerCase()==="none")return[];let t=W(r,",").map(Ye);if(!(t.length===0||t.length>4))return t.every(n=>n!==void 0)?t:void 0}function ye(e){if(typeof e!="string")return;let r=W(e,",").map(t=>t.replace(/^['"]|['"]$/g,"").trim()).filter(t=>De.test(t)).slice(0,4);return r.length>0?r:void 0}function Xe(e){let r=typeof e=="string"?e.trim().split(/\s+/):[e],t=A(r[0],0,64),n=A(r[1]??r[0],0,64);if(!(t===void 0||n===void 0))return{paddingBlock:t,paddingInline:n}}function je(e){if(e==="bold")return 700;if(e==="normal")return 400;let r=Number(e);return Number.isInteger(r)&&r>=100&&r<=900?r:void 0}function we({appearance:e,buttonsStyles:r,fontFamily:t}){let n=r.submitButton;if(!n)return;let o=e?.variables,i=Ge(n.background??n.backgroundColor),a=z(o?.colorPrimaryHover),u=a?{type:"solid",color:a}:i&&He(i),s={fontFamilies:ye(n.fontFamily)??ye(t),fontSize:A(n.fontSize??r.submitButtonFontSize,10,32)??16,fontWeight:je(n.fontWeight)??600,letterSpacing:We(n.letterSpacing,-.1,.5)??.01,lineHeight:A(n.lineHeight,.8,2)??1,textTransform:ze.has(String(n.textTransform))?n.textTransform:"uppercase"},c=Xe(n.padding),l=Ue(n.boxShadow),f=A(n.borderRadius,0,9999),y=typeof n.backdropFilter=="string"?A(Ne.exec(n.backdropFilter.trim())?.[1],0,40):void 0;return{foregroundColor:z(n.color)??"#FFFFFF",...i?{background:i,disabledBackground:i}:{},...u?{hoverBackground:u}:{},typography:s,...c?{spacing:c}:{},...l?{shadow:l}:{},...f===void 0?{}:{borderRadius:f},disabledOpacity:e?.theme==="night"?.8:.6,...y===void 0?{}:{backdropBlur:y}}}function qe(e,r=.12){let t=e.trim(),n=/^[0-9a-fA-F]{6}$/.test(t)?`#${t}`:t;return/^#[0-9a-fA-F]{6}$/.test(n)?U(n,r):e}function Ke(e){if(typeof e=="number"||typeof e=="string")return e}function xe({appearance:e,buttonsStyles:r,layout:t="default"}){let n=e?.variables,o=f=>typeof f=="string"&&f?f:void 0,i=r.submitButton,a=o(n?.colorPrimary)??o(i?.backgroundColor)??"#4A49FF",u=t==="buttons",s=r.nameInput,c=o(s?.fontFamily)??o(n?.fontFamily)??"Poppins, sans-serif",l=we({appearance:e,buttonsStyles:r,fontFamily:c});return{primaryColor:a,primaryHoverColor:o(n?.colorPrimaryHover)??qe(a,.12),inputBackgroundColor:o(r.cardInputBackground)??o(n?.colorBackground)??"#ffffff",textColor:o(r.cardInputColor)??o(s?.color)??o(n?.colorText)??"#262833",borderColor:o(r.cardInputBorder)??(u?"#e5e7eb":"#A4A4FF"),placeholderColor:o(r.cardInputPlaceholderColor)??"#9ca3af",errorColor:o(n?.colorDanger)??"#dc2626",successColor:"#16a34a",fontFamily:c,fontSize:o(r.cardInputFontSize)??o(n?.fontSizeBase)??"16px",fontWeight:String(Ke(s?.fontWeight)??400),borderRadius:o(n?.borderRadius)??"8px",...l?{submitButton:l}:{}}}import{Fragment as Ee,jsx as j,jsxs as nr}from"react/jsx-runtime";var ne=class extends M{constructor(r,t,n){super(r,t,n),this.name="FloPayCardSetupError",this.retryable=n.retryable}};function ve(e,r={}){let t=e instanceof M?e:void 0,n=t?.statusCode,o=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof n=="number"&&n>=500||t?.code==="vault_capture_timeout"||!t);return new ne(t?.message??(e instanceof Error?e.message:"Failed to load the secure card form."),t?.type??"api_error",{code:r.code??t?.code??"card_setup_load_failed",retryable:o,...t?.param?{param:t.param}:{},...n===void 0?{}:{statusCode:n}})}function Pr({sessionId:e,nonce:r,billingApiUrl:t,telemetry:n,theme:o="modern-light",containerStyle:i,loading:a=null,onReady:u,onComplete:s,onDecline:c,onCancel:l,onValidation:f,onError:y}){let[p,T]=$(null),[k,C]=$(null),[P,L]=$(null),[w,m]=$(null),[G,B]=$(null),x=h(!1),_=h(!1),b=X(()=>typeof o=="object"?void 0:tr(o),[o]),H=X(()=>typeof o=="object"?o:b?xe({appearance:b.appearance,buttonsStyles:b.buttonsLayout,layout:"default"}):null,[b,o]),q=X(()=>le(b?.buttonsLayout.cardFormContainer,i),[b,i]),S=X(()=>b?me(b):void 0,[b]),oe=h(u),K=h(y),ie=h(s),ae=h(c),se=h(l),ue=h(f),N=h(!1),Z=h(!1),J=h(0);return oe.current=u,K.current=y,ie.current=s,ae.current=c,se.current=l,ue.current=f,te(()=>{let d=J.current+1;return J.current=d,()=>{queueMicrotask(()=>{J.current===d&&(N.current||Z.current||(Z.current=!0,F(()=>{se.current?.({status:"cancelled",sessionId:e})})))})}},[e]),te(()=>{let d=!0,V=new Je(rr(t),{telemetry:n});return T(null),C(null),L(null),N.current=!1,Z.current=!1,(async()=>{try{if(!e.trim())throw new M("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new M("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let D=await V.getUnifiedCheckoutSession(e,r);if(!d)return;let R=D.data.session;if(!R||!er(R))throw new M("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let O=R.vault;if(O?.html?.trim()||(O=await V.getVaultCapture(e,r)),!O.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!d)return;C(O),T(new Qe({sessionId:e,operation:"card_setup",telemetry:n}))}catch(D){if(!d)return;let R=ve(D);N.current=!0,L(R),F(()=>K.current?.(R))}})(),()=>{d=!1,V.destroy()}},[t,r,e,n]),te(()=>{if(!p)return;let d=!1;_.current=!1,x.current=!1;let V=p.on("submitting",()=>{x.current=!0,B(null),m("processing")}),D=p.on("complete",v=>{N.current=!0,x.current=!1,m("success"),(async()=>(await new Promise(Q=>setTimeout(Q,600)),!_.current&&(_.current=!0,F(()=>{ie.current?.({status:"succeeded",sessionId:e,...v.paymentMethod?{paymentMethod:v.paymentMethod}:{}})}),d||m(null))))()}),R=p.on("decline",v=>{N.current=!0,x.current=!1,B(v.message??null),m("error"),F(()=>{ae.current?.({status:"declined",sessionId:e,...v.declineReason?{reason:v.declineReason}:{},...v.message?{message:v.message}:{}})}),(async()=>(await new Promise(Q=>setTimeout(Q,400)),d||m(null)))()}),O=p.on("challenge_dismissed",()=>{m(null)});return()=>{d=!0,V(),D(),R(),O()}},[p,e]),P?j("div",{role:"alert",children:P.message}):!p||!k?.html?j(Ee,{children:a}):nr(Ee,{children:[w&&j(ge,{status:w,errorMessage:G,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...S?{theme:S}:{}}),j(fe,{capture:p,html:k.html,messageToken:k.messageToken,expectedOrigin:k.expectedOrigin,theme:H,containerStyle:q,onReady:()=>{F(()=>oe.current?.())},onValidation:d=>{F(()=>ue.current?.(d))},onError:d=>{if(!d)return;x.current&&(x.current=!1,B(d),m("error"),setTimeout(()=>m(null),400));let V=ve(new Error(d),{code:"card_setup_widget_failed",retryable:!0});F(()=>K.current?.(V))}})]})}export{le as a,me as b,F as c,ge as d,de as e,fe as f,cr as g,qe as h,Ke as i,xe as j,ne as k,ve as l,Pr as m};
|
package/dist/chunk-LIYRDFMO.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{a as De,b as Le,c as P,d as Oe,f as Ie,g as Be,j as xe,l as F}from"./chunk-AZRGKPW7.mjs";import{PaymentAPI as Ke,PciVaultCardCapture as lt}from"@flopay/js/card-setup";import{FloPayError as M,isCardSetupCheckoutSession as ut,resolveBillingApiUrl as ae,resolveTheme as ct}from"@flopay/shared";import dt,{Suspense as ze,useCallback as V,useEffect as oe,useMemo as B,useRef as m,useState as w}from"react";import{PAYPAL_VAULTED_PAYMENT_METHOD_TYPE as tt}from"@flopay/shared";var rt=new Set(["apple_pay","google_pay","link","paypal","amazon_pay"]),nt=new Set(["wallet","apm"]);function U(t){return typeof t=="string"&&t.trim().length>0}function at(t){if(typeof t!="object"||t===null)return!1;let o=t;return U(o.family)&&U(o.paymentMethodType)}function ot(t){let a=t.raw?.data?.currency;return U(a)?a.trim().toUpperCase():null}function Ne(t){let o=ot(t),a=t.data.session?.advertisedPaymentMethods;if(!Array.isArray(a))return{card:!0,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]};let i={card:!1,stripe:[],paypal:null,currency:o,skippedForMissingCurrency:[]},c=new Set;for(let u of a){if(!at(u)||c.has(u.paymentMethodType))continue;let{family:d,paymentMethodType:f,providerType:x,publishableKey:_}=u;if(d==="card"){if(f!=="card")continue;i.card=!0}else if(nt.has(d)){if(x!=="stripe"||f==="card"||!U(_))continue;if(o===null){i.skippedForMissingCurrency.includes(f)||i.skippedForMissingCurrency.push(f);continue}i.stripe.push({method:f,publishableKey:_,currency:o})}else if(d==="paypal"){if(f!==tt||x!=="paypal"||!U(_))continue;i.paypal={clientId:_,...U(u.environment)?{environment:u.environment}:{}}}else continue;c.add(f)}return i.paypal&&(i.stripe=i.stripe.filter(u=>u.method!=="paypal")),i}function j(t){return[...t.card?["card"]:[],...t.stripe.map(o=>o.method),...t.paypal?["paypal"]:[]]}function Ye(t){return j(t).length>0}function K(t){return rt.has(t)?"wallet":"apm"}var st=["setup_intent","setup_intent_client_secret","redirect_status"];function We(){if(typeof window>"u")return null;let t=new URLSearchParams(window.location.search);return!t.has("setup_intent")||!t.has("redirect_status")?null:{failed:t.get("redirect_status")==="failed"}}function He(){if(typeof window>"u")return;let t=new URL(window.location.href),o=!1;for(let a of st)t.searchParams.has(a)&&(t.searchParams.delete(a),o=!0);o&&window.history.replaceState(window.history.state,"",t.toString())}function Ge(t){return t==="card"?{processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED"}:{processingLabel:"SAVING PAYMENT METHOD...",successLabel:"PAYMENT METHOD SAVED",errorLabel:"PAYMENT METHOD NOT SAVED"}}import{Fragment as qe,jsx as y,jsxs as ie}from"react/jsx-runtime";var pt=15,mt=2e3;function yt(t){return{userId:t.customer?.id??"",email:t.customer?.email??""}}function se(t){return new Promise(o=>setTimeout(o,t))}async function ft(t,o,a){if(!o.trim())throw new M("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new M("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let i=await t.getUnifiedCheckoutSession(o,a),c=i.data.session;if(!c||!ut(c))throw new M("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let u=Ne(i);if(!Ye(u)){let{skippedForMissingCurrency:d}=u,f=d.length>0?`FloPay: this setup session advertises only Stripe methods (${d.join(", ")}), and they need the session's currency, which the setup-session read did not carry.`:"FloPay: this setup session advertises no payment method.";throw new M(f,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:c,advertisement:u}}async function ht(t,o,a,i){let c=o.vault??null;if(c?.html?.trim()||(c=await t.getVaultCapture(a,i)),!c.html?.trim())throw new M("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return c}var z=class extends dt.Component{constructor(){super(...arguments);this.state={failed:!1}}static getDerivedStateFromError(){return{failed:!0}}componentDidCatch(a){this.props.onFailed(a,{code:"payment_method_setup_load_failed",retryable:!1})}render(){return this.state.failed?null:this.props.children}};function kt({branches:{StripeSetupMethod:t,PayPalSetupMethod:o},sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,theme:d="modern-light",containerStyle:f,loading:x=null,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe}){let[q]=w(We),[N,$]=w(null),[$e,J]=w(!1),[g,me]=w(null),[D,ye]=w(null),[fe,he]=w(null),[Y,h]=w(null),[Q,X]=w(()=>new Set),R=m(Q),Z=m(null);Z.current=N;let v=m(!1),ee=m(!1),L=m(!1),te=m(!1),re=m(0),W=m(0),A=m(!1),S=B(()=>typeof d=="object"?void 0:ct(d),[d]),Je=B(()=>typeof d=="object"?d:S?xe({appearance:S.appearance,buttonsStyles:S.buttonsLayout,layout:"default"}):null,[S,d]),Qe=B(()=>De(S?.buttonsLayout.cardFormContainer,f),[S,f]),Se=B(()=>S?Le(S):void 0,[S]),p=m({sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe});p.current={sessionId:a,nonce:i,billingApiUrl:c,telemetry:u,onReady:_,onComplete:le,onDecline:ue,onCancel:ce,onValidation:de,onError:pe},oe(()=>{A.current=!0;let e=re.current+1;return re.current=e,()=>{A.current=!1,W.current+=1,queueMicrotask(()=>{re.current===e&&(L.current||te.current||(te.current=!0,P(()=>{p.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let k=V((e,r)=>{L.current=!0,v.current=!1,h({status:"success",wording:e,message:null}),(async()=>(await se(600),!ee.current&&(ee.current=!0,P(()=>{p.current.onComplete?.({status:"succeeded",sessionId:p.current.sessionId,...r?{paymentMethod:r}:{}})}),A.current&&h(null))))()},[]),T=V((e,r)=>{L.current=!0,v.current=!1,h({status:"error",wording:e,message:r.message??null}),P(()=>{p.current.onDecline?.({status:"declined",sessionId:p.current.sessionId,...r.reason?{reason:r.reason}:{},...r.message?{message:r.message}:{}})}),(async()=>(await se(400),A.current&&h(null)))()},[]),C=V((e,r)=>{v.current?(v.current=!1,h({status:"error",wording:e,message:r.message}),setTimeout(()=>{A.current&&h(null)},400)):h(null),P(()=>p.current.onError?.(r))},[]),H=V(async e=>{let r=W.current+1;W.current=r;let s=()=>!A.current||r!==W.current;v.current=!0,h({status:"processing",wording:"payment_method",message:null});let l=new Ke(ae(p.current.billingApiUrl),{telemetry:p.current.telemetry});try{for(let n=0;n<pt;n+=1){if((n>0||e.waitFirst)&&await se(mt),s())return;let b=await l.getUnifiedCheckoutSession(p.current.sessionId,p.current.nonce);if(s())return;let E=b.data.session?.status;if(E==="complete"){J(!0),k("payment_method");return}if(E==="expired")throw new M("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new M("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(n){if(s())return;let b=n instanceof M&&n.code==="payment_method_setup_unverified";C("payment_method",F(n,b?{retryable:!0}:{}))}finally{l.destroy()}},[C,k]);oe(()=>{let e=!0,r=new Ke(ae(c),{telemetry:u});$(null),J(!1),me(null),ye(null),he(null);let s=new Set;return R.current=s,X(s),L.current=!1,te.current=!1,ee.current=!1,(async()=>{try{let{session:l,advertisement:n}=await ft(r,a,i);if(!e)return;let b={advertisement:n,customer:yt(l),...l.futureUse?{futureUse:l.futureUse}:{},...l.futureUseUnsupported?{futureUseUnsupported:l.futureUseUnsupported}:{}};if(q){if(He(),l.status==="complete"){J(!0),$(b),k("payment_method");return}q.failed?T("payment_method",{reason:"redirect_failed"}):H({waitFirst:!0})}let E=n.card?await ht(r,l,a,i):null;if(!e)return;$(b),E&&(ye(E),me(new lt({sessionId:a,operation:"card_setup",telemetry:u})))}catch(l){if(!e)return;let n=F(l);L.current=!0,he(n),P(()=>p.current.onError?.(n))}})(),()=>{e=!1,r.destroy()}},[c,i,q,T,k,a,u,H]),oe(()=>{if(!g)return;v.current=!1;let e=g.on("submitting",()=>{v.current=!0,h({status:"processing",wording:"card",message:null})}),r=g.on("complete",n=>{k("card",n.paymentMethod)}),s=g.on("decline",n=>{T("card",{...n.declineReason?{reason:n.declineReason}:{},...n.message?{message:n.message}:{}})}),l=g.on("challenge_dismissed",()=>{h(null)});return()=>{e(),r(),s(),l()}},[g,T,k]);let ge=V((e,r,s)=>{if(s.retryable){C("payment_method",F(r,s));return}if(R.current.has(e))return;let l=new Set(R.current);l.add(e),R.current=l,X(l);let n=Z.current?.advertisement,b=n?j(n).some(E=>!l.has(E)):!1;C("payment_method",F(r,{code:s.code,retryable:b}))},[C]),ve=B(()=>({onSubmitting:()=>{v.current=!0,h({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{H({waitFirst:!1})},onDeclined:e=>T("payment_method",e),onValidation:e=>{P(()=>p.current.onValidation?.(e))},onAbandoned:()=>{v.current=!1,h(null)}}),[T,H]),Pe=m(ge);Pe.current=ge;let Ce=m(new Map),G=e=>{let r=Ce.current.get(e);if(r)return r;let s=(l,n)=>Pe.current(e,l,n);return Ce.current.set(e,s),s},be=V(e=>{if(R.current.has(e))return;let r=new Set(R.current);r.add(e),R.current=r,X(r);let s=Z.current?.advertisement;s&&j(s).some(n=>!r.has(n))||C("payment_method",F(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[C]),we=m(be);we.current=be;let Me=m(new Map),_e=e=>{let r=Me.current.get(e);if(r)return r;let s=()=>we.current(e);return Me.current.set(e,s),s},Re=Y?y(Oe,{status:Y.status,errorMessage:Y.message,...Ge(Y.wording),successNote:null,...Se?{theme:Se}:{}}):null;if(fe)return y("div",{role:"alert",children:fe.message});if(!N||$e)return ie(qe,{children:[Re,N?null:x]});let{advertisement:O,customer:Xe,futureUse:Ee,futureUseUnsupported:Fe}=N,Ae=ae(c),ke=u===void 0?{}:{telemetry:u},ne=O.stripe.filter(({method:e})=>!Q.has(e)),I=Q.has("paypal")?null:O.paypal,Te=!!(O.card&&g&&D?.html),Ue=({method:e,publishableKey:r,currency:s})=>y("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:y(z,{onFailed:G(e),children:y(ze,{fallback:null,children:y(t,{method:e,category:K(e),publishableKey:r,currency:s,...Ee?{futureUse:Ee}:{},...Fe?{futureUseUnsupported:Fe}:{},sessionId:a,nonce:i,billingApiUrl:Ae,...ke,...S?{appearance:S.appearance,buttonsLayout:S.buttonsLayout}:{},...typeof d=="string"?{themeId:d}:{},...ve,onFailed:G(e),onUnavailable:_e(e)})})})},e),Ze=ne.filter(({method:e})=>K(e)==="wallet"),et=ne.filter(({method:e})=>K(e)!=="wallet"),Ve=ne.length>0||I!==null;return ie(qe,{children:[Re,Ve?ie("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[Ze.map(Ue),I?y("div",{"data-flopay-payment-method":"paypal",children:y(z,{onFailed:G("paypal"),children:y(ze,{fallback:null,children:y(o,{clientId:I.clientId,...I.environment?{environment:I.environment}:{},...O.currency?{currency:O.currency}:{},sessionId:a,nonce:i,billingApiUrl:Ae,customer:Xe,...ke,...ve,onFailed:G("paypal"),onUnavailable:_e("paypal")})})})}):null,et.map(Ue)]}):null,Te&&Ve?y(Be,{label:"or add a card"}):null,Te&&g&&D?.html?y("div",{"data-flopay-payment-method":"card",children:y(Ie,{capture:g,html:D.html,messageToken:D.messageToken,expectedOrigin:D.expectedOrigin,theme:Je,containerStyle:Qe,onReady:()=>{P(()=>p.current.onReady?.())},onValidation:e=>{P(()=>p.current.onValidation?.(e))},onError:e=>{e&&C("card",F(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{kt as a};
|
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};
|