@flopay/react 2.2.14 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -236,6 +236,8 @@ The checkout components also accept `buttonsStyles` from runtime contract 2.8.0.
236
236
 
237
237
  The checkout components accept an optional `country` (ISO 3166-1 alpha-2, any case) from runtime contract 2.9.0, as the 1.x `country` prop. A payment method whose session descriptor lists `countries` (Afterpay, Cash App Pay and so on) is offered only when the buyer's country is in that list. The country the buyer picks in the AVS form wins, then this prop, then the session's `accountData.country`; with none of them every method is offered, because the checkout never looks a country up. Changing the prop updates the mounted checkout without remounting.
238
238
 
239
+ The checkout components accept the 1.x card form props from runtime contract 2.10.0. `enableAVS` (`true`, or which billing address fields to collect, each `true` or the countries it applies to) and `avsLayout` (`'row'` or `'column'`) add the billing address fields to the card form, and `cardFieldOrder` reorders its rows (a permutation of `'name'`, `'number'` and `'expiry'`). In the buttons layout, `cardButtonContent`, `cardBackButtonContent` and `cardTitleContent` set the card button's content, the back button's label and the card form's title: text is sent as it is, and other content is rendered in your page and sent as markup, which the Flo-hosted card frame shows only after removing everything outside a strict allow-list of text, layout and image markup (no scripts, links, forms or event handlers, and images only as inline `data:image/` sources). An empty string hides that label. `moreOptionsLabel` and `submitLabel` set the "More payment options" link and the pay button, over `strings.morePaymentOptions` and `strings.payButton`. `onButtonClick(method)` is called with the payment method's name (`'card'`, `'apple_pay'`, `'google_pay'`, `'paypal'` or an alternative method's) when the buyer chooses one, for example to clear an error you show for the previous attempt.
240
+
239
241
  `layout="buttons"` stacks the payment methods as buttons with an expandable card form, and can change at runtime without recreating the session. In that layout, `onButtonClick` reports every method click, `onDecline` reports declines and cancellations, and `onBeforeButtonClick` runs before a method continues: return an `InlineSessionPatch` to update the inline draft, or `false` to stop. Keep it well under 900 ms for PayPal, Apple Pay, and Google Pay, because it runs during the provider's button handshake (see **Stalled wallet clicks** above).
240
242
 
241
243
  `paymentMethodLayout` sets the order of the payment method groups: `'card'`, `'paypal'`, `'wallets'` (Apple Pay and Google Pay) and `'apms'` (alternative payment methods such as Klarna, iDEAL or SEPA), with optional rules for buyers in particular countries. Without it, the order is PayPal, wallets, APMs, then card, and nothing extra is requested.
@@ -52,6 +52,11 @@ export interface FloPayRuntimeCheckoutProps {
52
52
  onError?: (error: FloPayError) => void;
53
53
  /** Further mount options, passed to the runtime as given (by value). A change mounts again. */
54
54
  extraMountOptions?: Record<string, unknown>;
55
+ /**
56
+ * `true` declares contract 2.10.0, so the runtime relays `buttonClick` (the buyer chose a payment
57
+ * method) to `onEvent`. A change mounts again.
58
+ */
59
+ buttonClicks?: boolean;
55
60
  }
56
61
  /**
57
62
  * A card checkout that runs from the Flo-hosted runtime. The component holds no checkout
@@ -1,4 +1,5 @@
1
1
  import type { CheckoutRuntimeAutomaticPayment } from '@flopay/js';
2
+ import type { AVSFieldConfig, VaultCardFieldKey } from '@flopay/shared';
2
3
  import type { ReactElement, ReactNode } from 'react';
3
4
  import type { FloPayRuntimeCardSetupProps } from './flopay-runtime-card-setup.js';
4
5
  import { FloPayRuntimeCardSetup } from './flopay-runtime-card-setup.js';
@@ -22,6 +23,27 @@ export interface FloPayCheckoutProps extends Omit<RuntimeCheckoutCoreProps, 'pub
22
23
  cardFieldPlaceholders?: Record<string, string>;
23
24
  enabledPaymentMethods?: string[];
24
25
  initialPayPalOrderId?: string;
26
+ /** The billing address fields the card form collects, as in 1.x (contract 2.10.0). */
27
+ enableAVS?: boolean | AVSFieldConfig;
28
+ /** How the AVS fields are laid out: `row` (the default) or `column`. */
29
+ avsLayout?: 'row' | 'column';
30
+ /** The order of the card form's rows: a permutation of `name`, `number` and `expiry`. */
31
+ cardFieldOrder?: VaultCardFieldKey[];
32
+ /**
33
+ * The buttons layout's card button content, back button label and card form title, as in 1.x.
34
+ * Text, or content this component renders in the page and sends as markup; the Flo frame keeps
35
+ * only text, layout and image markup (no scripts, links, forms or event handlers). An empty
36
+ * string hides that label. Each wins over the matching `strings` key.
37
+ */
38
+ cardButtonContent?: ReactNode;
39
+ cardBackButtonContent?: ReactNode;
40
+ cardTitleContent?: ReactNode;
41
+ /** The "More payment options" link's label, as in 1.x; wins over `strings.morePaymentOptions`. */
42
+ moreOptionsLabel?: string;
43
+ /** The pay button's label, as in 1.x; wins over `strings.payButton`. */
44
+ submitLabel?: string;
45
+ /** The buyer chose a payment method, by its name (`card`, `apple_pay`, `paypal`, ...), as in 1.x. */
46
+ onButtonClick?(method: string): void;
25
47
  /** The 1.x callbacks: each gets its runtime event's payload unchanged. */
26
48
  onComplete?(event: unknown): void;
27
49
  onDecline?(event: unknown): void;
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var N=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var se=Object.prototype.hasOwnProperty;var ce=(e,t)=>{for(var n in t)N(e,n,{get:t[n],enumerable:!0})},de=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ie(t))!se.call(e,r)&&r!==n&&N(e,r,{get:()=>t[r],enumerable:!(o=ue(t,r))||o.enumerable});return e};var le=e=>de(N({},"__esModule",{value:!0}),e);var xe={};ce(xe,{DirectPayPalButton:()=>te,FloPayAutomaticPaymentButton:()=>oe,FloPayCardSetup:()=>Z,FloPayCheckout:()=>E,FloPayPaymentMethodSetup:()=>$,FloPayProvider:()=>ee,FloPayRuntimeCardSetup:()=>T,FloPayRuntimeCheckout:()=>E,FloPayRuntimePaymentMethodSetup:()=>_,SplitCardForm:()=>X,VaultCardFields:()=>ne,dropThirdPartyOnlyError:()=>re.dropThirdPartyOnlyError});module.exports=le(xe);var re=require("@flopay/shared");var j=require("@flopay/js"),L=require("@flopay/shared"),S=require("react");var l=require("@flopay/shared");var D=require("react/jsx-runtime"),me="2.4.0";function Y(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var ye=new Set(["validation_error","api_error","authentication_error","rate_limit_error","network_error"]);function x(e,t,n,o={}){return Object.assign(new L.FloPayError(e,t,o),{retryable:n})}function pe(e){let t=Y(e)?e:{},n=typeof t.type=="string"&&ye.has(t.type)?t.type:"";return x(typeof t.message=="string"?t.message:"The setup failed.",n||"api_error",t.retryable===!0,{...typeof t.code=="string"?{code:t.code}:{},...typeof t.param=="string"?{param:t.param}:{},...typeof t.statusCode=="number"?{statusCode:t.statusCode}:{}})}function Pe(e){return e instanceof L.FloPayError?x(e.message,e.type,!0,{code:e.code??"runtime_load_failed",cause:e}):x("The checkout runtime failed to load.","network_error",!0,{code:"runtime_load_failed",cause:e})}function J(e){return{...e.theme===void 0?{}:{theme:e.theme},...e.appearance===void 0?{}:{appearance:e.appearance},...e.buttonsStyles===void 0?{}:{buttonsStyles:e.buttonsStyles},...e.containerStyle===void 0?{}:{containerStyle:e.containerStyle},...e.strings===void 0?{}:{strings:e.strings}}}function I({kind:e,props:t}){let{sessionId:n,nonce:o,runtimeUrl:r,runtimeTimeoutMs:i,locale:C}=t,F=(0,S.useRef)(null),P=(0,S.useRef)(null),f=(0,S.useRef)(t);f.current=t;let b=J(t),h=JSON.stringify(b),g=(0,S.useRef)(h);return(0,S.useEffect)(()=>{let m=F.current;if(!m)return;let c=!0,R=u=>{(0,l.invokeMerchantCallback)(()=>f.current.onError?.(u))},M=u=>{let d=f.current,y=u.payload;switch(u.name){case"setupReady":(0,l.invokeMerchantCallback)(()=>d.onReady?.());return;case"setupValidation":{let O=Y(y)&&typeof y.message=="string"?y.message:null;(0,l.invokeMerchantCallback)(()=>d.onValidation?.(O));return}case"complete":(0,l.invokeMerchantCallback)(()=>d.onComplete?.(y));return;case"decline":(0,l.invokeMerchantCallback)(()=>d.onDecline?.(y));return;case"cancel":(0,l.invokeMerchantCallback)(()=>d.onCancel?.(y));return;case"error":R(pe(y));return;default:return}};return(0,j.loadCheckoutRuntime)({runtimeUrl:r,...i===void 0?{}:{timeoutMs:i}}).then(u=>{if(!c)return;if(typeof u.mountSetup!="function"){R(x("The checkout runtime on this page is too old to run setup.","api_error",!1,{code:"runtime_setup_unsupported"}));return}let d=J(f.current);g.current=JSON.stringify(d),P.current=u.mountSetup(m,{setup:e,sessionId:n,nonce:o,contractVersion:C===void 0?me:"2.7.0",locale:C,...d,onEvent:M})},u=>{c&&R(Pe(u))}),()=>{c=!1;let u=P.current;P.current=null,u?.unmount()}},[e,n,o,r,i,C]),(0,S.useEffect)(()=>{let m=P.current;if(!m||g.current===h)return;g.current=h;let c=f.current;m.update({theme:c.theme,appearance:c.appearance,buttonsStyles:c.buttonsStyles,containerStyle:c.containerStyle,strings:c.strings})},[h]),(0,D.jsx)("div",{ref:F})}function T(e){return(0,D.jsx)(I,{kind:"card",props:e})}var G=require("react/jsx-runtime");function _(e){return(0,G.jsx)(I,{kind:"payment_method",props:e})}var w=require("react");var q=require("@flopay/js"),B=require("@flopay/shared"),s=require("react"),Q=require("react/jsx-runtime"),fe="2.2.0",he="2.3.0",Re="2.5.0",Se="2.6.0",Ce=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function Fe(e,t,n,o,r){return r!==void 0?"2.9.0":o!==void 0?"2.8.0":n!==void 0?"2.7.0":t!==void 0&&Object.keys(t).some(i=>!Ce.has(i))?Se:t!==void 0&&"hiddenPaymentMethods"in t?Re:e?he:fe}function ge(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function Ee(e){return e instanceof B.FloPayError?e:new B.FloPayError("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function z(e){let{publishableKey:t,sessionId:n,nonce:o,appearance:r,strings:i,locale:C,country:F,layout:P,runtimeUrl:f,runtimeTimeoutMs:b}=e,h=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),g=e.createSession===void 0?void 0:JSON.stringify(e.createSession),m=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),c=e.buttonsStyles===void 0?void 0:JSON.stringify(e.buttonsStyles),R=e.automaticPayment?.mode,M=e.automaticPayment?.getSession!==void 0,u=(0,s.useRef)(void 0),d=(0,s.useRef)(void 0),y=(0,s.useRef)(void 0),O=(0,s.useRef)(null),p=(0,s.useRef)(null),a=(0,s.useRef)(e);return a.current=e,(0,s.useEffect)(()=>{let v=!0;return(0,q.loadCheckoutRuntime)({runtimeUrl:f,timeoutMs:b}).then(A=>{let K=O.current;if(!v||!K)return;let U=a.current.paymentMethodLayout;u.current=U===void 0?void 0:JSON.stringify(U),d.current=a.current.buttonsStyles===void 0?void 0:JSON.stringify(a.current.buttonsStyles),y.current=a.current.country;let H=h===void 0?void 0:JSON.parse(h);p.current=A.mount(K,{...H,contractVersion:Fe(!!R,H,a.current.locale,a.current.buttonsStyles,a.current.country),...R?{automaticPayment:ge(R,M?()=>a.current.automaticPayment?.getSession:void 0)}:{},publishableKey:t,sessionId:n,nonce:o,createSession:g===void 0?void 0:JSON.parse(g),appearance:a.current.appearance,buttonsStyles:a.current.buttonsStyles,strings:a.current.strings,locale:a.current.locale,...a.current.country===void 0?{}:{country:a.current.country},paymentMethodLayout:u.current===void 0?void 0:JSON.parse(u.current),...P?{layout:P}:{},onEvent:ae=>a.current.onEvent?.(ae)})},A=>{v&&a.current.onError?.(Ee(A))}),()=>{v=!1,p.current?.unmount(),p.current=null}},[t,n,o,g,P,R,M,f,b,h]),(0,s.useEffect)(()=>{r!==void 0&&p.current?.update({appearance:r})},[r]),(0,s.useEffect)(()=>{c===void 0||c===d.current||!p.current||(d.current=c,p.current.update({buttonsStyles:a.current.buttonsStyles}))},[c]),(0,s.useEffect)(()=>{i!==void 0&&p.current?.update({strings:i})},[i]),(0,s.useEffect)(()=>{C!==void 0&&p.current?.update({locale:C})},[C]),(0,s.useEffect)(()=>{F===y.current||!p.current||(y.current=F,p.current.update({country:F??""}))},[F]),(0,s.useEffect)(()=>{if(m===void 0||m===u.current)return;let v=p.current;v&&(u.current=m,v.update({paymentMethodLayout:JSON.parse(m)}))},[m]),(0,Q.jsx)("div",{ref:O,"data-flopay-runtime-checkout":""})}var W=require("react"),V=(0,W.createContext)({});var k=require("react/jsx-runtime"),ke=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],ve={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function be(e){let t={};for(let o of ke)e[o]!==void 0&&(t[o]=e[o]);let n=[...e.hiddenPaymentMethods??[]];return e.showPayPal===!1&&!n.includes("paypal")&&n.push("paypal"),(e.hiddenPaymentMethods!==void 0||n.length>0)&&(t.hiddenPaymentMethods=n),Object.keys(t).length===0?void 0:t}function E(e){let t=(0,w.useContext)(V),n=(0,w.useRef)(e);return n.current=e,(0,k.jsx)(z,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,buttonsStyles:e.buttonsStyles,strings:e.strings,locale:e.locale,country:e.country,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:be(e),onError:o=>n.current.onError?.(o),onEvent:o=>{let r=n.current;r.onEvent?.(o);let i=r[ve[o.name]];i&&(0,l.invokeMerchantCallback)(()=>i(o.payload))}})}function X(e){return(0,k.jsx)(E,{...e})}var Z=T,$=_;function ee({publishableKey:e,runtimeUrl:t,children:n}){return(0,k.jsx)(V.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var Me=["card","apple_pay","google_pay","apms"],Oe=["paypal","apple_pay","google_pay","apms"];function te(e){return(0,k.jsx)(E,{...e,hiddenPaymentMethods:Me})}function ne(e){return(0,k.jsx)(E,{...e,hiddenPaymentMethods:Oe})}function oe({mode:e,getSession:t,onSuccess:n,onComplete:o,...r}){return(0,k.jsx)(E,{...r,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:i=>{o&&(0,l.invokeMerchantCallback)(()=>o(i)),n&&(0,l.invokeMerchantCallback)(()=>n(i))}})}0&&(module.exports={DirectPayPalButton,FloPayAutomaticPaymentButton,FloPayCardSetup,FloPayCheckout,FloPayPaymentMethodSetup,FloPayProvider,FloPayRuntimeCardSetup,FloPayRuntimeCheckout,FloPayRuntimePaymentMethodSetup,SplitCardForm,VaultCardFields,dropThirdPartyOnlyError});
1
+ "use strict";var N=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var me=Object.getOwnPropertyNames;var ye=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var n in t)N(e,n,{get:t[n],enumerable:!0})},Pe=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of me(t))!ye.call(e,o)&&o!==n&&N(e,o,{get:()=>t[o],enumerable:!(r=ce(t,o))||r.enumerable});return e};var fe=e=>Pe(N({},"__esModule",{value:!0}),e);var Ie={};pe(Ie,{DirectPayPalButton:()=>ue,FloPayAutomaticPaymentButton:()=>se,FloPayCardSetup:()=>oe,FloPayCheckout:()=>v,FloPayPaymentMethodSetup:()=>re,FloPayProvider:()=>ae,FloPayRuntimeCardSetup:()=>x,FloPayRuntimeCheckout:()=>v,FloPayRuntimePaymentMethodSetup:()=>A,SplitCardForm:()=>ne,VaultCardFields:()=>ie,dropThirdPartyOnlyError:()=>de.dropThirdPartyOnlyError});module.exports=fe(Ie);var de=require("@flopay/shared");var Y=require("@flopay/js"),w=require("@flopay/shared"),b=require("react");var P=require("@flopay/shared");var I=require("react/jsx-runtime"),Ce="2.4.0";function G(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var Re=new Set(["validation_error","api_error","authentication_error","rate_limit_error","network_error"]);function _(e,t,n,r={}){return Object.assign(new w.FloPayError(e,t,r),{retryable:n})}function he(e){let t=G(e)?e:{},n=typeof t.type=="string"&&Re.has(t.type)?t.type:"";return _(typeof t.message=="string"?t.message:"The setup failed.",n||"api_error",t.retryable===!0,{...typeof t.code=="string"?{code:t.code}:{},...typeof t.param=="string"?{param:t.param}:{},...typeof t.statusCode=="number"?{statusCode:t.statusCode}:{}})}function Se(e){return e instanceof w.FloPayError?_(e.message,e.type,!0,{code:e.code??"runtime_load_failed",cause:e}):_("The checkout runtime failed to load.","network_error",!0,{code:"runtime_load_failed",cause:e})}function j(e){return{...e.theme===void 0?{}:{theme:e.theme},...e.appearance===void 0?{}:{appearance:e.appearance},...e.buttonsStyles===void 0?{}:{buttonsStyles:e.buttonsStyles},...e.containerStyle===void 0?{}:{containerStyle:e.containerStyle},...e.strings===void 0?{}:{strings:e.strings}}}function B({kind:e,props:t}){let{sessionId:n,nonce:r,runtimeUrl:o,runtimeTimeoutMs:d,locale:s}=t,k=(0,b.useRef)(null),h=(0,b.useRef)(null),S=(0,b.useRef)(t);S.current=t;let a=j(t),c=JSON.stringify(a),m=(0,b.useRef)(c);return(0,b.useEffect)(()=>{let R=k.current;if(!R)return;let u=!0,E=y=>{(0,P.invokeMerchantCallback)(()=>S.current.onError?.(y))},M=y=>{let p=S.current,F=y.payload;switch(y.name){case"setupReady":(0,P.invokeMerchantCallback)(()=>p.onReady?.());return;case"setupValidation":{let T=G(F)&&typeof F.message=="string"?F.message:null;(0,P.invokeMerchantCallback)(()=>p.onValidation?.(T));return}case"complete":(0,P.invokeMerchantCallback)(()=>p.onComplete?.(F));return;case"decline":(0,P.invokeMerchantCallback)(()=>p.onDecline?.(F));return;case"cancel":(0,P.invokeMerchantCallback)(()=>p.onCancel?.(F));return;case"error":E(he(F));return;default:return}};return(0,Y.loadCheckoutRuntime)({runtimeUrl:o,...d===void 0?{}:{timeoutMs:d}}).then(y=>{if(!u)return;if(typeof y.mountSetup!="function"){E(_("The checkout runtime on this page is too old to run setup.","api_error",!1,{code:"runtime_setup_unsupported"}));return}let p=j(S.current);m.current=JSON.stringify(p),h.current=y.mountSetup(R,{setup:e,sessionId:n,nonce:r,contractVersion:s===void 0?Ce:"2.7.0",locale:s,...p,onEvent:M})},y=>{u&&E(Se(y))}),()=>{u=!1;let y=h.current;h.current=null,y?.unmount()}},[e,n,r,o,d,s]),(0,b.useEffect)(()=>{let R=h.current;if(!R||m.current===c)return;m.current=c;let u=S.current;R.update({theme:u.theme,appearance:u.appearance,buttonsStyles:u.buttonsStyles,containerStyle:u.containerStyle,strings:u.strings})},[c]),(0,I.jsx)("div",{ref:k})}function x(e){return(0,I.jsx)(B,{kind:"card",props:e})}var q=require("react/jsx-runtime");function A(e){return(0,q.jsx)(B,{kind:"payment_method",props:e})}var C=require("react");var z=require("@flopay/js"),V=require("@flopay/shared"),l=require("react"),W=require("react/jsx-runtime"),Fe="2.2.0",ge="2.3.0",ke="2.5.0",Ee="2.6.0",be="2.10.0",ve=new Set(["enableAVS","avsLayout","cardFieldOrder","cardButtonContent","cardBackButtonContent","cardTitleContent"]),Me=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function Oe(e,t,n,r,o,d){return d||t!==void 0&&Object.keys(t).some(s=>ve.has(s))?be:o!==void 0?"2.9.0":r!==void 0?"2.8.0":n!==void 0?"2.7.0":t!==void 0&&Object.keys(t).some(s=>!Me.has(s))?Ee:t!==void 0&&"hiddenPaymentMethods"in t?ke:e?ge:Fe}function Te(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function _e(e){return e instanceof V.FloPayError?e:new V.FloPayError("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function Q(e){let{publishableKey:t,sessionId:n,nonce:r,appearance:o,strings:d,locale:s,country:k,layout:h,runtimeUrl:S,runtimeTimeoutMs:a,buttonClicks:c}=e,m=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),R=e.createSession===void 0?void 0:JSON.stringify(e.createSession),u=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),E=e.buttonsStyles===void 0?void 0:JSON.stringify(e.buttonsStyles),M=e.automaticPayment?.mode,y=e.automaticPayment?.getSession!==void 0,p=(0,l.useRef)(void 0),F=(0,l.useRef)(void 0),T=(0,l.useRef)(void 0),K=(0,l.useRef)(null),g=(0,l.useRef)(null),i=(0,l.useRef)(e);return i.current=e,(0,l.useEffect)(()=>{let O=!0;return(0,z.loadCheckoutRuntime)({runtimeUrl:S,timeoutMs:a}).then(L=>{let H=K.current;if(!O||!H)return;let J=i.current.paymentMethodLayout;p.current=J===void 0?void 0:JSON.stringify(J),F.current=i.current.buttonsStyles===void 0?void 0:JSON.stringify(i.current.buttonsStyles),T.current=i.current.country;let U=m===void 0?void 0:JSON.parse(m);g.current=L.mount(H,{...U,contractVersion:Oe(!!M,U,i.current.locale,i.current.buttonsStyles,i.current.country,c),...M?{automaticPayment:Te(M,y?()=>i.current.automaticPayment?.getSession:void 0)}:{},publishableKey:t,sessionId:n,nonce:r,createSession:R===void 0?void 0:JSON.parse(R),appearance:i.current.appearance,buttonsStyles:i.current.buttonsStyles,strings:i.current.strings,locale:i.current.locale,...i.current.country===void 0?{}:{country:i.current.country},paymentMethodLayout:p.current===void 0?void 0:JSON.parse(p.current),...h?{layout:h}:{},onEvent:le=>i.current.onEvent?.(le)})},L=>{O&&i.current.onError?.(_e(L))}),()=>{O=!1,g.current?.unmount(),g.current=null}},[t,n,r,R,h,M,y,S,a,m,c]),(0,l.useEffect)(()=>{o!==void 0&&g.current?.update({appearance:o})},[o]),(0,l.useEffect)(()=>{E===void 0||E===F.current||!g.current||(F.current=E,g.current.update({buttonsStyles:i.current.buttonsStyles}))},[E]),(0,l.useEffect)(()=>{d!==void 0&&g.current?.update({strings:d})},[d]),(0,l.useEffect)(()=>{s!==void 0&&g.current?.update({locale:s})},[s]),(0,l.useEffect)(()=>{k===T.current||!g.current||(T.current=k,g.current.update({country:k??""}))},[k]),(0,l.useEffect)(()=>{if(u===void 0||u===p.current)return;let O=g.current;O&&(p.current=u,O.update({paymentMethodLayout:JSON.parse(u)}))},[u]),(0,W.jsx)("div",{ref:K,"data-flopay-runtime-checkout":""})}var X=require("react"),D=(0,X.createContext)({});var f=require("react/jsx-runtime"),xe=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId","enableAVS","avsLayout","cardFieldOrder"],$=["cardButtonContent","cardBackButtonContent","cardTitleContent"],Ae={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function ee(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e)}function te(e){return e!=null&&typeof e!="boolean"&&ee(e)===void 0}function Le({content:e,onMarkup:t}){let n=(0,C.useRef)(null);return(0,C.useEffect)(()=>{n.current&&t(n.current.innerHTML)}),(0,f.jsx)("div",{ref:n,hidden:!0,"aria-hidden":"true","data-flopay-slot-markup":"",children:(0,C.isValidElement)(e)||Array.isArray(e)?e:null})}function Ne(e,t){let n={};for(let o of xe)e[o]!==void 0&&(n[o]=e[o]);for(let o of $){let s=ee(e[o])??(te(e[o])?t[o]:void 0);s!==void 0&&(n[o]=s)}let r=[...e.hiddenPaymentMethods??[]];return e.showPayPal===!1&&!r.includes("paypal")&&r.push("paypal"),(e.hiddenPaymentMethods!==void 0||r.length>0)&&(n.hiddenPaymentMethods=r),Object.keys(n).length===0?void 0:n}function Z(e){return e.moreOptionsLabel===void 0&&e.submitLabel===void 0?e.strings:{...e.strings,...e.moreOptionsLabel===void 0?{}:{morePaymentOptions:e.moreOptionsLabel},...e.submitLabel===void 0?{}:{payButton:e.submitLabel}}}function v(e){let t=(0,C.useContext)(D),n=(0,C.useRef)(e);n.current=e;let[r,o]=(0,C.useState)({}),d=a=>c=>o(m=>m[a]===c?m:{...m,[a]:c}),s=JSON.stringify(Z(e)??null),k=(0,C.useMemo)(()=>Z(n.current),[s]),h=$.filter(a=>te(e[a])),S=(0,f.jsx)(Q,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,buttonsStyles:e.buttonsStyles,strings:k,locale:e.locale,country:e.country,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:Ne(e,r),buttonClicks:e.onButtonClick!==void 0,onError:a=>n.current.onError?.(a),onEvent:a=>{let c=n.current;if(c.onEvent?.(a),a.name==="buttonClick"){let R=a.payload?.method,u=c.onButtonClick;u&&typeof R=="string"&&(0,P.invokeMerchantCallback)(()=>u(R));return}let m=c[Ae[a.name]];m&&(0,P.invokeMerchantCallback)(()=>m(a.payload))}});return h.length===0?S:(0,f.jsxs)(f.Fragment,{children:[S,h.map(a=>(0,f.jsx)(Le,{content:e[a],onMarkup:d(a)},a))]})}function ne(e){return(0,f.jsx)(v,{...e})}var oe=x,re=A;function ae({publishableKey:e,runtimeUrl:t,children:n}){return(0,f.jsx)(D.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var we=["card","apple_pay","google_pay","apms"],Be=["paypal","apple_pay","google_pay","apms"];function ue(e){return(0,f.jsx)(v,{...e,hiddenPaymentMethods:we})}function ie(e){return(0,f.jsx)(v,{...e,hiddenPaymentMethods:Be})}function se({mode:e,getSession:t,onSuccess:n,onComplete:r,...o}){return(0,f.jsx)(v,{...o,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:d=>{r&&(0,P.invokeMerchantCallback)(()=>r(d)),n&&(0,P.invokeMerchantCallback)(()=>n(d))}})}0&&(module.exports={DirectPayPalButton,FloPayAutomaticPaymentButton,FloPayCardSetup,FloPayCheckout,FloPayPaymentMethodSetup,FloPayProvider,FloPayRuntimeCardSetup,FloPayRuntimeCheckout,FloPayRuntimePaymentMethodSetup,SplitCardForm,VaultCardFields,dropThirdPartyOnlyError});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as v}from"./chunk-ZG2NKEN7.mjs";import{a as C,c as b}from"./chunk-QHQ55OPE.mjs";import{dropThirdPartyOnlyError as ve}from"@flopay/shared";import{useContext as W,useRef as X}from"react";import{loadCheckoutRuntime as V}from"@flopay/js";import{FloPayError as I}from"@flopay/shared";import{useEffect as d,useRef as c}from"react";import{jsx as z}from"react/jsx-runtime";var K="2.2.0",U="2.3.0",H="2.5.0",J="2.6.0",j=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function Y(e,t,n,r,i){return i!==void 0?"2.9.0":r!==void 0?"2.8.0":n!==void 0?"2.7.0":t!==void 0&&Object.keys(t).some(a=>!j.has(a))?J:t!==void 0&&"hiddenPaymentMethods"in t?H:e?U:K}function G(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function q(e){return e instanceof I?e:new I("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function B(e){let{publishableKey:t,sessionId:n,nonce:r,appearance:i,strings:a,locale:R,country:p,layout:F,runtimeUrl:x,runtimeTimeoutMs:A}=e,S=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),k=e.createSession===void 0?void 0:JSON.stringify(e.createSession),m=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),f=e.buttonsStyles===void 0?void 0:JSON.stringify(e.buttonsStyles),h=e.automaticPayment?.mode,L=e.automaticPayment?.getSession!==void 0,P=c(void 0),g=c(void 0),E=c(void 0),N=c(null),u=c(null),o=c(e);return o.current=e,d(()=>{let s=!0;return V({runtimeUrl:x,timeoutMs:A}).then(M=>{let w=N.current;if(!s||!w)return;let T=o.current.paymentMethodLayout;P.current=T===void 0?void 0:JSON.stringify(T),g.current=o.current.buttonsStyles===void 0?void 0:JSON.stringify(o.current.buttonsStyles),E.current=o.current.country;let _=S===void 0?void 0:JSON.parse(S);u.current=M.mount(w,{..._,contractVersion:Y(!!h,_,o.current.locale,o.current.buttonsStyles,o.current.country),...h?{automaticPayment:G(h,L?()=>o.current.automaticPayment?.getSession:void 0)}:{},publishableKey:t,sessionId:n,nonce:r,createSession:k===void 0?void 0:JSON.parse(k),appearance:o.current.appearance,buttonsStyles:o.current.buttonsStyles,strings:o.current.strings,locale:o.current.locale,...o.current.country===void 0?{}:{country:o.current.country},paymentMethodLayout:P.current===void 0?void 0:JSON.parse(P.current),...F?{layout:F}:{},onEvent:D=>o.current.onEvent?.(D)})},M=>{s&&o.current.onError?.(q(M))}),()=>{s=!1,u.current?.unmount(),u.current=null}},[t,n,r,k,F,h,L,x,A,S]),d(()=>{i!==void 0&&u.current?.update({appearance:i})},[i]),d(()=>{f===void 0||f===g.current||!u.current||(g.current=f,u.current.update({buttonsStyles:o.current.buttonsStyles}))},[f]),d(()=>{a!==void 0&&u.current?.update({strings:a})},[a]),d(()=>{R!==void 0&&u.current?.update({locale:R})},[R]),d(()=>{p===E.current||!u.current||(E.current=p,u.current.update({country:p??""}))},[p]),d(()=>{if(m===void 0||m===P.current)return;let s=u.current;s&&(P.current=m,s.update({paymentMethodLayout:JSON.parse(m)}))},[m]),z("div",{ref:N,"data-flopay-runtime-checkout":""})}import{createContext as Q}from"react";var O=Q({});import{jsx as y}from"react/jsx-runtime";var Z=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],$={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function ee(e){let t={};for(let r of Z)e[r]!==void 0&&(t[r]=e[r]);let n=[...e.hiddenPaymentMethods??[]];return e.showPayPal===!1&&!n.includes("paypal")&&n.push("paypal"),(e.hiddenPaymentMethods!==void 0||n.length>0)&&(t.hiddenPaymentMethods=n),Object.keys(t).length===0?void 0:t}function l(e){let t=W(O),n=X(e);return n.current=e,y(B,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,buttonsStyles:e.buttonsStyles,strings:e.strings,locale:e.locale,country:e.country,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:ee(e),onError:r=>n.current.onError?.(r),onEvent:r=>{let i=n.current;i.onEvent?.(r);let a=i[$[r.name]];a&&C(()=>a(r.payload))}})}function te(e){return y(l,{...e})}var ne=b,oe=v;function re({publishableKey:e,runtimeUrl:t,children:n}){return y(O.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var ae=["card","apple_pay","google_pay","apms"],ue=["paypal","apple_pay","google_pay","apms"];function ie(e){return y(l,{...e,hiddenPaymentMethods:ae})}function de(e){return y(l,{...e,hiddenPaymentMethods:ue})}function se({mode:e,getSession:t,onSuccess:n,onComplete:r,...i}){return y(l,{...i,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:a=>{r&&C(()=>r(a)),n&&C(()=>n(a))}})}export{ie as DirectPayPalButton,se as FloPayAutomaticPaymentButton,ne as FloPayCardSetup,l as FloPayCheckout,oe as FloPayPaymentMethodSetup,re as FloPayProvider,b as FloPayRuntimeCardSetup,l as FloPayRuntimeCheckout,v as FloPayRuntimePaymentMethodSetup,te as SplitCardForm,de as VaultCardFields,ve as dropThirdPartyOnlyError};
1
+ import{a as A}from"./chunk-ZG2NKEN7.mjs";import{a as g,c as L}from"./chunk-QHQ55OPE.mjs";import{dropThirdPartyOnlyError as He}from"@flopay/shared";import{isValidElement as re,useContext as ae,useEffect as ue,useMemo as ie,useRef as K,useState as de}from"react";import{loadCheckoutRuntime as Y}from"@flopay/js";import{FloPayError as I}from"@flopay/shared";import{useEffect as P,useRef as R}from"react";import{jsx as ne}from"react/jsx-runtime";var G="2.2.0",q="2.3.0",z="2.5.0",Q="2.6.0",W="2.10.0",X=new Set(["enableAVS","avsLayout","cardFieldOrder","cardButtonContent","cardBackButtonContent","cardTitleContent"]),Z=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function $(e,n,t,u,r,d){return d||n!==void 0&&Object.keys(n).some(i=>X.has(i))?W:r!==void 0?"2.9.0":u!==void 0?"2.8.0":t!==void 0?"2.7.0":n!==void 0&&Object.keys(n).some(i=>!Z.has(i))?Q:n!==void 0&&"hiddenPaymentMethods"in n?z:e?q:G}function ee(e,n){let t={mode:e};return n&&Object.defineProperty(t,"getSession",{enumerable:!0,get:n}),t}function te(e){return e instanceof I?e:new I("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function V(e){let{publishableKey:n,sessionId:t,nonce:u,appearance:r,strings:d,locale:i,country:f,layout:p,runtimeUrl:F,runtimeTimeoutMs:o,buttonClicks:c}=e,l=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),h=e.createSession===void 0?void 0:JSON.stringify(e.createSession),y=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),b=e.buttonsStyles===void 0?void 0:JSON.stringify(e.buttonsStyles),M=e.automaticPayment?.mode,x=e.automaticPayment?.getSession!==void 0,k=R(void 0),E=R(void 0),O=R(void 0),T=R(null),s=R(null),a=R(e);return a.current=e,P(()=>{let C=!0;return Y({runtimeUrl:F,timeoutMs:o}).then(v=>{let _=T.current;if(!C||!_)return;let B=a.current.paymentMethodLayout;k.current=B===void 0?void 0:JSON.stringify(B),E.current=a.current.buttonsStyles===void 0?void 0:JSON.stringify(a.current.buttonsStyles),O.current=a.current.country;let w=l===void 0?void 0:JSON.parse(l);s.current=v.mount(_,{...w,contractVersion:$(!!M,w,a.current.locale,a.current.buttonsStyles,a.current.country,c),...M?{automaticPayment:ee(M,x?()=>a.current.automaticPayment?.getSession:void 0)}:{},publishableKey:n,sessionId:t,nonce:u,createSession:h===void 0?void 0:JSON.parse(h),appearance:a.current.appearance,buttonsStyles:a.current.buttonsStyles,strings:a.current.strings,locale:a.current.locale,...a.current.country===void 0?{}:{country:a.current.country},paymentMethodLayout:k.current===void 0?void 0:JSON.parse(k.current),...p?{layout:p}:{},onEvent:j=>a.current.onEvent?.(j)})},v=>{C&&a.current.onError?.(te(v))}),()=>{C=!1,s.current?.unmount(),s.current=null}},[n,t,u,h,p,M,x,F,o,l,c]),P(()=>{r!==void 0&&s.current?.update({appearance:r})},[r]),P(()=>{b===void 0||b===E.current||!s.current||(E.current=b,s.current.update({buttonsStyles:a.current.buttonsStyles}))},[b]),P(()=>{d!==void 0&&s.current?.update({strings:d})},[d]),P(()=>{i!==void 0&&s.current?.update({locale:i})},[i]),P(()=>{f===O.current||!s.current||(O.current=f,s.current.update({country:f??""}))},[f]),P(()=>{if(y===void 0||y===k.current)return;let C=s.current;C&&(k.current=y,C.update({paymentMethodLayout:JSON.parse(y)}))},[y]),ne("div",{ref:T,"data-flopay-runtime-checkout":""})}import{createContext as oe}from"react";var N=oe({});import{Fragment as ke,jsx as m,jsxs as ge}from"react/jsx-runtime";var se=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId","enableAVS","avsLayout","cardFieldOrder"],H=["cardButtonContent","cardBackButtonContent","cardTitleContent"],le={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function U(e){if(typeof e=="string")return e;if(typeof e=="number")return String(e)}function J(e){return e!=null&&typeof e!="boolean"&&U(e)===void 0}function ce({content:e,onMarkup:n}){let t=K(null);return ue(()=>{t.current&&n(t.current.innerHTML)}),m("div",{ref:t,hidden:!0,"aria-hidden":"true","data-flopay-slot-markup":"",children:re(e)||Array.isArray(e)?e:null})}function ye(e,n){let t={};for(let r of se)e[r]!==void 0&&(t[r]=e[r]);for(let r of H){let i=U(e[r])??(J(e[r])?n[r]:void 0);i!==void 0&&(t[r]=i)}let u=[...e.hiddenPaymentMethods??[]];return e.showPayPal===!1&&!u.includes("paypal")&&u.push("paypal"),(e.hiddenPaymentMethods!==void 0||u.length>0)&&(t.hiddenPaymentMethods=u),Object.keys(t).length===0?void 0:t}function D(e){return e.moreOptionsLabel===void 0&&e.submitLabel===void 0?e.strings:{...e.strings,...e.moreOptionsLabel===void 0?{}:{morePaymentOptions:e.moreOptionsLabel},...e.submitLabel===void 0?{}:{payButton:e.submitLabel}}}function S(e){let n=ae(N),t=K(e);t.current=e;let[u,r]=de({}),d=o=>c=>r(l=>l[o]===c?l:{...l,[o]:c}),i=JSON.stringify(D(e)??null),f=ie(()=>D(t.current),[i]),p=H.filter(o=>J(e[o])),F=m(V,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,buttonsStyles:e.buttonsStyles,strings:f,locale:e.locale,country:e.country,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??n.publishableKey??"",runtimeUrl:e.runtimeUrl??n.runtimeUrl??"",extraMountOptions:ye(e,u),buttonClicks:e.onButtonClick!==void 0,onError:o=>t.current.onError?.(o),onEvent:o=>{let c=t.current;if(c.onEvent?.(o),o.name==="buttonClick"){let h=o.payload?.method,y=c.onButtonClick;y&&typeof h=="string"&&g(()=>y(h));return}let l=c[le[o.name]];l&&g(()=>l(o.payload))}});return p.length===0?F:ge(ke,{children:[F,p.map(o=>m(ce,{content:e[o],onMarkup:d(o)},o))]})}function me(e){return m(S,{...e})}var Pe=L,fe=A;function pe({publishableKey:e,runtimeUrl:n,children:t}){return m(N.Provider,{value:{publishableKey:e,runtimeUrl:n},children:t})}var he=["card","apple_pay","google_pay","apms"],Ce=["paypal","apple_pay","google_pay","apms"];function Re(e){return m(S,{...e,hiddenPaymentMethods:he})}function Se(e){return m(S,{...e,hiddenPaymentMethods:Ce})}function Fe({mode:e,getSession:n,onSuccess:t,onComplete:u,...r}){return m(S,{...r,automaticPayment:{mode:e??"automatic",...n?{getSession:n}:{}},onComplete:d=>{u&&g(()=>u(d)),t&&g(()=>t(d))}})}export{Re as DirectPayPalButton,Fe as FloPayAutomaticPaymentButton,Pe as FloPayCardSetup,S as FloPayCheckout,fe as FloPayPaymentMethodSetup,pe as FloPayProvider,L as FloPayRuntimeCardSetup,S as FloPayRuntimeCheckout,A as FloPayRuntimePaymentMethodSetup,me as SplitCardForm,Se as VaultCardFields,He as dropThirdPartyOnlyError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/react",
3
- "version": "2.2.14",
3
+ "version": "2.3.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "publishConfig": {
@@ -36,8 +36,8 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@flopay/js": "2.2.14",
40
- "@flopay/shared": "2.2.14"
39
+ "@flopay/js": "2.3.0",
40
+ "@flopay/shared": "2.3.0"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=18.0.0",