@flopay/react 2.1.1 → 2.2.1
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 +3 -0
- package/dist/flopay-runtime-checkout.d.ts +3 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -232,6 +232,8 @@ The billing API can route hosted and eligible saved cards to an approved Worldpa
|
|
|
232
232
|
|
|
233
233
|
On the setup components, `appearance` and `buttonsStyles` still win over the bundle for the fields they touch; see the [ButtonsLayoutStyles reference](https://flopay.com/docs/technical-reference/react/flopay-checkout#buttonslayoutstyles-reference) for every override field.
|
|
234
234
|
|
|
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
|
+
|
|
235
237
|
`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).
|
|
236
238
|
|
|
237
239
|
`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.
|
|
@@ -540,6 +542,7 @@ export function OneClickUpsell() {
|
|
|
540
542
|
| `paymentMethodLayout` | `PaymentMethodLayoutRules?` | Order of `'card'`, `'paypal'`, `'wallets'` and `'apms'`, the groups behind "More payment options", and per-country rules, resolved for each buyer by the billing API; without it, PayPal, wallets, APMs, card, and no link |
|
|
541
543
|
| `theme` | `ThemeId?` | Theme of the hosted card form, a preset or raw colours; omitted, the form keeps its default look |
|
|
542
544
|
| `appearance` | `FloPayAppearance?` | Stripe-side appearance overrides |
|
|
545
|
+
| `buttonsStyles` | `ButtonsLayoutStyles?` | Hosted card-form style overrides; live updates require runtime contract 2.8.0 |
|
|
543
546
|
| `showPayPal` | `boolean?` | Show PayPal (default `true`) |
|
|
544
547
|
| `enabledPaymentMethods` | `string[]?` | The only payment methods offered, by method or group name (`card`, `paypal`, `apple_pay`, `google_pay`, `apms`, or a method such as `ideal`); a method must also be offered by the session and not hidden. Omitted or empty, every offered method is shown |
|
|
545
548
|
| `initialPayPalOrderId` | `string?` | A PayPal order you already created: the buyer's PayPal click resumes it instead of creating a new one |
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { CheckoutRuntimeAutomaticPayment, CheckoutRuntimeEvent } from '@flopay/js';
|
|
2
|
-
import type { PaymentMethodLayoutRules } from '@flopay/shared';
|
|
2
|
+
import type { ButtonsLayoutStyles, PaymentMethodLayoutRules } from '@flopay/shared';
|
|
3
3
|
import { FloPayError } from '@flopay/shared';
|
|
4
4
|
import type { ReactElement } from 'react';
|
|
5
5
|
export interface FloPayRuntimeCheckoutProps {
|
|
@@ -13,6 +13,8 @@ export interface FloPayRuntimeCheckoutProps {
|
|
|
13
13
|
*/
|
|
14
14
|
createSession?: Record<string, unknown>;
|
|
15
15
|
appearance?: Record<string, unknown>;
|
|
16
|
+
/** Existing card/button/input/AVS appearance, relayed to the secure frame (2.8.0). */
|
|
17
|
+
buttonsStyles?: ButtonsLayoutStyles;
|
|
16
18
|
/** Merchant wording overrides, applied by the runtime over the strings the API returns. */
|
|
17
19
|
strings?: Record<string, string>;
|
|
18
20
|
/** Merchant language override; the API selects and returns the resolved language. */
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
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});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flopay/react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
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.
|
|
40
|
-
"@flopay/shared": "2.
|
|
39
|
+
"@flopay/js": "2.2.1",
|
|
40
|
+
"@flopay/shared": "2.2.1"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"react": ">=18.0.0",
|