@flopay/react 2.2.8 → 2.2.9

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
@@ -234,6 +234,8 @@ On the setup components, `appearance` and `buttonsStyles` still win over the bun
234
234
 
235
235
  The checkout components also accept `buttonsStyles` from runtime contract 2.8.0. It preserves the existing `ButtonsLayoutStyles` card, input, submit-button and address-field styling through the hosted frame. Updating the prop re-styles the existing frame without remounting or reading the session again. Omitting it keeps the current overrides; `{}` clears them. The billing API and session still own country, address requirements and payment-method availability.
236
236
 
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
+
237
239
  `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).
238
240
 
239
241
  `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.
@@ -19,6 +19,13 @@ export interface FloPayRuntimeCheckoutProps {
19
19
  strings?: Record<string, string>;
20
20
  /** Merchant language override; the API selects and returns the resolved language. */
21
21
  locale?: string;
22
+ /**
23
+ * The buyer's country (ISO alpha-2), as the 1.x `country` prop (contract 2.9.0). The runtime
24
+ * offers a payment method with a country rule only when the country is in it; the country the
25
+ * buyer picks in the AVS form wins over this one, and this one over the session's. A later
26
+ * change applies to the mounted checkout; removing it lets the session's country apply again.
27
+ */
28
+ country?: string;
22
29
  /**
23
30
  * The merchant's payment method layout rules. The runtime has the billing API resolve them
24
31
  * for the buyer and lays out the payment method groups in that order, with the groups behind
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var w=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ue=Object.prototype.hasOwnProperty;var ie=(e,t)=>{for(var n in t)w(e,n,{get:t[n],enumerable:!0})},se=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of ae(t))!ue.call(e,r)&&r!==n&&w(e,r,{get:()=>t[r],enumerable:!(o=re(t,r))||o.enumerable});return e};var le=e=>se(w({},"__esModule",{value:!0}),e);var Me={};ie(Me,{DirectPayPalButton:()=>$,FloPayAutomaticPaymentButton:()=>te,FloPayCardSetup:()=>W,FloPayCheckout:()=>F,FloPayPaymentMethodSetup:()=>X,FloPayProvider:()=>Z,FloPayRuntimeCardSetup:()=>O,FloPayRuntimeCheckout:()=>F,FloPayRuntimePaymentMethodSetup:()=>x,SplitCardForm:()=>Q,VaultCardFields:()=>ee,dropThirdPartyOnlyError:()=>ne.dropThirdPartyOnlyError});module.exports=le(Me);var ne=require("@flopay/shared");var H=require("@flopay/js"),A=require("@flopay/shared"),h=require("react");var c=require("@flopay/shared");var L=require("react/jsx-runtime"),de="2.4.0";function J(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var ce=new Set(["validation_error","api_error","authentication_error","rate_limit_error","network_error"]);function M(e,t,n,o={}){return Object.assign(new A.FloPayError(e,t,o),{retryable:n})}function me(e){let t=J(e)?e:{},n=typeof t.type=="string"&&ce.has(t.type)?t.type:"";return M(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 ye(e){return e instanceof A.FloPayError?M(e.message,e.type,!0,{code:e.code??"runtime_load_failed",cause:e}):M("The checkout runtime failed to load.","network_error",!0,{code:"runtime_load_failed",cause:e})}function U(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 N({kind:e,props:t}){let{sessionId:n,nonce:o,runtimeUrl:r,runtimeTimeoutMs:l,locale:R}=t,E=(0,h.useRef)(null),S=(0,h.useRef)(null),P=(0,h.useRef)(t);P.current=t;let b=U(t),f=JSON.stringify(b),p=(0,h.useRef)(f);return(0,h.useEffect)(()=>{let y=E.current;if(!y)return;let s=!0,k=i=>{(0,c.invokeMerchantCallback)(()=>P.current.onError?.(i))},C=i=>{let m=P.current,a=i.payload;switch(i.name){case"setupReady":(0,c.invokeMerchantCallback)(()=>m.onReady?.());return;case"setupValidation":{let u=J(a)&&typeof a.message=="string"?a.message:null;(0,c.invokeMerchantCallback)(()=>m.onValidation?.(u));return}case"complete":(0,c.invokeMerchantCallback)(()=>m.onComplete?.(a));return;case"decline":(0,c.invokeMerchantCallback)(()=>m.onDecline?.(a));return;case"cancel":(0,c.invokeMerchantCallback)(()=>m.onCancel?.(a));return;case"error":k(me(a));return;default:return}};return(0,H.loadCheckoutRuntime)({runtimeUrl:r,...l===void 0?{}:{timeoutMs:l}}).then(i=>{if(!s)return;if(typeof i.mountSetup!="function"){k(M("The checkout runtime on this page is too old to run setup.","api_error",!1,{code:"runtime_setup_unsupported"}));return}let m=U(P.current);p.current=JSON.stringify(m),S.current=i.mountSetup(y,{setup:e,sessionId:n,nonce:o,contractVersion:R===void 0?de:"2.7.0",locale:R,...m,onEvent:C})},i=>{s&&k(ye(i))}),()=>{s=!1;let i=S.current;S.current=null,i?.unmount()}},[e,n,o,r,l,R]),(0,h.useEffect)(()=>{let y=S.current;if(!y||p.current===f)return;p.current=f;let s=P.current;y.update({theme:s.theme,appearance:s.appearance,buttonsStyles:s.buttonsStyles,containerStyle:s.containerStyle,strings:s.strings})},[f]),(0,L.jsx)("div",{ref:E})}function O(e){return(0,L.jsx)(N,{kind:"card",props:e})}var j=require("react/jsx-runtime");function x(e){return(0,j.jsx)(N,{kind:"payment_method",props:e})}var T=require("react");var Y=require("@flopay/js"),I=require("@flopay/shared"),d=require("react"),q=require("react/jsx-runtime"),pe="2.2.0",Pe="2.3.0",fe="2.5.0",he="2.6.0",Re=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function Se(e,t,n,o){return o!==void 0?"2.8.0":n!==void 0?"2.7.0":t!==void 0&&Object.keys(t).some(r=>!Re.has(r))?he:t!==void 0&&"hiddenPaymentMethods"in t?fe:e?Pe:pe}function Ce(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function Fe(e){return e instanceof I.FloPayError?e:new I.FloPayError("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function G(e){let{publishableKey:t,sessionId:n,nonce:o,appearance:r,strings:l,locale:R,layout:E,runtimeUrl:S,runtimeTimeoutMs:P}=e,b=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),f=e.createSession===void 0?void 0:JSON.stringify(e.createSession),p=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),y=e.buttonsStyles===void 0?void 0:JSON.stringify(e.buttonsStyles),s=e.automaticPayment?.mode,k=e.automaticPayment?.getSession!==void 0,C=(0,d.useRef)(void 0),i=(0,d.useRef)(void 0),m=(0,d.useRef)(null),a=(0,d.useRef)(null),u=(0,d.useRef)(e);return u.current=e,(0,d.useEffect)(()=>{let v=!0;return(0,Y.loadCheckoutRuntime)({runtimeUrl:S,timeoutMs:P}).then(_=>{let B=m.current;if(!v||!B)return;let V=u.current.paymentMethodLayout;C.current=V===void 0?void 0:JSON.stringify(V),i.current=u.current.buttonsStyles===void 0?void 0:JSON.stringify(u.current.buttonsStyles);let K=b===void 0?void 0:JSON.parse(b);a.current=_.mount(B,{...K,contractVersion:Se(!!s,K,u.current.locale,u.current.buttonsStyles),...s?{automaticPayment:Ce(s,k?()=>u.current.automaticPayment?.getSession:void 0)}:{},publishableKey:t,sessionId:n,nonce:o,createSession:f===void 0?void 0:JSON.parse(f),appearance:u.current.appearance,buttonsStyles:u.current.buttonsStyles,strings:u.current.strings,locale:u.current.locale,paymentMethodLayout:C.current===void 0?void 0:JSON.parse(C.current),...E?{layout:E}:{},onEvent:oe=>u.current.onEvent?.(oe)})},_=>{v&&u.current.onError?.(Fe(_))}),()=>{v=!1,a.current?.unmount(),a.current=null}},[t,n,o,f,E,s,k,S,P,b]),(0,d.useEffect)(()=>{r!==void 0&&a.current?.update({appearance:r})},[r]),(0,d.useEffect)(()=>{y===void 0||y===i.current||!a.current||(i.current=y,a.current.update({buttonsStyles:u.current.buttonsStyles}))},[y]),(0,d.useEffect)(()=>{l!==void 0&&a.current?.update({strings:l})},[l]),(0,d.useEffect)(()=>{R!==void 0&&a.current?.update({locale:R})},[R]),(0,d.useEffect)(()=>{if(p===void 0||p===C.current)return;let v=a.current;v&&(C.current=p,v.update({paymentMethodLayout:JSON.parse(p)}))},[p]),(0,q.jsx)("div",{ref:m,"data-flopay-runtime-checkout":""})}var z=require("react"),D=(0,z.createContext)({});var g=require("react/jsx-runtime"),ge=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],Ee={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function ke(e){let t={};for(let o of ge)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 F(e){let t=(0,T.useContext)(D),n=(0,T.useRef)(e);return n.current=e,(0,g.jsx)(G,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,buttonsStyles:e.buttonsStyles,strings:e.strings,locale:e.locale,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:ke(e),onError:o=>n.current.onError?.(o),onEvent:o=>{let r=n.current;r.onEvent?.(o);let l=r[Ee[o.name]];l&&(0,c.invokeMerchantCallback)(()=>l(o.payload))}})}function Q(e){return(0,g.jsx)(F,{...e})}var W=O,X=x;function Z({publishableKey:e,runtimeUrl:t,children:n}){return(0,g.jsx)(D.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var ve=["card","apple_pay","google_pay","apms"],be=["paypal","apple_pay","google_pay","apms"];function $(e){return(0,g.jsx)(F,{...e,hiddenPaymentMethods:ve})}function ee(e){return(0,g.jsx)(F,{...e,hiddenPaymentMethods:be})}function te({mode:e,getSession:t,onSuccess:n,onComplete:o,...r}){return(0,g.jsx)(F,{...r,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:l=>{o&&(0,c.invokeMerchantCallback)(()=>o(l)),n&&(0,c.invokeMerchantCallback)(()=>n(l))}})}0&&(module.exports={DirectPayPalButton,FloPayAutomaticPaymentButton,FloPayCardSetup,FloPayCheckout,FloPayPaymentMethodSetup,FloPayProvider,FloPayRuntimeCardSetup,FloPayRuntimeCheckout,FloPayRuntimePaymentMethodSetup,SplitCardForm,VaultCardFields,dropThirdPartyOnlyError});
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});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a as M}from"./chunk-ZG2NKEN7.mjs";import{a as h,c as E}from"./chunk-QHQ55OPE.mjs";import{dropThirdPartyOnlyError as Me}from"@flopay/shared";import{useContext as z,useRef as Q}from"react";import{loadCheckoutRuntime as B}from"@flopay/js";import{FloPayError as T}from"@flopay/shared";import{useEffect as s,useRef as P}from"react";import{jsx as G}from"react/jsx-runtime";var D="2.2.0",V="2.3.0",K="2.5.0",U="2.6.0",H=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function J(e,t,n,o){return o!==void 0?"2.8.0":n!==void 0?"2.7.0":t!==void 0&&Object.keys(t).some(r=>!H.has(r))?U:t!==void 0&&"hiddenPaymentMethods"in t?K:e?V:D}function j(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function Y(e){return e instanceof T?e:new T("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function _(e){let{publishableKey:t,sessionId:n,nonce:o,appearance:r,strings:u,locale:C,layout:R,runtimeUrl:v,runtimeTimeoutMs:O}=e,F=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),S=e.createSession===void 0?void 0:JSON.stringify(e.createSession),y=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),p=e.buttonsStyles===void 0?void 0:JSON.stringify(e.buttonsStyles),f=e.automaticPayment?.mode,x=e.automaticPayment?.getSession!==void 0,m=P(void 0),k=P(void 0),A=P(null),i=P(null),a=P(e);return a.current=e,s(()=>{let d=!0;return B({runtimeUrl:v,timeoutMs:O}).then(g=>{let L=A.current;if(!d||!L)return;let N=a.current.paymentMethodLayout;m.current=N===void 0?void 0:JSON.stringify(N),k.current=a.current.buttonsStyles===void 0?void 0:JSON.stringify(a.current.buttonsStyles);let w=F===void 0?void 0:JSON.parse(F);i.current=g.mount(L,{...w,contractVersion:J(!!f,w,a.current.locale,a.current.buttonsStyles),...f?{automaticPayment:j(f,x?()=>a.current.automaticPayment?.getSession:void 0)}:{},publishableKey:t,sessionId:n,nonce:o,createSession:S===void 0?void 0:JSON.parse(S),appearance:a.current.appearance,buttonsStyles:a.current.buttonsStyles,strings:a.current.strings,locale:a.current.locale,paymentMethodLayout:m.current===void 0?void 0:JSON.parse(m.current),...R?{layout:R}:{},onEvent:I=>a.current.onEvent?.(I)})},g=>{d&&a.current.onError?.(Y(g))}),()=>{d=!1,i.current?.unmount(),i.current=null}},[t,n,o,S,R,f,x,v,O,F]),s(()=>{r!==void 0&&i.current?.update({appearance:r})},[r]),s(()=>{p===void 0||p===k.current||!i.current||(k.current=p,i.current.update({buttonsStyles:a.current.buttonsStyles}))},[p]),s(()=>{u!==void 0&&i.current?.update({strings:u})},[u]),s(()=>{C!==void 0&&i.current?.update({locale:C})},[C]),s(()=>{if(y===void 0||y===m.current)return;let d=i.current;d&&(m.current=y,d.update({paymentMethodLayout:JSON.parse(y)}))},[y]),G("div",{ref:A,"data-flopay-runtime-checkout":""})}import{createContext as q}from"react";var b=q({});import{jsx as c}from"react/jsx-runtime";var W=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],X={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function Z(e){let t={};for(let o of W)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 l(e){let t=z(b),n=Q(e);return n.current=e,c(_,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,buttonsStyles:e.buttonsStyles,strings:e.strings,locale:e.locale,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:Z(e),onError:o=>n.current.onError?.(o),onEvent:o=>{let r=n.current;r.onEvent?.(o);let u=r[X[o.name]];u&&h(()=>u(o.payload))}})}function $(e){return c(l,{...e})}var ee=E,te=M;function ne({publishableKey:e,runtimeUrl:t,children:n}){return c(b.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var oe=["card","apple_pay","google_pay","apms"],ae=["paypal","apple_pay","google_pay","apms"];function re(e){return c(l,{...e,hiddenPaymentMethods:oe})}function ue(e){return c(l,{...e,hiddenPaymentMethods:ae})}function ie({mode:e,getSession:t,onSuccess:n,onComplete:o,...r}){return c(l,{...r,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:u=>{o&&h(()=>o(u)),n&&h(()=>n(u))}})}export{re as DirectPayPalButton,ie as FloPayAutomaticPaymentButton,ee as FloPayCardSetup,l as FloPayCheckout,te as FloPayPaymentMethodSetup,ne as FloPayProvider,E as FloPayRuntimeCardSetup,l as FloPayRuntimeCheckout,M as FloPayRuntimePaymentMethodSetup,$ as SplitCardForm,ue as VaultCardFields,Me as dropThirdPartyOnlyError};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/react",
3
- "version": "2.2.8",
3
+ "version": "2.2.9",
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.8",
40
- "@flopay/shared": "2.2.8"
39
+ "@flopay/js": "2.2.9",
40
+ "@flopay/shared": "2.2.9"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=18.0.0",