@flopay/react 1.14.15 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -218,11 +218,50 @@ One value styles non-card Stripe Elements, the SDK-rendered wrapper and AVS fiel
218
218
 
219
219
  `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).
220
220
 
221
+ `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.
222
+
223
+ - `order` is the default order. Groups you leave out follow the ones you list, in the default order, so `order: ['card']` puts card first and keeps the rest as they were.
224
+ - `moreOptions` puts groups behind a closed **More payment options** link, so they stay available without competing for the buyer's first tap. See **More payment options** below.
225
+ - `countryRules` gives buyers in some countries their own `order` and `moreOptions`. Each rule lists ISO 3166-1 alpha-2 `countries`; the first rule naming the buyer's country applies, and a field a rule leaves out uses the default one.
226
+ - The FloPay billing API applies the rules to each buyer and the checkout shows the order it resolves. The buyer's country is the checkout session's country when it has one (with inline `createSession`, `account.country`; the checkout asks once the session's details are attached, so that country is used), otherwise the buyer's IP country. The IP country is used only to pick the rule and never reaches your page. Unknown or repeated values are ignored, and the API's warnings about them are logged to the console.
227
+ - Until the order is known the payment methods show placeholders, so nothing moves once it is on screen. If the API is slow or unavailable, the default `order` applies without country rules.
228
+ - In `layout="buttons"` every group follows the order, and Card is the **Credit / Debit Card** button. In the default layout PayPal, wallets and APMs follow the order among the buttons; Card first puts the card form above them, with an "or pay another way" divider, and anywhere else the card form stays below "or pay with card".
229
+ - A group that is hidden (`showPayPal={false}`) or unavailable (no wallet on the device, no APM for the currency) is skipped and leaves no gap. Hiding a group is still the job of the show/hide props.
230
+ - The rules can change after mount. The checkout asks the API again and keeps the current order until the new one is known. A group whose place changes is mounted again rather than moved, so its provider frame never breaks; set the rules before the buyer starts paying, because a moved card form reloads its fields.
231
+ - `FloPayCheckout` passes the rules to its built-in form and injects them into custom-layout children that do not set their own.
232
+
233
+ ```tsx
234
+ <FloPayCheckout
235
+ sessionId={sessionId}
236
+ nonce={nonce}
237
+ layout="buttons"
238
+ paymentMethodLayout={{
239
+ order: ['card', 'wallets', 'apms', 'paypal'],
240
+ moreOptions: ['paypal'],
241
+ countryRules: [
242
+ { countries: ['US', 'GB', 'CA', 'AU', 'NZ', 'IE'], order: ['paypal'], moreOptions: [] },
243
+ ],
244
+ }}
245
+ />
246
+ ```
247
+
248
+ Here buyers outside the six countries see card, Apple Pay / Google Pay and APMs, with PayPal behind the link; buyers inside them see PayPal first, with no link.
249
+
250
+ ##### More payment options
251
+
252
+ - **Placement.** In `layout="buttons"` the link sits under the buttons, and any group can go behind it, Card included. In the default layout it sits under the buttons and above "or pay with card"; the card form always stays in view there, so `'card'` in `moreOptions` applies to the buttons layout only.
253
+ - **Opening.** The link is closed at first. Opening it reveals the groups behind it in place, in the resolved order, and they stay revealed. The groups load while the link is closed, so PayPal and the wallets are ready the moment it opens, and everything behind it works as it does in view, PayPal's popup or redirect included.
254
+ - **Edge cases.** When nothing available would stay in view, every group shows and there is no link. When nothing behind the link is available (hidden by the show/hide props, or no wallet on the device), there is no link.
255
+ - **Text and look.** The link reads "More payment options". Set `moreOptionsLabel` to final, already-localized plain text to change it. It takes the theme's accent colour (`appearance.variables.colorPrimary`) and font.
256
+ - **Accessibility.** The link is a button: it is reached by Tab, opened with Enter or Space, and announces itself as collapsed. Opening it moves focus to the revealed group, which is labelled with the link's text.
257
+ - **Analytics.** Opening it emits `more_options_opened` on `onInstrument`, once per checkout, so you can measure how often buyers open it.
258
+ - `FloPayCheckout` injects `moreOptionsLabel`, like `paymentMethodLayout`, into custom-layout children that do not set their own.
259
+
221
260
  #### Merchant instrument feed
222
261
 
223
262
  `onInstrument` on `FloPayCheckout` or `FloPayProvider` forwards a stable, privacy-safe checkout funnel to your own analytics as `FloInstrumentEvent` values. `schemaVersion` is always `1`, and `gateway` (`stripe` or `paypal`) is included only when an event is attributable to that provider.
224
263
 
225
- - Lifecycle names are `checkout_mount`, `sdk_loaded`, `form_rendered`, `card_expanded`, `tokenize`, `process_attempt`, and `3ds_challenge`. `checkout_mount`, `sdk_loaded`, `form_rendered`, and `card_expanded` arrive at most once per logical checkout; `tokenize`, `process_attempt`, and `3ds_challenge` may repeat for each attempt.
264
+ - Lifecycle names are `checkout_mount`, `sdk_loaded`, `form_rendered`, `card_expanded`, `more_options_opened`, `tokenize`, `process_attempt`, and `3ds_challenge`. `checkout_mount`, `sdk_loaded`, `form_rendered`, `card_expanded`, and `more_options_opened` arrive at most once per logical checkout; `tokenize`, `process_attempt`, and `3ds_challenge` may repeat for each attempt.
226
265
  - `checkout_error` adds one of four phases: `session_create`, `sdk_load`, `process`, or `wallets`.
227
266
 
228
267
  The callback is an allowlisted projection with no card data, tokens, provider object IDs, secrets, or raw PII. A throwing `onInstrument` consumer never breaks checkout, and `telemetry={false}` does not disable this merchant-owned feed.
@@ -605,6 +644,8 @@ export function ComposedCheckout({ session, nonce }: { session: CheckoutSession;
605
644
  | `checkoutMode` | `CheckoutMode?` | Overrides the session's checkout mode |
606
645
  | `billingApiUrl` | `string?` | Billing API base URL; defaults to the configured environment |
607
646
  | `layout` | `'default' \| 'buttons'` | Payment form layout |
647
+ | `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 |
648
+ | `moreOptionsLabel` | `string?` | Text of the "More payment options" link, as final, already-localized plain text |
608
649
  | `theme` | `ThemeId?` | Theme bundle for the whole checkout |
609
650
  | `appearance` | `FloPayAppearance?` | Stripe-side appearance overrides |
610
651
  | `buttonsStyles` | `ButtonsLayoutStyles?` | Wrapper style overrides layered on the theme |
@@ -719,6 +760,8 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
719
760
  | `totalAmount` | `number?` | Amount in the smallest currency unit, for wallet and PayPal configuration |
720
761
  | `currency` | `string?` | Currency code for wallet and PayPal configuration |
721
762
  | `layout` | `'default' \| 'buttons'` | Payment form layout |
763
+ | `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 |
764
+ | `moreOptionsLabel` | `string?` | Text of the "More payment options" link, as final, already-localized plain text |
722
765
  | `theme` | `ThemeId?` | Theme bundle |
723
766
  | `submitLabel` | `(string \| null)?` | Live wording for the hosted card submit button; omitted, `null`, or blank shows the hosted default `CONFIRM PAYMENT` |
724
767
  | `showStripe` / `showPayPal` | `boolean?` | Toggle Stripe methods and PayPal |
@@ -777,6 +820,9 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
777
820
  | `InlineSessionDraft` | Draft accepted by `FloPayCheckoutProps.createSession` |
778
821
  | `InlineSessionPatch` | Partial draft returned from `FloPayCheckoutProps.onBeforeButtonClick` |
779
822
  | `WalletPresentation` | Closed wallet presentation preference: `auto`, `popup`, or `prefer_redirect` |
823
+ | `PaymentMethodGroup` | A group `paymentMethodLayout` can place: `'card'`, `'paypal'`, `'wallets'` or `'apms'` |
824
+ | `PaymentMethodLayoutRules` | `{ order?: PaymentMethodGroup[]; moreOptions?: PaymentMethodGroup[]; countryRules?: PaymentMethodCountryRule[] }`, the merchant's layout rules |
825
+ | `PaymentMethodCountryRule` | `{ countries: string[]; order?: PaymentMethodGroup[]; moreOptions?: PaymentMethodGroup[] }`, a rule for buyers in the listed ISO 3166-1 alpha-2 countries |
780
826
  | `FloInstrumentEvent` | Versioned merchant instrument union |
781
827
 
782
828
  ## Errors
@@ -1,4 +1,4 @@
1
- import type { BeforeButtonClickEvent, CheckoutButtonMethod, CheckoutMode, DeclineEvent, FloInstrumentEvent, FloPayAppearance, FloPayPaymentCancelEvent, InlineSessionDraft, InlineSessionPatch, PaymentResult, WalletPresentation } from '@flopay/shared';
1
+ import type { BeforeButtonClickEvent, CheckoutButtonMethod, CheckoutMode, DeclineEvent, FloInstrumentEvent, FloPayAppearance, FloPayPaymentCancelEvent, InlineSessionDraft, InlineSessionPatch, PaymentMethodLayoutRules, PaymentResult, WalletPresentation } from '@flopay/shared';
2
2
  import { FloPayError } from '@flopay/shared';
3
3
  import React from 'react';
4
4
  /** Props for the all-in-one `FloPayCheckout` wrapper. */
@@ -104,6 +104,23 @@ export interface FloPayCheckoutProps {
104
104
  debug?: boolean;
105
105
  /** Layout mode: 'default' (all visible) or 'buttons' (PayPal/wallets + expandable card form). */
106
106
  layout?: 'default' | 'buttons';
107
+ /**
108
+ * The merchant's rules for the order of `'card'`, `'paypal'`, `'wallets'`
109
+ * and `'apms'`, with optional per-country rules. The billing API applies
110
+ * them to each buyer and the checkout shows the order it resolves. Without
111
+ * the prop the order is PayPal, wallets, APMs, then card. Can change after
112
+ * mount; a group whose place changes is mounted again. `moreOptions` puts
113
+ * groups behind a closed "More payment options" link. Injected into
114
+ * custom-layout children that set none. See
115
+ * `SplitCardFormProps.paymentMethodLayout`.
116
+ */
117
+ paymentMethodLayout?: PaymentMethodLayoutRules;
118
+ /**
119
+ * The text of the "More payment options" link, as final, already-localized
120
+ * plain text. Injected into custom-layout children that set none. See
121
+ * `SplitCardFormProps.moreOptionsLabel`.
122
+ */
123
+ moreOptionsLabel?: string;
107
124
  /**
108
125
  * High-level theme bundle that styles non-card Stripe Elements, the FloPay
109
126
  * wrapper / AVS inputs, and the hosted vault widget. One of: `'classic'`
@@ -242,4 +259,4 @@ export interface FloPayCheckoutProps {
242
259
  * />
243
260
  * ```
244
261
  */
245
- export declare function FloPayCheckout({ sessionId: sessionIdProp, nonce: nonceProp, createSession: createSessionParams, billingApiUrl, telemetry, appearance: appearanceOverride, locale, loading: loadingNode, error: errorNode, onComplete, onError, onInstrument, onDecline, onCancel, onCountryChange, onZipChange, showPayPal, showStripe, walletPresentation, enabledPaymentMethods: enabledPaymentMethodsProp, showApplePay, showGooglePay, debug, layout, theme, buttonsTheme, buttonsStyles, cardButtonContent, cardBackButtonContent, cardTitleContent, showSecurityFooter: _showSecurityFooter, onButtonClick, onBeforeButtonClick, enableAVS, cardFieldOrder, cardAutoFocus, cardPreFormSlot, avsLayout, submitLabel, className, initialErrorMessage, initialPayPalOrderId, children, checkoutMode: checkoutModeProp, confirmLabel, renderConfirmButton, onSessionCompleted, }: FloPayCheckoutProps): React.ReactElement;
262
+ export declare function FloPayCheckout({ sessionId: sessionIdProp, nonce: nonceProp, createSession: createSessionParams, billingApiUrl, telemetry, appearance: appearanceOverride, locale, loading: loadingNode, error: errorNode, onComplete, onError, onInstrument, onDecline, onCancel, onCountryChange, onZipChange, showPayPal, showStripe, walletPresentation, enabledPaymentMethods: enabledPaymentMethodsProp, showApplePay, showGooglePay, debug, layout, paymentMethodLayout, moreOptionsLabel, theme, buttonsTheme, buttonsStyles, cardButtonContent, cardBackButtonContent, cardTitleContent, showSecurityFooter: _showSecurityFooter, onButtonClick, onBeforeButtonClick, enableAVS, cardFieldOrder, cardAutoFocus, cardPreFormSlot, avsLayout, submitLabel, className, initialErrorMessage, initialPayPalOrderId, children, checkoutMode: checkoutModeProp, confirmLabel, renderConfirmButton, onSessionCompleted, }: FloPayCheckoutProps): React.ReactElement;