@flopay/react 2.2.8 → 2.2.10
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 +2 -0
- package/dist/flopay-runtime-checkout.d.ts +7 -0
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
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
|
|
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
|
|
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.
|
|
3
|
+
"version": "2.2.10",
|
|
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.
|
|
40
|
-
"@flopay/shared": "2.2.
|
|
39
|
+
"@flopay/js": "2.2.10",
|
|
40
|
+
"@flopay/shared": "2.2.10"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=18.0.0",
|