@flopay/react 1.20.11 → 1.20.13
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-ITRFSHZP.mjs +6 -0
- package/dist/{chunk-D4CVZRT4.mjs → chunk-PCIHQY3X.mjs} +1 -1
- package/dist/index.cjs +8 -8
- package/dist/index.mjs +4 -4
- package/dist/payment-method-setup-entry.cjs +3 -3
- package/dist/payment-method-setup-entry.mjs +1 -1
- package/dist/vault-card-fields.d.ts +3 -1
- package/package.json +3 -3
- package/dist/chunk-YR36EYW2.mjs +0 -6
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var J=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var ge=Object.getOwnPropertyNames;var Ce=Object.prototype.hasOwnProperty;var Se=(e,r)=>{for(var t in r)J(e,t,{get:r[t],enumerable:!0})},he=(e,r,t,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of ge(r))!Ce.call(e,i)&&i!==t&&J(e,i,{get:()=>r[i],enumerable:!(o=ye(r,i))||o.enumerable});return e};var ve=e=>he(J({},"__esModule",{value:!0}),e);var Te={};Se(Te,{FloPayCardSetup:()=>me,FloPayCardSetupError:()=>B});module.exports=ve(Te);var q=require("@flopay/js/card-setup"),l=require("@flopay/shared"),n=require("react");var K=require("@flopay/shared"),Re=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 be(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return Re.has(r.charAt(0).toLowerCase()+r.slice(1))}function Ee(e,r){return typeof r=="number"&&r!==0&&!be(e)?`${r}px`:String(r).trim()}function ie(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]=Ee(t,o)}}}var Q=require("@flopay/shared"),we=require("@flopay/shared");function le(e){let r=(0,Q.resolveCardSetupTheme)(e);return{...r,surface:r.surface,overlayTheme:r.overlayTheme}}var S=require("@flopay/shared");var a=require("react/jsx-runtime");var Pe={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function ue({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:i,errorLabel:E="PAYMENT FAILED",successNote:u="You will be automatically redirected, do not close or navigate away from this window.",theme:m=Pe}){let w={fontSize:13,color:m.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return(0,a.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,a.jsxs)("div",{"data-testid":"flopay-processing-overlay-panel",style:{borderRadius:12,boxShadow:"0 8px 32px rgba(0,0,0,0.18)",...m.panel,padding:"2rem 2.5rem",textAlign:"center",minWidth:240,display:"flex",flexDirection:"column",alignItems:"center",gap:16},children:[(0,a.jsxs)("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&(0,a.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,a.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:m.spinnerTrackColor,strokeWidth:"3"}),(0,a.jsx)("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:m.spinnerAccentColor})]}),e==="success"&&(0,a.jsx)("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:(0,a.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,a.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),(0,a.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,a.jsx)("div",{style:{animation:"flopay-shake 0.4s ease"},children:(0,a.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,a.jsx)("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),(0,a.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,a.jsxs)("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:m.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(i??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&E]}),e==="success"&&u!==null&&(0,a.jsx)("p",{style:w,children:u}),e==="error"&&r&&(0,a.jsx)("p",{style:w,children:r}),(0,a.jsx)("style",{children:`
|
|
2
2
|
@keyframes flopay-spin { to { transform: rotate(360deg); } }
|
|
3
3
|
@keyframes flopay-pop { 0% { transform: scale(0); } 100% { transform: scale(1); } }
|
|
4
4
|
@keyframes flopay-draw { to { stroke-dashoffset: 0; } }
|
|
5
5
|
@keyframes flopay-shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-4px); } 40%,80% { transform: translateX(4px); } }
|
|
6
|
-
`})]})})}var
|
|
6
|
+
`})]})})}var c=require("react");var H=require("react"),ce=typeof window>"u"?H.useEffect:H.useLayoutEffect;var re=require("react/jsx-runtime"),ee=new WeakSet;function de({capture:e,html:r,messageToken:t,expectedOrigin:o,expiresAt:i,verificationRequired:E,theme:u,submitLabel:m,containerStyle:w,onReady:_,onError:M,onValidation:V}){let T=(0,c.useRef)(null),D=(0,c.useRef)(_),k=(0,c.useRef)(M),f=(0,c.useRef)(V);D.current=_,k.current=M,f.current=V;let P=(0,c.useRef)(u);P.current=u;let y=(0,c.useRef)(null),g=m??void 0,x=(0,c.useRef)(g);x.current=g;let O=(0,c.useRef)(void 0);return(0,c.useEffect)(()=>{let h=T.current;if(!h)return;let d=!0,Y=!1,F=()=>{!d||Y||(Y=!0,D.current?.())},v=e.on("ready",()=>{F()}),I=e.on("error",R=>{k.current?.(R.message??"There was a problem loading the secure card form.")}),X=e.on("validation",R=>{f.current?.(R.message??null)}),N=x.current??(ee.has(e)?null:void 0),G={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...typeof i=="string"?{expiresAt:i}:{},...E?{verificationRequired:!0}:{},...P.current?{theme:P.current}:{},...N===void 0?{}:{submitLabel:N}};return y.current=P.current??null,O.current=x.current,x.current!==void 0&&ee.add(e),e.mount(h,G).then(()=>{F()}).catch(R=>{d&&k.current?.(R instanceof Error?R.message:"Failed to load the secure card form.")}),()=>{d=!1,v(),I(),X(),e.unmount()}},[e,r,t,o,i,E]),ce(()=>{let h=T.current;h&&ie(h,w)},[w]),(0,c.useEffect)(()=>{u!==void 0&&(u===null&&y.current===null||(y.current=u,e.applyTheme?.(u)))},[e,u]),(0,c.useEffect)(()=>{g!==O.current&&(O.current=g,g!==void 0&&ee.add(e),e.setSubmitLabel?.(g??null))},[e,g]),(0,re.jsx)("div",{ref:T,"data-testid":"flopay-vault-card-fields"})}var C=require("react/jsx-runtime"),B=class extends l.FloPayError{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function fe(e,r={}){let t=e instanceof l.FloPayError?e:void 0,o=t?.statusCode,i=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof o=="number"&&o>=500||t?.code==="vault_capture_timeout"||!t);return new B(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:i,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}function me({sessionId:e,nonce:r,billingApiUrl:t,telemetry:o,theme:i="modern-light",containerStyle:E,appearance:u,buttonsStyles:m,loading:w=null,onReady:_,onComplete:M,onDecline:V,onCancel:T,onValidation:D,onError:k}){let[f,P]=(0,n.useState)(null),[y,g]=(0,n.useState)(null),[x,O]=(0,n.useState)(null),[h,d]=(0,n.useState)(null),[Y,F]=(0,n.useState)(null),v=(0,n.useRef)(!1),I=(0,n.useRef)(!1),{vaultTheme:X,surface:N,overlayTheme:G}=(0,n.useMemo)(()=>le({theme:i,appearance:u,buttonsStyles:m}),[i,u,m]),R=(0,n.useMemo)(()=>(0,K.mergeCardSetupSurface)(N,E),[N,E]),te=(0,n.useRef)(_),j=(0,n.useRef)(k),oe=(0,n.useRef)(M),ne=(0,n.useRef)(V),ae=(0,n.useRef)(T),se=(0,n.useRef)(D),U=(0,n.useRef)(!1),Z=(0,n.useRef)(!1),$=(0,n.useRef)(0);return te.current=_,j.current=k,oe.current=M,ne.current=V,ae.current=T,se.current=D,(0,n.useEffect)(()=>{let s=$.current+1;return $.current=s,()=>{queueMicrotask(()=>{$.current===s&&(U.current||Z.current||(Z.current=!0,(0,S.invokeMerchantCallback)(()=>{ae.current?.({status:"cancelled",sessionId:e})})))})}},[e]),(0,n.useEffect)(()=>{let s=!0,A=(0,l.resolveBillingApiUrl)(t),W=new q.PaymentAPI(A,{telemetry:o});return P(null),g(null),O(null),U.current=!1,Z.current=!1,(async()=>{try{if(!e.trim())throw new l.FloPayError("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new l.FloPayError("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let z=await W.getUnifiedCheckoutSession(e,r);if(!s)return;let b=z.data.session;if(!b||!(0,l.isCardSetupCheckoutSession)(b))throw new l.FloPayError("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let p=b.vault;(0,l.isMountableVaultBlock)(p)||(p=await W.getVaultCapture(e,r));let L=(0,l.resolveVaultMountOptions)(p,{billingApiUrl:A,sessionId:e,nonce:r});if(!L)throw new l.FloPayError("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!s)return;g(L),P(new q.PciVaultCardCapture({sessionId:e,operation:"card_setup",telemetry:o}))}catch(z){if(!s)return;let b=fe(z);U.current=!0,O(b),(0,S.invokeMerchantCallback)(()=>j.current?.(b))}})(),()=>{s=!1,W.destroy()}},[t,r,e,o]),(0,n.useEffect)(()=>{if(!f)return;let s=!1;I.current=!1,v.current=!1;let A=f.on("submitting",()=>{v.current=!0,F(null),d("processing")}),W=f.on("complete",p=>{U.current=!0,v.current=!1,d("success"),(async()=>(await new Promise(L=>setTimeout(L,600)),!I.current&&(I.current=!0,(0,S.invokeMerchantCallback)(()=>{oe.current?.({status:"succeeded",sessionId:e,...p.paymentMethod?{paymentMethod:p.paymentMethod}:{}})}),s||d(null))))()}),z=f.on("decline",p=>{U.current=!0,v.current=!1,F(p.message??null),d("error"),(0,S.invokeMerchantCallback)(()=>{ne.current?.({status:"declined",sessionId:e,...p.declineReason?{reason:p.declineReason}:{},...p.message?{message:p.message}:{}})}),(async()=>(await new Promise(L=>setTimeout(L,400)),s||d(null)))()}),b=f.on("challenge_dismissed",()=>{d(null)});return()=>{s=!0,A(),W(),z(),b()}},[f,e]),x?(0,C.jsx)("div",{role:"alert",children:x.message}):!f||!y?.html?(0,C.jsx)(C.Fragment,{children:w}):(0,C.jsxs)(C.Fragment,{children:[h&&(0,C.jsx)(ue,{status:h,errorMessage:Y,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...G?{theme:G}:{}}),(0,C.jsx)(de,{capture:f,html:y.html,messageToken:y.messageToken,expectedOrigin:y.expectedOrigin,expiresAt:y.expiresAt,verificationRequired:y.verificationRequired,theme:X,containerStyle:R,onReady:()=>{(0,S.invokeMerchantCallback)(()=>te.current?.())},onValidation:s=>{(0,S.invokeMerchantCallback)(()=>se.current?.(s))},onError:s=>{if(!s)return;v.current&&(v.current=!1,F(s),d("error"),setTimeout(()=>d(null),400));let A=fe(new Error(s),{code:"card_setup_widget_failed",retryable:!0});(0,S.invokeMerchantCallback)(()=>j.current?.(A))}})]})}0&&(module.exports={FloPayCardSetup,FloPayCardSetupError});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{h as e,j as t}from"./chunk-
|
|
1
|
+
import{h as e,j as t}from"./chunk-ITRFSHZP.mjs";export{t as FloPayCardSetup,e as FloPayCardSetupError};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{useEffect as J,useRef as S}from"react";import{mergeCardSetupSurface as ie}from"@flopay/shared";var ge=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 Ce(e){let r=e.replace(/^(Webkit|Moz|ms)(?=[A-Z])/,"");return ge.has(r.charAt(0).toLowerCase()+r.slice(1))}function he(e,r){return typeof r=="number"&&r!==0&&!Ce(e)?`${r}px`:String(r).trim()}function se(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]=he(t,o)}}}import{useEffect as Se,useLayoutEffect as ve}from"react";var le=typeof window>"u"?Se:ve;import{jsx as H,jsxs as Re}from"react/jsx-runtime";var K=new WeakSet;function ue({capture:e,html:r,messageToken:t,expectedOrigin:o,expiresAt:d,verificationRequired:R,theme:a,submitLabel:p,containerStyle:b,onReady:_,onError:M,onValidation:V}){let x=S(null),D=S(_),P=S(M),u=S(V);D.current=_,P.current=M,u.current=V;let E=S(a);E.current=a;let f=S(null),m=p??void 0,w=S(m);w.current=m;let T=S(void 0);return J(()=>{let y=x.current;if(!y)return;let s=!0,Y=!1,k=()=>{!s||Y||(Y=!0,D.current?.())},g=e.on("ready",()=>{k()}),I=e.on("error",C=>{P.current?.(C.message??"There was a problem loading the secure card form.")}),X=e.on("validation",C=>{u.current?.(C.message??null)}),N=w.current??(K.has(e)?null:void 0),G={html:r,...t?{messageToken:t}:{},...o?{expectedOrigin:o}:{},...typeof d=="string"?{expiresAt:d}:{},...R?{verificationRequired:!0}:{},...E.current?{theme:E.current}:{},...N===void 0?{}:{submitLabel:N}};return f.current=E.current??null,T.current=w.current,w.current!==void 0&&K.add(e),e.mount(y,G).then(()=>{k()}).catch(C=>{s&&P.current?.(C instanceof Error?C.message:"Failed to load the secure card form.")}),()=>{s=!1,g(),I(),X(),e.unmount()}},[e,r,t,o,d,R]),le(()=>{let y=x.current;y&&se(y,b)},[b]),J(()=>{a!==void 0&&(a===null&&f.current===null||(f.current=a,e.applyTheme?.(a)))},[e,a]),J(()=>{m!==T.current&&(T.current=m,m!==void 0&&K.add(e),e.setSubmitLabel?.(m??null))},[e,m]),H("div",{ref:x,"data-testid":"flopay-vault-card-fields"})}function Ue({label:e}){return Re("div",{style:{display:"flex",alignItems:"center",gap:"0.75rem",margin:"0.5rem 0 0.75rem",color:"#999",fontSize:"0.85rem"},children:[H("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}}),H("span",{children:e}),H("div",{style:{flex:1,height:1,backgroundColor:"#ddd"}})]})}import{PaymentAPI as xe,PciVaultCardCapture as Pe}from"@flopay/js/card-setup";import{FloPayError as F,isCardSetupCheckoutSession as Te,isMountableVaultBlock as ke,resolveBillingApiUrl as Oe,resolveVaultMountOptions as Ae}from"@flopay/shared";import{useEffect as Q,useMemo as fe,useRef as c,useState as B}from"react";import{computeCardSetupOverlayTheme as Ye,resolveCardSetupTheme as be}from"@flopay/shared";import{mergeButtonsStyles as qe}from"@flopay/shared";function ce(e){let r=be(e);return{...r,surface:r.surface,overlayTheme:r.overlayTheme}}import{invokeMerchantCallback as v}from"@flopay/shared";import{jsx as l,jsxs as L}from"react/jsx-runtime";var Ee={panel:{background:"white"},spinnerTrackColor:"#e5e7eb",spinnerAccentColor:"#4A49FF",labelColors:{processing:"#374151",success:"#16a34a",error:"#dc2626"},noteColor:"#6b7280"};function de({status:e,errorMessage:r,authorized:t=!1,processingLabel:o="PROCESSING...",successLabel:d,errorLabel:R="PAYMENT FAILED",successNote:a="You will be automatically redirected, do not close or navigate away from this window.",theme:p=Ee}){let b={fontSize:13,color:p.noteColor,fontWeight:400,maxWidth:260,lineHeight:1.4,margin:0};return l("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:L("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:[L("div",{style:{width:48,height:48,position:"relative"},children:[e==="processing"&&L("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:[l("circle",{cx:"12",cy:"12",r:"10",stroke:p.spinnerTrackColor,strokeWidth:"3"}),l("path",{d:"M4 12a8 8 0 018-8v3a5 5 0 00-5 5H4z",fill:p.spinnerAccentColor})]}),e==="success"&&l("div",{style:{animation:"flopay-pop 0.4s cubic-bezier(0.34,1.56,0.64,1)"},children:L("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[l("circle",{cx:"12",cy:"12",r:"11",fill:"#22c55e"}),l("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"&&l("div",{style:{animation:"flopay-shake 0.4s ease"},children:L("svg",{"aria-hidden":"true",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[l("circle",{cx:"12",cy:"12",r:"11",fill:"#ef4444"}),l("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"}})]})})]}),L("span",{style:{fontSize:14,fontWeight:600,letterSpacing:"0.05em",color:p.labelColors[e]},children:[e==="processing"&&o,e==="success"&&(d??(t?"PAYMENT AUTHORISED":"PAYMENT SUCCESSFUL")),e==="error"&&R]}),e==="success"&&a!==null&&l("p",{style:b,children:a}),e==="error"&&r&&l("p",{style:b,children:r}),l("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
|
+
`})]})})}import{Fragment as ye,jsx as q,jsxs as Le}from"react/jsx-runtime";var ee=class extends F{constructor(r,t,o){super(r,t,o),this.name="FloPayCardSetupError",this.retryable=o.retryable}};function me(e,r={}){let t=e instanceof F?e:void 0,o=t?.statusCode,d=r.retryable??(t?.type==="network_error"||t?.type==="rate_limit_error"||typeof o=="number"&&o>=500||t?.code==="vault_capture_timeout"||!t);return new ee(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:d,...t?.param?{param:t.param}:{},...o===void 0?{}:{statusCode:o}})}function ar({sessionId:e,nonce:r,billingApiUrl:t,telemetry:o,theme:d="modern-light",containerStyle:R,appearance:a,buttonsStyles:p,loading:b=null,onReady:_,onComplete:M,onDecline:V,onCancel:x,onValidation:D,onError:P}){let[u,E]=B(null),[f,m]=B(null),[w,T]=B(null),[y,s]=B(null),[Y,k]=B(null),g=c(!1),I=c(!1),{vaultTheme:X,surface:N,overlayTheme:G}=fe(()=>ce({theme:d,appearance:a,buttonsStyles:p}),[d,a,p]),C=fe(()=>ie(N,R),[N,R]),re=c(_),j=c(P),te=c(M),oe=c(V),ne=c(x),ae=c(D),U=c(!1),Z=c(!1),$=c(0);return re.current=_,j.current=P,te.current=M,oe.current=V,ne.current=x,ae.current=D,Q(()=>{let n=$.current+1;return $.current=n,()=>{queueMicrotask(()=>{$.current===n&&(U.current||Z.current||(Z.current=!0,v(()=>{ne.current?.({status:"cancelled",sessionId:e})})))})}},[e]),Q(()=>{let n=!0,O=Oe(t),W=new xe(O,{telemetry:o});return E(null),m(null),T(null),U.current=!1,Z.current=!1,(async()=>{try{if(!e.trim())throw new F("FloPayCardSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!r.trim())throw new F("FloPayCardSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let z=await W.getUnifiedCheckoutSession(e,r);if(!n)return;let h=z.data.session;if(!h||!Te(h))throw new F("FloPayCardSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidCardSetupSession",param:"sessionId"});let i=h.vault;ke(i)||(i=await W.getVaultCapture(e,r));let A=Ae(i,{billingApiUrl:O,sessionId:e,nonce:r});if(!A)throw new F("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});if(!n)return;m(A),E(new Pe({sessionId:e,operation:"card_setup",telemetry:o}))}catch(z){if(!n)return;let h=me(z);U.current=!0,T(h),v(()=>j.current?.(h))}})(),()=>{n=!1,W.destroy()}},[t,r,e,o]),Q(()=>{if(!u)return;let n=!1;I.current=!1,g.current=!1;let O=u.on("submitting",()=>{g.current=!0,k(null),s("processing")}),W=u.on("complete",i=>{U.current=!0,g.current=!1,s("success"),(async()=>(await new Promise(A=>setTimeout(A,600)),!I.current&&(I.current=!0,v(()=>{te.current?.({status:"succeeded",sessionId:e,...i.paymentMethod?{paymentMethod:i.paymentMethod}:{}})}),n||s(null))))()}),z=u.on("decline",i=>{U.current=!0,g.current=!1,k(i.message??null),s("error"),v(()=>{oe.current?.({status:"declined",sessionId:e,...i.declineReason?{reason:i.declineReason}:{},...i.message?{message:i.message}:{}})}),(async()=>(await new Promise(A=>setTimeout(A,400)),n||s(null)))()}),h=u.on("challenge_dismissed",()=>{s(null)});return()=>{n=!0,O(),W(),z(),h()}},[u,e]),w?q("div",{role:"alert",children:w.message}):!u||!f?.html?q(ye,{children:b}):Le(ye,{children:[y&&q(de,{status:y,errorMessage:Y,processingLabel:"SAVING CARD...",successLabel:"CARD SAVED",errorLabel:"CARD NOT SAVED",successNote:null,...G?{theme:G}:{}}),q(ue,{capture:u,html:f.html,messageToken:f.messageToken,expectedOrigin:f.expectedOrigin,expiresAt:f.expiresAt,verificationRequired:f.verificationRequired,theme:X,containerStyle:C,onReady:()=>{v(()=>re.current?.())},onValidation:n=>{v(()=>ae.current?.(n))},onError:n=>{if(!n)return;g.current&&(g.current=!1,k(n),s("error"),setTimeout(()=>s(null),400));let O=me(new Error(n),{code:"card_setup_widget_failed",retryable:!0});v(()=>j.current?.(O))}})]})}export{ie as a,ce as b,v as c,de as d,le as e,ue as f,Ue as g,ee as h,me as i,ar as j};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as Te,b as De,c as g,d as Le,f as Ne,g as We,i as w}from"./chunk-ITRFSHZP.mjs";import{PaymentAPI as ze,PciVaultCardCapture as ot}from"@flopay/js/card-setup";import{FloPayError as b,isCardSetupCheckoutSession as st,isMountableVaultBlock as it,resolveBillingApiUrl as Z,resolveVaultMountOptions as lt}from"@flopay/shared";import ut,{Suspense as $e,useCallback as k,useEffect as ee,useMemo as te,useRef as l,useState as P}from"react";import{clearSetupRedirectParams as Ye,readSetupRedirectReturn as qe}from"@flopay/js/card-setup";import{advertisedMethodKeys as X,advertisesAnyMethod as Ge,readSetupAdvertisement as Ke,setupOverlayLabels as je,stripeMethodCategory as N}from"@flopay/shared";import{Fragment as Je,jsx as d,jsxs as ne}from"react/jsx-runtime";var dt=15,ct=2e3;function pt(p){return{userId:p.customer?.id??"",email:p.customer?.email??""}}function re(p){return new Promise(h=>setTimeout(h,p))}async function mt(p,h,a){if(!h.trim())throw new b("FloPayPaymentMethodSetup requires a sessionId.","validation_error",{code:"MissingCheckoutSessionId",param:"sessionId"});if(!a.trim())throw new b("FloPayPaymentMethodSetup requires a session nonce.","validation_error",{code:"MissingCheckoutSessionToken",param:"nonce"});let u=await p.getUnifiedCheckoutSession(h,a),m=u.data.session;if(!m||!st(m))throw new b("FloPayPaymentMethodSetup only accepts a zero-amount, productless setup session.","validation_error",{code:"InvalidPaymentMethodSetupSession",param:"sessionId"});let o=Ke(u);if(!Ge(o)){let{skippedForMissingCurrency:f}=o,V=f.length>0?`FloPay: this setup session advertises only Stripe methods (${f.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 b(V,"validation_error",{code:"NoAdvertisedPaymentMethods",param:"sessionId"})}return{session:m,advertisement:o}}async function yt(p,h,a,u,m){let o=h.vault??null;it(o)||(o=await p.getVaultCapture(a,u));let f=lt(o,{billingApiUrl:m,sessionId:a,nonce:u});if(!f)throw new b("FloPay: this setup session has no vault card capability. Upgrade the billing backend integration.","api_error",{code:"UnsupportedBackendVaultCapability"});return f}var W=class extends ut.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 Et({branches:{StripeSetupMethod:p,PayPalSetupMethod:h},sessionId:a,nonce:u,billingApiUrl:m,telemetry:o,theme:f="modern-light",containerStyle:V,appearance:ae,buttonsStyles:oe,loading:Qe=null,onReady:se,onComplete:ie,onDecline:le,onCancel:ue,onValidation:de,onError:ce}){let[Y]=P(qe),[x,q]=P(null),[Xe,G]=P(!1),[v,pe]=P(null),[F,me]=P(null),[ye,fe]=P(null),[I,c]=P(null),[K,j]=P(()=>new Set),M=l(K),H=l(null);H.current=x;let S=l(!1),z=l(!1),A=l(!1),$=l(!1),J=l(0),T=l(0),_=l(!1),{vaultTheme:Ze,surface:he,overlayTheme:ve,appearance:Se,buttonsLayout:ge}=te(()=>De({theme:f,appearance:ae,buttonsStyles:oe}),[f,ae,oe]),et=te(()=>Te(he,V),[he,V]),s=l({sessionId:a,nonce:u,billingApiUrl:m,telemetry:o,onReady:se,onComplete:ie,onDecline:le,onCancel:ue,onValidation:de,onError:ce});s.current={sessionId:a,nonce:u,billingApiUrl:m,telemetry:o,onReady:se,onComplete:ie,onDecline:le,onCancel:ue,onValidation:de,onError:ce},ee(()=>{_.current=!0;let e=J.current+1;return J.current=e,()=>{_.current=!1,T.current+=1,queueMicrotask(()=>{J.current===e&&(A.current||$.current||($.current=!0,g(()=>{s.current.onCancel?.({status:"cancelled",sessionId:a})})))})}},[a]);let E=k((e,t)=>{A.current=!0,S.current=!1,c({status:"success",wording:e,message:null}),(async()=>(await re(600),!z.current&&(z.current=!0,g(()=>{s.current.onComplete?.({status:"succeeded",sessionId:s.current.sessionId,...t?{paymentMethod:t}:{}})}),_.current&&c(null))))()},[]),U=k((e,t)=>{A.current=!0,S.current=!1,c({status:"error",wording:e,message:t.message??null}),g(()=>{s.current.onDecline?.({status:"declined",sessionId:s.current.sessionId,...t.reason?{reason:t.reason}:{},...t.message?{message:t.message}:{}})}),(async()=>(await re(400),_.current&&c(null)))()},[]),C=k((e,t)=>{S.current?(S.current=!1,c({status:"error",wording:e,message:t.message}),setTimeout(()=>{_.current&&c(null)},400)):c(null),g(()=>s.current.onError?.(t))},[]),D=k(async e=>{let t=T.current+1;T.current=t;let n=()=>!_.current||t!==T.current;S.current=!0,c({status:"processing",wording:"payment_method",message:null});let i=new ze(Z(s.current.billingApiUrl),{telemetry:s.current.telemetry});try{for(let r=0;r<dt;r+=1){if((r>0||e.waitFirst)&&await re(ct),n())return;let y=await i.getUnifiedCheckoutSession(s.current.sessionId,s.current.nonce);if(n())return;let R=y.data.session?.status;if(R==="complete"){G(!0),E("payment_method");return}if(R==="expired")throw new b("This setup session expired before the payment method was saved.","validation_error",{code:"payment_method_setup_expired"})}throw new b("The payment method could not be confirmed yet. Please try again.","api_error",{code:"payment_method_setup_unverified"})}catch(r){if(n())return;let y=r instanceof b&&r.code==="payment_method_setup_unverified";C("payment_method",w(r,y?{retryable:!0}:{}))}finally{i.destroy()}},[C,E]);ee(()=>{let e=!0,t=Z(m),n=new ze(t,{telemetry:o});q(null),G(!1),pe(null),me(null),fe(null);let i=new Set;return M.current=i,j(i),A.current=!1,$.current=!1,z.current=!1,(async()=>{try{let{session:r,advertisement:y}=await mt(n,a,u);if(!e)return;let R={advertisement:y,customer:pt(r),...r.futureUse?{futureUse:r.futureUse}:{},...r.futureUseUnsupported?{futureUseUnsupported:r.futureUseUnsupported}:{}};if(Y){if(Ye(),r.status==="complete"){G(!0),q(R),E("payment_method");return}Y.failed?U("payment_method",{reason:"redirect_failed"}):D({waitFirst:!0})}let Ie=y.card?await yt(n,r,a,u,t):null;if(!e)return;q(R),Ie&&(me(Ie),pe(new ot({sessionId:a,operation:"card_setup",telemetry:o})))}catch(r){if(!e)return;let y=w(r);A.current=!0,fe(y),g(()=>s.current.onError?.(y))}})(),()=>{e=!1,n.destroy()}},[m,u,Y,U,E,a,o,D]),ee(()=>{if(!v)return;S.current=!1;let e=v.on("submitting",()=>{S.current=!0,c({status:"processing",wording:"card",message:null})}),t=v.on("complete",r=>{E("card",r.paymentMethod)}),n=v.on("decline",r=>{U("card",{...r.declineReason?{reason:r.declineReason}:{},...r.message?{message:r.message}:{}})}),i=v.on("challenge_dismissed",()=>{c(null)});return()=>{e(),t(),n(),i()}},[v,U,E]);let Ce=k((e,t,n)=>{if(n.retryable){C("payment_method",w(t,n));return}if(M.current.has(e))return;let i=new Set(M.current);i.add(e),M.current=i,j(i);let r=H.current?.advertisement,y=r?X(r).some(R=>!i.has(R)):!1;C("payment_method",w(t,{code:n.code,retryable:y}))},[C]),Pe=te(()=>({onSubmitting:()=>{S.current=!0,c({status:"processing",wording:"payment_method",message:null})},onConfirmed:()=>{D({waitFirst:!1})},onDeclined:e=>U("payment_method",e),onValidation:e=>{g(()=>s.current.onValidation?.(e))},onAbandoned:()=>{S.current=!1,c(null)}}),[U,D]),be=l(Ce);be.current=Ce;let Fe=l(new Map),L=e=>{let t=Fe.current.get(e);if(t)return t;let n=(i,r)=>be.current(e,i,r);return Fe.current.set(e,n),n},Me=k(e=>{if(M.current.has(e))return;let t=new Set(M.current);t.add(e),M.current=t,j(t);let n=H.current?.advertisement;n&&X(n).some(r=>!t.has(r))||C("payment_method",w(new Error("FloPay: none of the advertised payment methods can be used here."),{code:"payment_method_setup_unavailable",retryable:!1}))},[C]),Re=l(Me);Re.current=Me;let we=l(new Map),_e=e=>{let t=we.current.get(e);if(t)return t;let n=()=>Re.current(e);return we.current.set(e,n),n},Ee=I?d(Le,{status:I.status,errorMessage:I.message,...je(I.wording),successNote:null,...ve?{theme:ve}:{}}):null;if(ye)return d("div",{role:"alert",children:ye.message});if(!x||Xe)return ne(Je,{children:[Ee,x?null:Qe]});let{advertisement:B,customer:tt,futureUse:Ue,futureUseUnsupported:ke}=x,Ae=Z(m),Be=o===void 0?{}:{telemetry:o},Q=B.stripe.filter(({method:e})=>!K.has(e)),O=K.has("paypal")?null:B.paypal,Oe=!!(B.card&&v&&F?.html),Ve=({method:e,publishableKey:t,currency:n})=>d("div",{"data-flopay-payment-method":e,style:{display:"contents"},children:d(W,{onFailed:L(e),children:d($e,{fallback:null,children:d(p,{method:e,category:N(e),publishableKey:t,currency:n,...Ue?{futureUse:Ue}:{},...ke?{futureUseUnsupported:ke}:{},sessionId:a,nonce:u,billingApiUrl:Ae,...Be,...Se?{appearance:Se}:{},...ge?{buttonsLayout:ge}:{},...typeof f=="string"?{themeId:f}:{},...Pe,onFailed:L(e),onUnavailable:_e(e)})})})},e),rt=Q.filter(({method:e})=>N(e)==="wallet"),nt=Q.filter(({method:e})=>N(e)!=="wallet"),xe=Q.length>0||O!==null;return ne(Je,{children:[Ee,xe?ne("div",{"data-flopay-payment-methods":"",style:{position:"relative",display:"flex",flexDirection:"column",gap:"0.5rem"},children:[rt.map(Ve),O?d("div",{"data-flopay-payment-method":"paypal",children:d(W,{onFailed:L("paypal"),children:d($e,{fallback:null,children:d(h,{clientId:O.clientId,...O.environment?{environment:O.environment}:{},...B.currency?{currency:B.currency}:{},sessionId:a,nonce:u,billingApiUrl:Ae,customer:tt,...Be,...Pe,onFailed:L("paypal"),onUnavailable:_e("paypal")})})})}):null,nt.map(Ve)]}):null,Oe&&xe?d(We,{label:"or add a card"}):null,Oe&&v&&F?.html?d("div",{"data-flopay-payment-method":"card",children:d(Ne,{capture:v,html:F.html,messageToken:F.messageToken,expectedOrigin:F.expectedOrigin,expiresAt:F.expiresAt,verificationRequired:F.verificationRequired,theme:Ze,containerStyle:et,onReady:()=>{g(()=>s.current.onReady?.())},onValidation:e=>{g(()=>s.current.onValidation?.(e))},onError:e=>{e&&C("card",w(new Error(e),{code:"card_setup_widget_failed",retryable:!0}))}})}):null]})}export{Et as a};
|