@flopay/react 2.0.0 → 2.0.2

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
@@ -208,7 +208,7 @@ The billing API can route hosted and eligible saved cards to an approved Worldpa
208
208
 
209
209
  #### Themes and layouts
210
210
 
211
- `FloPayCardSetup` and `FloPayPaymentMethodSetup` accept one `theme` prop, a `ThemeId`, and the hosted runtime applies it to the setup form (see **FloPayCardSetup** below). The checkout components (`FloPayCheckout`, `FloPayAutomaticPaymentButton`, `SplitCardForm`, `DirectPayPalButton` and `VaultCardFields`) accept the same prop and forward it to the runtime unchanged; see **Known limits in 2.0.0** under Public API.
211
+ `FloPayCardSetup` and `FloPayPaymentMethodSetup` accept one `theme` prop, a `ThemeId`, and the hosted runtime applies it to the setup form (see **FloPayCardSetup** below). The checkout components (`FloPayCheckout`, `FloPayAutomaticPaymentButton`, `SplitCardForm`, `DirectPayPalButton` and `VaultCardFields`) accept the same prop, and the runtime applies it to the hosted card form; see **Known limits in 2.0.0** under Public API.
212
212
 
213
213
  | Theme | Aesthetic |
214
214
  |-------|-----------|
@@ -525,15 +525,15 @@ export function OneClickUpsell() {
525
525
  | `createSession` | `InlineSessionDraft?` | Creates the session inline instead of using `sessionId` |
526
526
  | `layout` | `'default' \| 'buttons'` | Payment form layout |
527
527
  | `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 |
528
- | `theme` | `ThemeId?` | Forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
528
+ | `theme` | `ThemeId?` | Theme of the hosted card form, a preset or raw colours; omitted, the form keeps its default look |
529
529
  | `appearance` | `FloPayAppearance?` | Stripe-side appearance overrides |
530
530
  | `showPayPal` | `boolean?` | Show PayPal (default `true`) |
531
- | `enabledPaymentMethods` | `string[]?` | Forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
532
- | `initialPayPalOrderId` | `string?` | Forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
533
- | `showCardBrandIcons` | `boolean?` | Forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
534
- | `showCardFieldLabels` | `boolean?` | Forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
535
- | `cardFieldLabels` | `CardFieldLabels?` | `number`, `expiry`, `cvv` and `name` text, forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
536
- | `cardFieldPlaceholders` | `CardFieldPlaceholders?` | `number`, `expiry`, `cvv` and `name` text, forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
531
+ | `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 |
532
+ | `initialPayPalOrderId` | `string?` | A PayPal order you already created: the buyer's PayPal click resumes it instead of creating a new one |
533
+ | `showCardBrandIcons` | `boolean?` | Shows or hides the card brand icons in the hosted card form; omitted, nothing is sent |
534
+ | `showCardFieldLabels` | `boolean?` | Shows or hides a label above each hosted card field; omitted, nothing is sent |
535
+ | `cardFieldLabels` | `CardFieldLabels?` | The hosted card fields' label text: optional `number`, `expiry`, `cvv` and `name`; omitted, nothing is sent |
536
+ | `cardFieldPlaceholders` | `CardFieldPlaceholders?` | The hosted card fields' placeholder text: optional `number`, `expiry`, `cvv` and `name`; omitted, nothing is sent |
537
537
  | `onCardFieldsReady` | `(event: CardFieldsReadyEvent) => void` | The hosted card fields are interactive; once per card form, with `elapsedMs` since it mounted |
538
538
  | `onCardFieldsFailed` | `(event: CardFieldsFailedEvent) => void` | The card fields failed to load or were not ready in time; not a decline or payment error |
539
539
  | `onComplete` | `(result: PaymentResult) => void` | Payment succeeded or was authorized |
@@ -590,7 +590,7 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
590
590
  | `sessionId` / `nonce` | `string?` | Reuse an existing auto-mode session |
591
591
  | `getSession` | `({ signal }: { signal: AbortSignal }) => Promise<OneClickSession>` | Fetches a server-minted `{ sessionId, nonce }` (from `@flopay/node` `createOneClick`) on click. 15s timeout, aborted on unmount |
592
592
  | `createSession` | `InlineSessionDraft?` | Inline draft for the session to create (deprecated: use `getSession`) |
593
- | `theme` | `ThemeId?` | Forwarded to the runtime as given; omitted, nothing is sent. See **Known limits in 2.0.0** |
593
+ | `theme` | `ThemeId?` | Theme of the hosted card form in the fallback checkout, as on `FloPayCheckout` |
594
594
  | `onSuccess` | `(event: FloPayAutomaticPaymentSuccessEvent) => void` | Payment completed |
595
595
  | `onDecline` | `(decline: DeclineEvent) => void` | Payment declined. Carries the failed session's `sessionId` |
596
596
  | `onError` | `(error: FloPayError) => void` | Payment or setup error. Carries `sessionId` when the failure happened after the session was created |
@@ -603,12 +603,12 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
603
603
  | `nonce` | `string?` | Session-bound token forwarded on intent, decline, account, and process calls |
604
604
  | `layout` | `'default' \| 'buttons'` | Payment form layout |
605
605
  | `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 |
606
- | `theme` | `ThemeId?` | Forwarded to the runtime as given, as on `FloPayCheckout` |
607
- | `enabledPaymentMethods` | `string[]?` | Forwarded to the runtime as given, as on `FloPayCheckout` |
608
- | `showCardBrandIcons` | `boolean?` | Forwarded to the runtime as given, as on `FloPayCheckout` |
609
- | `showCardFieldLabels` | `boolean?` | Forwarded to the runtime as given, as on `FloPayCheckout` |
610
- | `cardFieldLabels` | `CardFieldLabels?` | Forwarded to the runtime as given, as on `FloPayCheckout` |
611
- | `cardFieldPlaceholders` | `CardFieldPlaceholders?` | Forwarded to the runtime as given, as on `FloPayCheckout` |
606
+ | `theme` | `ThemeId?` | Theme of the hosted card form, as on `FloPayCheckout` |
607
+ | `enabledPaymentMethods` | `string[]?` | The only payment methods offered, as on `FloPayCheckout` |
608
+ | `showCardBrandIcons` | `boolean?` | Shows or hides the card brand icons, as on `FloPayCheckout` |
609
+ | `showCardFieldLabels` | `boolean?` | Shows or hides the card field labels, as on `FloPayCheckout` |
610
+ | `cardFieldLabels` | `CardFieldLabels?` | The card fields' label text, as on `FloPayCheckout` |
611
+ | `cardFieldPlaceholders` | `CardFieldPlaceholders?` | The card fields' placeholder text, as on `FloPayCheckout` |
612
612
  | `onCardFieldsReady` / `onCardFieldsFailed` | callbacks | Card-field lifecycle; see **Card-field lifecycle** above |
613
613
  | `onComplete` / `onDecline` / `onError` | callbacks | Checkout outcomes |
614
614
  | `onCancel` | `(event: FloPayPaymentCancelEvent) => void` | The buyer left the direct PayPal button's PayPal window without approving; see the PayPal section above |
@@ -663,23 +663,23 @@ No public prop, option or type names a payment processor any more. Payment metho
663
663
  - `fallbackPublishableKey`: `fallbackPublishableKey` is deleted with no replacement.
664
664
  - CheckoutGateways (`gateways.stripe`, `gateways.paypal`): `paymentMethods`: availability of `card`, `paypal`, `wallets` and `apms`, with no processor key. `gateways.stripe` becomes `card`, `wallets` and `apms`; `gateways.paypal` becomes `paypal`.
665
665
 
666
- `showPayPal` stays: `showPayPal: false` is forwarded as hiding `paypal`, merged with any `hiddenPaymentMethods` you pass. Omitting both hides nothing. The presentation props the runtime accepts (`appearance`, `strings`, `layout`, `paymentMethodLayout`, and the setup components' `theme`, `appearance` and `buttonsStyles`) are forwarded, not interpreted. Seven more 1.x checkout props stay and are forwarded too; see **Known limits in 2.0.0** below.
666
+ `showPayPal` stays: `showPayPal: false` is forwarded as hiding `paypal`, merged with any `hiddenPaymentMethods` you pass. Omitting both hides nothing. The presentation props the runtime accepts (`appearance`, `strings`, `layout`, `paymentMethodLayout`, and the setup components' `theme`, `appearance` and `buttonsStyles`) are forwarded, not interpreted. Seven more 1.x checkout props stay, are forwarded too and work again from runtime contract 2.6.0; see **Known limits in 2.0.0** below.
667
667
 
668
668
  **Default checkout mode.** A session created with no `checkoutMode` now defaults to `'full'` (it was `'confirm'` in 1.x), in `@flopay/js` and `@flopay/node`. An explicit `'confirm'`, `'auto'` or `'full'` is sent unchanged. Merchants who want the old default must set `checkoutMode: 'confirm'` and create the session from a server with merchant credentials (`@flopay/node` `checkout.sessions.createOneClick`, handed to `getSession`).
669
669
 
670
670
  ### Known limits in 2.0.0
671
671
 
672
- `FloPayCheckout`, `SplitCardForm`, `FloPayAutomaticPaymentButton`, `DirectPayPalButton` and `VaultCardFields` accept seven 1.x props and forward them to the hosted runtime unchanged, but **the runtime does not act on them yet, so in 2.0.0 they have no effect**: `theme`, `showCardBrandIcons`, `showCardFieldLabels`, `cardFieldLabels`, `cardFieldPlaceholders`, `enabledPaymentMethods` and `initialPayPalOrderId`. They are not removed. A page that sets them keeps compiling and raises no error, and it needs no change once the runtime supports them. Omitted, nothing is sent.
672
+ `FloPayCheckout`, `SplitCardForm`, `FloPayAutomaticPaymentButton`, `DirectPayPalButton` and `VaultCardFields` accept seven 1.x props and forward them to the hosted runtime, which acts on them (runtime contract 2.6.0): `theme`, `showCardBrandIcons`, `showCardFieldLabels`, `cardFieldLabels`, `cardFieldPlaceholders`, `enabledPaymentMethods` and `initialPayPalOrderId`. The 2.0.0 runtime ignored them; a page that already sets them needs no change for them to work. A mount that sets any of them declares contract 2.6.0. Omitted, nothing is sent.
673
673
 
674
- - `theme` leaves the checkout's look as it is. On `FloPayCardSetup` and `FloPayPaymentMethodSetup`, `theme` is applied, as described under **Themes and layouts**.
675
- - `showCardBrandIcons`, `showCardFieldLabels`, `cardFieldLabels` and `cardFieldPlaceholders` leave the hosted card form's own icons, labels and placeholder text as they are. `cardFieldLabels` and `cardFieldPlaceholders` take optional `number`, `expiry`, `cvv` and `name` text.
676
- - `enabledPaymentMethods` does not narrow the payment methods on offer. The session's `paymentMethods` decide which methods the runtime offers, and `hiddenPaymentMethods` hides them.
677
- - `initialPayPalOrderId` does not resume a PayPal order.
674
+ - `theme` styles the hosted card form: a `ThemeId`, or the raw colours as an object. On `FloPayCardSetup` and `FloPayPaymentMethodSetup`, `theme` is applied to the setup form, as described under **Themes and layouts**.
675
+ - `showCardBrandIcons` and `showCardFieldLabels` turn the hosted card form's brand icons and field labels on or off, and `cardFieldLabels` and `cardFieldPlaceholders` set its label and placeholder text, from optional `number`, `expiry`, `cvv` and `name` text. The runtime hands them to the card form when it loads and again whenever it becomes ready again. Changing one of them mounts the checkout again with the new value.
676
+ - `enabledPaymentMethods` narrows the payment methods on offer, by the same names as `hiddenPaymentMethods`: `card`, `paypal`, `apple_pay`, `google_pay`, `apms`, or one alternative method such as `ideal`. A method is shown only when the session's `paymentMethods` offer it, it is enabled and it is not hidden: the list never adds a method. Omitted or empty, every offered method is shown.
677
+ - `initialPayPalOrderId` resumes a PayPal order you already created: the buyer's PayPal click starts from that order instead of creating a new one, and approving it pays that order once.
678
678
 
679
679
  `appearance` still carries any `.Label` rule you set for the labels. In 1.x the labels used its `color`, `fontSize`, `fontWeight`, `letterSpacing`, `textTransform` and `marginBottom`, and every other `.Label` property was ignored.
680
680
 
681
681
  ```tsx
682
- // Forwarded unchanged in 2.0.0.
682
+ // Labels above the hosted card fields, with your own placeholder text.
683
683
  <FloPayCheckout
684
684
  sessionId={sessionId}
685
685
  nonce={sessionNonce}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var _=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var n in t)_(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of ne(t))!oe.call(e,a)&&a!==n&&_(e,a,{get:()=>t[a],enumerable:!(o=te(t,a))||o.enumerable});return e};var ue=e=>ae(_({},"__esModule",{value:!0}),e);var ge={};re(ge,{DirectPayPalButton:()=>W,FloPayAutomaticPaymentButton:()=>Z,FloPayCardSetup:()=>q,FloPayCheckout:()=>C,FloPayPaymentMethodSetup:()=>z,FloPayProvider:()=>Q,FloPayRuntimeCardSetup:()=>M,FloPayRuntimeCheckout:()=>C,FloPayRuntimePaymentMethodSetup:()=>b,SplitCardForm:()=>G,VaultCardFields:()=>X,dropThirdPartyOnlyError:()=>$.dropThirdPartyOnlyError});module.exports=ue(ge);var $=require("@flopay/shared");var B=require("@flopay/js"),w=require("@flopay/shared"),h=require("react");var d=require("@flopay/shared");var T=require("react/jsx-runtime"),ie="2.4.0";function U(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var se=new Set(["validation_error","api_error","authentication_error","rate_limit_error","network_error"]);function v(e,t,n,o={}){return Object.assign(new w.FloPayError(e,t,o),{retryable:n})}function le(e){let t=U(e)?e:{},n=typeof t.type=="string"&&se.has(t.type)?t.type:"";return v(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 de(e){return e instanceof w.FloPayError?v(e.message,e.type,!0,{code:e.code??"runtime_load_failed",cause:e}):v("The checkout runtime failed to load.","network_error",!0,{code:"runtime_load_failed",cause:e})}function V(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 O({kind:e,props:t}){let{sessionId:n,nonce:o,runtimeUrl:a,runtimeTimeoutMs:s}=t,F=(0,h.useRef)(null),R=(0,h.useRef)(null),P=(0,h.useRef)(t);P.current=t;let g=V(t),f=JSON.stringify(g),y=(0,h.useRef)(f);return(0,h.useEffect)(()=>{let c=F.current;if(!c)return;let l=!0,p=r=>{(0,d.invokeMerchantCallback)(()=>P.current.onError?.(r))},E=r=>{let u=P.current,i=r.payload;switch(r.name){case"setupReady":(0,d.invokeMerchantCallback)(()=>u.onReady?.());return;case"setupValidation":{let k=U(i)&&typeof i.message=="string"?i.message:null;(0,d.invokeMerchantCallback)(()=>u.onValidation?.(k));return}case"complete":(0,d.invokeMerchantCallback)(()=>u.onComplete?.(i));return;case"decline":(0,d.invokeMerchantCallback)(()=>u.onDecline?.(i));return;case"cancel":(0,d.invokeMerchantCallback)(()=>u.onCancel?.(i));return;case"error":p(le(i));return;default:return}};return(0,B.loadCheckoutRuntime)({runtimeUrl:a,...s===void 0?{}:{timeoutMs:s}}).then(r=>{if(!l)return;if(typeof r.mountSetup!="function"){p(v("The checkout runtime on this page is too old to run setup.","api_error",!1,{code:"runtime_setup_unsupported"}));return}let u=V(P.current);y.current=JSON.stringify(u),R.current=r.mountSetup(c,{setup:e,sessionId:n,nonce:o,contractVersion:ie,...u,onEvent:E})},r=>{l&&p(de(r))}),()=>{l=!1;let r=R.current;R.current=null,r?.unmount()}},[e,n,o,a,s]),(0,h.useEffect)(()=>{let c=R.current;if(!c||y.current===f)return;y.current=f;let l=P.current;c.update({theme:l.theme,appearance:l.appearance,buttonsStyles:l.buttonsStyles,containerStyle:l.containerStyle,strings:l.strings})},[f]),(0,T.jsx)("div",{ref:F})}function M(e){return(0,T.jsx)(O,{kind:"card",props:e})}var H=require("react/jsx-runtime");function b(e){return(0,H.jsx)(O,{kind:"payment_method",props:e})}var x=require("react");var K=require("@flopay/js"),A=require("@flopay/shared"),m=require("react"),j=require("react/jsx-runtime"),ce="2.2.0",me="2.3.0",ye="2.5.0";function pe(e,t){return t!==void 0&&"hiddenPaymentMethods"in t?ye:e?me:ce}function Pe(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function fe(e){return e instanceof A.FloPayError?e:new A.FloPayError("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function J(e){let{publishableKey:t,sessionId:n,nonce:o,appearance:a,strings:s,layout:F,runtimeUrl:R,runtimeTimeoutMs:P}=e,g=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),f=e.createSession===void 0?void 0:JSON.stringify(e.createSession),y=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),c=e.automaticPayment?.mode,l=e.automaticPayment?.getSession!==void 0,p=(0,m.useRef)(void 0),E=(0,m.useRef)(null),r=(0,m.useRef)(null),u=(0,m.useRef)(e);return u.current=e,(0,m.useEffect)(()=>{let i=!0;return(0,K.loadCheckoutRuntime)({runtimeUrl:R,timeoutMs:P}).then(k=>{let N=E.current;if(!i||!N)return;let I=u.current.paymentMethodLayout;p.current=I===void 0?void 0:JSON.stringify(I);let D=g===void 0?void 0:JSON.parse(g);r.current=k.mount(N,{...D,contractVersion:pe(!!c,D),...c?{automaticPayment:Pe(c,l?()=>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,strings:u.current.strings,paymentMethodLayout:p.current===void 0?void 0:JSON.parse(p.current),...F?{layout:F}:{},onEvent:ee=>u.current.onEvent?.(ee)})},k=>{i&&u.current.onError?.(fe(k))}),()=>{i=!1,r.current?.unmount(),r.current=null}},[t,n,o,f,F,c,l,R,P,g]),(0,m.useEffect)(()=>{a!==void 0&&r.current?.update({appearance:a})},[a]),(0,m.useEffect)(()=>{s!==void 0&&r.current?.update({strings:s})},[s]),(0,m.useEffect)(()=>{if(y===void 0||y===p.current)return;let i=r.current;i&&(p.current=y,i.update({paymentMethodLayout:JSON.parse(y)}))},[y]),(0,j.jsx)("div",{ref:E,"data-flopay-runtime-checkout":""})}var Y=require("react"),L=(0,Y.createContext)({});var S=require("react/jsx-runtime"),he=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],Re={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function Ce(e){let t={};for(let o of he)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 C(e){let t=(0,x.useContext)(L),n=(0,x.useRef)(e);return n.current=e,(0,S.jsx)(J,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,strings:e.strings,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:Ce(e),onError:o=>n.current.onError?.(o),onEvent:o=>{let a=n.current;a.onEvent?.(o);let s=a[Re[o.name]];s&&(0,d.invokeMerchantCallback)(()=>s(o.payload))}})}function G(e){return(0,S.jsx)(C,{...e})}var q=M,z=b;function Q({publishableKey:e,runtimeUrl:t,children:n}){return(0,S.jsx)(L.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var Se=["card","apple_pay","google_pay","apms"],Fe=["paypal","apple_pay","google_pay","apms"];function W(e){return(0,S.jsx)(C,{...e,hiddenPaymentMethods:Se})}function X(e){return(0,S.jsx)(C,{...e,hiddenPaymentMethods:Fe})}function Z({mode:e,getSession:t,onSuccess:n,onComplete:o,...a}){return(0,S.jsx)(C,{...a,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:s=>{o&&(0,d.invokeMerchantCallback)(()=>o(s)),n&&(0,d.invokeMerchantCallback)(()=>n(s))}})}0&&(module.exports={DirectPayPalButton,FloPayAutomaticPaymentButton,FloPayCardSetup,FloPayCheckout,FloPayPaymentMethodSetup,FloPayProvider,FloPayRuntimeCardSetup,FloPayRuntimeCheckout,FloPayRuntimePaymentMethodSetup,SplitCardForm,VaultCardFields,dropThirdPartyOnlyError});
1
+ "use strict";var O=Object.defineProperty;var te=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var oe=Object.prototype.hasOwnProperty;var re=(e,t)=>{for(var n in t)O(e,n,{get:t[n],enumerable:!0})},ae=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of ne(t))!oe.call(e,a)&&a!==n&&O(e,a,{get:()=>t[a],enumerable:!(o=te(t,a))||o.enumerable});return e};var ue=e=>ae(O({},"__esModule",{value:!0}),e);var ke={};re(ke,{DirectPayPalButton:()=>W,FloPayAutomaticPaymentButton:()=>Z,FloPayCardSetup:()=>q,FloPayCheckout:()=>C,FloPayPaymentMethodSetup:()=>z,FloPayProvider:()=>Q,FloPayRuntimeCardSetup:()=>M,FloPayRuntimeCheckout:()=>C,FloPayRuntimePaymentMethodSetup:()=>b,SplitCardForm:()=>G,VaultCardFields:()=>X,dropThirdPartyOnlyError:()=>$.dropThirdPartyOnlyError});module.exports=ue(ke);var $=require("@flopay/shared");var B=require("@flopay/js"),T=require("@flopay/shared"),h=require("react");var l=require("@flopay/shared");var w=require("react/jsx-runtime"),ie="2.4.0";function K(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}var se=new Set(["validation_error","api_error","authentication_error","rate_limit_error","network_error"]);function v(e,t,n,o={}){return Object.assign(new T.FloPayError(e,t,o),{retryable:n})}function de(e){let t=K(e)?e:{},n=typeof t.type=="string"&&se.has(t.type)?t.type:"";return v(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 le(e){return e instanceof T.FloPayError?v(e.message,e.type,!0,{code:e.code??"runtime_load_failed",cause:e}):v("The checkout runtime failed to load.","network_error",!0,{code:"runtime_load_failed",cause:e})}function V(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 _({kind:e,props:t}){let{sessionId:n,nonce:o,runtimeUrl:a,runtimeTimeoutMs:s}=t,F=(0,h.useRef)(null),R=(0,h.useRef)(null),P=(0,h.useRef)(t);P.current=t;let E=V(t),f=JSON.stringify(E),y=(0,h.useRef)(f);return(0,h.useEffect)(()=>{let c=F.current;if(!c)return;let d=!0,p=r=>{(0,l.invokeMerchantCallback)(()=>P.current.onError?.(r))},k=r=>{let u=P.current,i=r.payload;switch(r.name){case"setupReady":(0,l.invokeMerchantCallback)(()=>u.onReady?.());return;case"setupValidation":{let g=K(i)&&typeof i.message=="string"?i.message:null;(0,l.invokeMerchantCallback)(()=>u.onValidation?.(g));return}case"complete":(0,l.invokeMerchantCallback)(()=>u.onComplete?.(i));return;case"decline":(0,l.invokeMerchantCallback)(()=>u.onDecline?.(i));return;case"cancel":(0,l.invokeMerchantCallback)(()=>u.onCancel?.(i));return;case"error":p(de(i));return;default:return}};return(0,B.loadCheckoutRuntime)({runtimeUrl:a,...s===void 0?{}:{timeoutMs:s}}).then(r=>{if(!d)return;if(typeof r.mountSetup!="function"){p(v("The checkout runtime on this page is too old to run setup.","api_error",!1,{code:"runtime_setup_unsupported"}));return}let u=V(P.current);y.current=JSON.stringify(u),R.current=r.mountSetup(c,{setup:e,sessionId:n,nonce:o,contractVersion:ie,...u,onEvent:k})},r=>{d&&p(le(r))}),()=>{d=!1;let r=R.current;R.current=null,r?.unmount()}},[e,n,o,a,s]),(0,h.useEffect)(()=>{let c=R.current;if(!c||y.current===f)return;y.current=f;let d=P.current;c.update({theme:d.theme,appearance:d.appearance,buttonsStyles:d.buttonsStyles,containerStyle:d.containerStyle,strings:d.strings})},[f]),(0,w.jsx)("div",{ref:F})}function M(e){return(0,w.jsx)(_,{kind:"card",props:e})}var U=require("react/jsx-runtime");function b(e){return(0,U.jsx)(_,{kind:"payment_method",props:e})}var x=require("react");var H=require("@flopay/js"),A=require("@flopay/shared"),m=require("react"),j=require("react/jsx-runtime"),ce="2.2.0",me="2.3.0",ye="2.5.0",pe="2.6.0",Pe=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function fe(e,t){return t!==void 0&&Object.keys(t).some(n=>!Pe.has(n))?pe:t!==void 0&&"hiddenPaymentMethods"in t?ye:e?me:ce}function he(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function Re(e){return e instanceof A.FloPayError?e:new A.FloPayError("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function J(e){let{publishableKey:t,sessionId:n,nonce:o,appearance:a,strings:s,layout:F,runtimeUrl:R,runtimeTimeoutMs:P}=e,E=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),f=e.createSession===void 0?void 0:JSON.stringify(e.createSession),y=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),c=e.automaticPayment?.mode,d=e.automaticPayment?.getSession!==void 0,p=(0,m.useRef)(void 0),k=(0,m.useRef)(null),r=(0,m.useRef)(null),u=(0,m.useRef)(e);return u.current=e,(0,m.useEffect)(()=>{let i=!0;return(0,H.loadCheckoutRuntime)({runtimeUrl:R,timeoutMs:P}).then(g=>{let L=k.current;if(!i||!L)return;let I=u.current.paymentMethodLayout;p.current=I===void 0?void 0:JSON.stringify(I);let D=E===void 0?void 0:JSON.parse(E);r.current=g.mount(L,{...D,contractVersion:fe(!!c,D),...c?{automaticPayment:he(c,d?()=>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,strings:u.current.strings,paymentMethodLayout:p.current===void 0?void 0:JSON.parse(p.current),...F?{layout:F}:{},onEvent:ee=>u.current.onEvent?.(ee)})},g=>{i&&u.current.onError?.(Re(g))}),()=>{i=!1,r.current?.unmount(),r.current=null}},[t,n,o,f,F,c,d,R,P,E]),(0,m.useEffect)(()=>{a!==void 0&&r.current?.update({appearance:a})},[a]),(0,m.useEffect)(()=>{s!==void 0&&r.current?.update({strings:s})},[s]),(0,m.useEffect)(()=>{if(y===void 0||y===p.current)return;let i=r.current;i&&(p.current=y,i.update({paymentMethodLayout:JSON.parse(y)}))},[y]),(0,j.jsx)("div",{ref:k,"data-flopay-runtime-checkout":""})}var Y=require("react"),N=(0,Y.createContext)({});var S=require("react/jsx-runtime"),Ce=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],Se={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function Fe(e){let t={};for(let o of Ce)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 C(e){let t=(0,x.useContext)(N),n=(0,x.useRef)(e);return n.current=e,(0,S.jsx)(J,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,strings:e.strings,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:Fe(e),onError:o=>n.current.onError?.(o),onEvent:o=>{let a=n.current;a.onEvent?.(o);let s=a[Se[o.name]];s&&(0,l.invokeMerchantCallback)(()=>s(o.payload))}})}function G(e){return(0,S.jsx)(C,{...e})}var q=M,z=b;function Q({publishableKey:e,runtimeUrl:t,children:n}){return(0,S.jsx)(N.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var Ee=["card","apple_pay","google_pay","apms"],ge=["paypal","apple_pay","google_pay","apms"];function W(e){return(0,S.jsx)(C,{...e,hiddenPaymentMethods:Ee})}function X(e){return(0,S.jsx)(C,{...e,hiddenPaymentMethods:ge})}function Z({mode:e,getSession:t,onSuccess:n,onComplete:o,...a}){return(0,S.jsx)(C,{...a,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:s=>{o&&(0,l.invokeMerchantCallback)(()=>o(s)),n&&(0,l.invokeMerchantCallback)(()=>n(s))}})}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 S}from"./chunk-KPRDVWZP.mjs";import{a as P,c as k}from"./chunk-XRYDC367.mjs";import{dropThirdPartyOnlyError as Re}from"@flopay/shared";import{useContext as J,useRef as j}from"react";import{loadCheckoutRuntime as _}from"@flopay/js";import{FloPayError as w}from"@flopay/shared";import{useEffect as p,useRef as h}from"react";import{jsx as H}from"react/jsx-runtime";var T="2.2.0",I="2.3.0",B="2.5.0";function D(e,t){return t!==void 0&&"hiddenPaymentMethods"in t?B:e?I:T}function V(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function U(e){return e instanceof w?e:new w("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function L(e){let{publishableKey:t,sessionId:n,nonce:o,appearance:r,strings:a,layout:f,runtimeUrl:g,runtimeTimeoutMs:E}=e,C=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),F=e.createSession===void 0?void 0:JSON.stringify(e.createSession),m=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),y=e.automaticPayment?.mode,v=e.automaticPayment?.getSession!==void 0,c=h(void 0),x=h(null),u=h(null),i=h(e);return i.current=e,p(()=>{let d=!0;return _({runtimeUrl:g,timeoutMs:E}).then(R=>{let b=x.current;if(!d||!b)return;let A=i.current.paymentMethodLayout;c.current=A===void 0?void 0:JSON.stringify(A);let O=C===void 0?void 0:JSON.parse(C);u.current=R.mount(b,{...O,contractVersion:D(!!y,O),...y?{automaticPayment:V(y,v?()=>i.current.automaticPayment?.getSession:void 0)}:{},publishableKey:t,sessionId:n,nonce:o,createSession:F===void 0?void 0:JSON.parse(F),appearance:i.current.appearance,strings:i.current.strings,paymentMethodLayout:c.current===void 0?void 0:JSON.parse(c.current),...f?{layout:f}:{},onEvent:N=>i.current.onEvent?.(N)})},R=>{d&&i.current.onError?.(U(R))}),()=>{d=!1,u.current?.unmount(),u.current=null}},[t,n,o,F,f,y,v,g,E,C]),p(()=>{r!==void 0&&u.current?.update({appearance:r})},[r]),p(()=>{a!==void 0&&u.current?.update({strings:a})},[a]),p(()=>{if(m===void 0||m===c.current)return;let d=u.current;d&&(c.current=m,d.update({paymentMethodLayout:JSON.parse(m)}))},[m]),H("div",{ref:x,"data-flopay-runtime-checkout":""})}import{createContext as K}from"react";var M=K({});import{jsx as l}from"react/jsx-runtime";var Y=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],G={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function q(e){let t={};for(let o of Y)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 s(e){let t=J(M),n=j(e);return n.current=e,l(L,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,strings:e.strings,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:q(e),onError:o=>n.current.onError?.(o),onEvent:o=>{let r=n.current;r.onEvent?.(o);let a=r[G[o.name]];a&&P(()=>a(o.payload))}})}function z(e){return l(s,{...e})}var Q=k,W=S;function X({publishableKey:e,runtimeUrl:t,children:n}){return l(M.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var Z=["card","apple_pay","google_pay","apms"],$=["paypal","apple_pay","google_pay","apms"];function ee(e){return l(s,{...e,hiddenPaymentMethods:Z})}function te(e){return l(s,{...e,hiddenPaymentMethods:$})}function ne({mode:e,getSession:t,onSuccess:n,onComplete:o,...r}){return l(s,{...r,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:a=>{o&&P(()=>o(a)),n&&P(()=>n(a))}})}export{ee as DirectPayPalButton,ne as FloPayAutomaticPaymentButton,Q as FloPayCardSetup,s as FloPayCheckout,W as FloPayPaymentMethodSetup,X as FloPayProvider,k as FloPayRuntimeCardSetup,s as FloPayRuntimeCheckout,S as FloPayRuntimePaymentMethodSetup,z as SplitCardForm,te as VaultCardFields,Re as dropThirdPartyOnlyError};
1
+ import{a as S}from"./chunk-KPRDVWZP.mjs";import{a as P,c as k}from"./chunk-XRYDC367.mjs";import{dropThirdPartyOnlyError as Se}from"@flopay/shared";import{useContext as Y,useRef as G}from"react";import{loadCheckoutRuntime as T}from"@flopay/js";import{FloPayError as N}from"@flopay/shared";import{useEffect as p,useRef as h}from"react";import{jsx as j}from"react/jsx-runtime";var _="2.2.0",I="2.3.0",B="2.5.0",D="2.6.0",V=new Set(["publishableKey","sessionId","nonce","createSession","appearance","strings","onEvent","contractVersion","paymentMethodLayout","layout","automaticPayment","setup","hiddenPaymentMethods"]);function U(e,t){return t!==void 0&&Object.keys(t).some(n=>!V.has(n))?D:t!==void 0&&"hiddenPaymentMethods"in t?B:e?I:_}function H(e,t){let n={mode:e};return t&&Object.defineProperty(n,"getSession",{enumerable:!0,get:t}),n}function K(e){return e instanceof N?e:new N("The checkout runtime failed to load.","network_error",{code:"runtime_load_failed",cause:e})}function w(e){let{publishableKey:t,sessionId:n,nonce:o,appearance:r,strings:a,layout:f,runtimeUrl:M,runtimeTimeoutMs:g}=e,C=e.extraMountOptions===void 0?void 0:JSON.stringify(e.extraMountOptions),R=e.createSession===void 0?void 0:JSON.stringify(e.createSession),c=e.paymentMethodLayout===void 0?void 0:JSON.stringify(e.paymentMethodLayout),y=e.automaticPayment?.mode,v=e.automaticPayment?.getSession!==void 0,m=h(void 0),b=h(null),u=h(null),i=h(e);return i.current=e,p(()=>{let d=!0;return T({runtimeUrl:M,timeoutMs:g}).then(F=>{let x=b.current;if(!d||!x)return;let O=i.current.paymentMethodLayout;m.current=O===void 0?void 0:JSON.stringify(O);let A=C===void 0?void 0:JSON.parse(C);u.current=F.mount(x,{...A,contractVersion:U(!!y,A),...y?{automaticPayment:H(y,v?()=>i.current.automaticPayment?.getSession:void 0)}:{},publishableKey:t,sessionId:n,nonce:o,createSession:R===void 0?void 0:JSON.parse(R),appearance:i.current.appearance,strings:i.current.strings,paymentMethodLayout:m.current===void 0?void 0:JSON.parse(m.current),...f?{layout:f}:{},onEvent:L=>i.current.onEvent?.(L)})},F=>{d&&i.current.onError?.(K(F))}),()=>{d=!1,u.current?.unmount(),u.current=null}},[t,n,o,R,f,y,v,M,g,C]),p(()=>{r!==void 0&&u.current?.update({appearance:r})},[r]),p(()=>{a!==void 0&&u.current?.update({strings:a})},[a]),p(()=>{if(c===void 0||c===m.current)return;let d=u.current;d&&(m.current=c,d.update({paymentMethodLayout:JSON.parse(c)}))},[c]),j("div",{ref:b,"data-flopay-runtime-checkout":""})}import{createContext as J}from"react";var E=J({});import{jsx as l}from"react/jsx-runtime";var q=["theme","showCardBrandIcons","showCardFieldLabels","cardFieldLabels","cardFieldPlaceholders","enabledPaymentMethods","initialPayPalOrderId"],z={complete:"onComplete",decline:"onDecline",error:"onError",cancel:"onCancel",instruments:"onInstrument",cardFieldsReady:"onCardFieldsReady",cardFieldsFailed:"onCardFieldsFailed"};function Q(e){let t={};for(let o of q)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 s(e){let t=Y(E),n=G(e);return n.current=e,l(w,{sessionId:e.sessionId,nonce:e.nonce,createSession:e.createSession,appearance:e.appearance,strings:e.strings,paymentMethodLayout:e.paymentMethodLayout,layout:e.layout,automaticPayment:e.automaticPayment,runtimeTimeoutMs:e.runtimeTimeoutMs,publishableKey:e.publishableKey??t.publishableKey??"",runtimeUrl:e.runtimeUrl??t.runtimeUrl??"",extraMountOptions:Q(e),onError:o=>n.current.onError?.(o),onEvent:o=>{let r=n.current;r.onEvent?.(o);let a=r[z[o.name]];a&&P(()=>a(o.payload))}})}function W(e){return l(s,{...e})}var X=k,Z=S;function $({publishableKey:e,runtimeUrl:t,children:n}){return l(E.Provider,{value:{publishableKey:e,runtimeUrl:t},children:n})}var ee=["card","apple_pay","google_pay","apms"],te=["paypal","apple_pay","google_pay","apms"];function ne(e){return l(s,{...e,hiddenPaymentMethods:ee})}function oe(e){return l(s,{...e,hiddenPaymentMethods:te})}function ae({mode:e,getSession:t,onSuccess:n,onComplete:o,...r}){return l(s,{...r,automaticPayment:{mode:e??"automatic",...t?{getSession:t}:{}},onComplete:a=>{o&&P(()=>o(a)),n&&P(()=>n(a))}})}export{ne as DirectPayPalButton,ae as FloPayAutomaticPaymentButton,X as FloPayCardSetup,s as FloPayCheckout,Z as FloPayPaymentMethodSetup,$ as FloPayProvider,k as FloPayRuntimeCardSetup,s as FloPayRuntimeCheckout,S as FloPayRuntimePaymentMethodSetup,W as SplitCardForm,oe as VaultCardFields,Se as dropThirdPartyOnlyError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flopay/react",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
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.0.0",
40
- "@flopay/shared": "2.0.0"
39
+ "@flopay/js": "2.0.2",
40
+ "@flopay/shared": "2.0.2"
41
41
  },
42
42
  "peerDependencies": {
43
43
  "react": ">=18.0.0",