@flopay/react 1.18.0 → 1.19.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
@@ -93,6 +93,7 @@ Skip your own session-creation route and create the session inside the component
93
93
 
94
94
  - **Currency is required.** Pass `currency` on `createSession`, or on the first item, subscription, or product. Without one the SDK throws a `CurrencyRequired` validation error before sending anything.
95
95
  - **Detached creation (default).** The checkout creates a lightweight session *shell* first, then attaches the catalog in a background claim. The hosted card form mounts from the shell without waiting for the claim or Stripe.js; wallets, alternative payment methods, and PayPal load in parallel and appear when the claim lands. The card form's submit button stays gated until the claim settles, because the billing API refuses to charge an unclaimed session; a buyer who clicks during that window is asked to press pay again. Catalog and coupon errors surface as a checkout load error. `createSession.timeoutMs` applies separately to the shell and the claim (12 seconds each by default). Detached creation requires billing API v1.7.12 or newer and `checkoutMode: 'full'`, and is skipped when `tokenizedData` is supplied; pass `deferDataAttachment: false` to force a single request.
96
+ - **Supplied buyer names.** When `createSession.account` has a non-blank `firstName` or `lastName`, the first session request (the shell) already carries the trimmed first and last name, so the billing API issues the hosted card form with its cardholder name field hidden from the start: the field is never rendered. A first name alone or a last name alone is sent on its own. Email, `userId`, the address, and the cart still arrive with the claim, and names are not part of the inline-session cache identity, so editing a name does not start a new session. Blank or whitespace-only names count as absent and leave the request and the form unchanged. The buyer types no name in this case, so no name input is reported. A billing API that does not yet keep names on the shell ignores them and shows the field as before.
96
97
  - **Late buyer identity.** Any still-anonymous session the checkout renders (including an existing session passed as `sessionId` and `nonce` with `buyerIdentified: false`) attaches the buyer email the checkout collects, or a wallet or PayPal approval supplies, through the session claim before payment.
97
98
  - **Checkout metadata.** `checkoutMetadata` is sent unchanged on the initial request and never repeated in a claim. Omitting it keeps the request shape; an explicit `null` and `{}` stay distinct. Returned metadata is on the normalized session and its `data.session`. The billing API alone enforces size limits.
98
99
  - **Idempotency.** The create request sends a stable `Idempotency-Key` whenever a secure random source is available. `FloPayCheckout` resolves the key once per logical checkout, stores it with the inline-session cache in `sessionStorage`, and reuses it across retries, effect reruns, and remounts, so StrictMode double-mounts or navigation flicker cannot create two sessions or two charges. A logical checkout is identified by merchant, buyer, cart and pricing, coupons, and checkout metadata (keys canonicalized, raw metadata not stored); checkout-mode, token, and analytics prop changes do not rotate it. Pass `createSession.idempotencyKey` to control the key yourself; it must be non-empty, at most 255 characters, and never reused for a new purchase.
@@ -142,6 +143,39 @@ Set `showCardBrandIcons` on `FloPayCheckout` or `SplitCardForm` to show the Visa
142
143
  - **Compatibility.** A billing API whose card form predates the icons ignores the setting and keeps the field as it was.
143
144
  - **Custom layouts.** `FloPayCheckout` forwards the prop to its built-in form. A `SplitCardForm` you render as a custom-layout child takes its own `showCardBrandIcons`.
144
145
 
146
+ #### Card field labels
147
+
148
+ Set `showCardFieldLabels` on `FloPayCheckout` or `SplitCardForm` to show visible labels above the hosted card fields, and `cardFieldLabels` to change their text:
149
+
150
+ ```tsx
151
+ <FloPayCheckout
152
+ sessionId={sessionId}
153
+ nonce={sessionNonce}
154
+ showCardFieldLabels
155
+ cardFieldLabels={{ number: 'Card number', expiry: 'Valid until', cvv: 'Security code' }}
156
+ appearance={{ rules: { '.Label': { color: '#475569', fontWeight: '500', marginBottom: '6px' } } }}
157
+ />
158
+ ```
159
+
160
+ - **Opt-in.** When both props are omitted, nothing is sent and the card form looks as it does today. `false` hides the labels again.
161
+ - **Text.** `cardFieldLabels` takes optional `number`, `expiry`, `cvv` and `name` text (`CardFieldLabels`). Only the fields you set are sent, exactly as given: the hosted form shows the text literally. A field you leave out keeps the hosted form's default wording, and removing the prop restores all of them.
162
+ - **Live updates.** Changing either prop updates the hosted form in place, without remounting it or clearing entered card details. The SDK re-sends the settings whenever the hosted form becomes ready again.
163
+ - **Custom layouts.** `FloPayCheckout` forwards both props to its built-in form. A `SplitCardForm` you render as a custom-layout child takes its own.
164
+ - **Authenticated.** Like a custom submit label, the label settings are bound to the session and the card form's `messageToken`, and the SDK sends them only to the hosted form's exact `expectedOrigin`, never to `'*'`. A card form without them (an older billing API) receives no label settings and keeps its default look.
165
+
166
+ The labels are styled by the same `appearance.rules['.Label']` rule that styles Stripe's labels, so one setting styles both. The supported `.Label` properties are:
167
+
168
+ | `.Label` property | Hosted label |
169
+ |---|---|
170
+ | `color` | Text colour |
171
+ | `fontSize` | Font size, in `px` (`'13px'`) |
172
+ | `fontWeight` | Font weight (`'500'`, or `normal` / `bold`) |
173
+ | `letterSpacing` | Letter spacing, in `em` (`'0.05em'`) |
174
+ | `textTransform` | `none`, `uppercase`, `lowercase` or `capitalize` |
175
+ | `marginBottom` | The gap between the label and its field, in `px` (`'6px'`) |
176
+
177
+ Every other `.Label` property (for example `padding`, `border`, `marginTop`, `fontFamily` or `lineHeight`) is ignored, as are empty values and values of the wrong type; none of them raises an error. Without a supported `.Label` property, the theme sent to the hosted form is unchanged. The preset themes already style `.Label`, so their label style applies as soon as the labels are shown. The hosted form enforces its own bounds on the values.
178
+
145
179
  #### Card field placeholders
146
180
 
147
181
  Set `cardFieldPlaceholders` on `FloPayCheckout` or `SplitCardForm` to choose the placeholder text of the hosted card fields. Every field is optional: `number` (card number), `expiry` (expiry date), `cvv` (security code) and `name` (name on card):
@@ -745,6 +779,8 @@ export function ComposedCheckout({ session, nonce }: { session: CheckoutSession;
745
779
  | `avsLayout` | `'row' \| 'column'` | AVS field layout |
746
780
  | `cardFieldOrder` | `VaultCardFieldKey[]?` | Order of the hosted card rows |
747
781
  | `showCardBrandIcons` | `boolean?` | Set `true` to show the Visa, Mastercard, Amex and Discover icons in the hosted card number field; omitted or `false` keeps the field as it is |
782
+ | `showCardFieldLabels` | `boolean?` | Set `true` to show visible labels above the hosted card fields, styled by `appearance.rules['.Label']`; omitted sends nothing |
783
+ | `cardFieldLabels` | `CardFieldLabels?` | Label text (`number`, `expiry`, `cvv`, `name`); only the fields you set are sent, verbatim |
748
784
  | `cardFieldPlaceholders` | `CardFieldPlaceholders?` | Placeholder text for the hosted card fields: `number`, `expiry`, `cvv` and `name`, each optional; `''` shows no placeholder; updates live; omitted keeps the hosted wording |
749
785
  | `cardAutoFocus` | `boolean?` | Set `false` to stop the checkout focusing the card form (or the identity/AVS field above it) when it opens; omitted or `true` keeps the default |
750
786
  | `cardFieldsTimeoutMs` | `number?` | Milliseconds the card fields may take to become interactive before `onCardFieldsFailed` reports `timeout` (default 15 000) |
@@ -860,6 +896,8 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
860
896
  | `enableAVS` | `boolean \| AVSFieldConfig` | Collect and validate the billing address |
861
897
  | `cardFieldOrder` | `VaultCardFieldKey[]?` | Order of the hosted card rows |
862
898
  | `showCardBrandIcons` | `boolean?` | Set `true` to show the Visa, Mastercard, Amex and Discover icons in the hosted card number field; omitted or `false` keeps the field as it is |
899
+ | `showCardFieldLabels` | `boolean?` | Set `true` to show visible labels above the hosted card fields, styled by `appearance.rules['.Label']`; omitted sends nothing |
900
+ | `cardFieldLabels` | `CardFieldLabels?` | Label text (`number`, `expiry`, `cvv`, `name`); only the fields you set are sent, verbatim |
863
901
  | `cardFieldPlaceholders` | `CardFieldPlaceholders?` | Placeholder text for the hosted card fields: `number`, `expiry`, `cvv` and `name`, each optional; `''` shows no placeholder; updates live; omitted keeps the hosted wording |
864
902
  | `cardAutoFocus` | `boolean?` | Set `false` to stop the form focusing the hosted card (or the identity/AVS field above it) when it opens; omitted or `true` keeps the default |
865
903
  | `cardFieldsTimeoutMs` | `number?` | Milliseconds the card fields may take to become interactive before `onCardFieldsFailed` reports `timeout` (default 15 000) |
@@ -1,4 +1,4 @@
1
- import type { BeforeButtonClickEvent, CardFieldsFailedEvent, CardFieldsReadyEvent, CheckoutButtonMethod, CheckoutMode, DeclineEvent, FloInstrumentEvent, FloPayAppearance, FloPayPaymentCancelEvent, InlineSessionDraft, InlineSessionPatch, PaymentMethodLayoutRules, PaymentResult, WalletPresentation } from '@flopay/shared';
1
+ import type { BeforeButtonClickEvent, CardFieldLabels, CardFieldsFailedEvent, CardFieldsReadyEvent, 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. */
@@ -188,6 +188,16 @@ export interface FloPayCheckoutProps {
188
188
  * Vault card path only; an older hosted form ignores it.
189
189
  */
190
190
  showCardBrandIcons?: boolean;
191
+ /**
192
+ * Show the visible labels above the hosted card fields. Omitted sends nothing,
193
+ * so the form looks as it does today. Vault card path only.
194
+ */
195
+ showCardFieldLabels?: boolean;
196
+ /**
197
+ * Replace the text of the labels (`number`, `expiry`, `cvv`, `name`). Only the
198
+ * fields you set are sent. Vault card path only.
199
+ */
200
+ cardFieldLabels?: CardFieldLabels;
191
201
  /**
192
202
  * Placeholder text for the hosted card fields (`number`, `expiry`, `cvv`,
193
203
  * `name`), each optional. Only the fields given are sent; the rest keep the
@@ -279,4 +289,4 @@ export interface FloPayCheckoutProps {
279
289
  * />
280
290
  * ```
281
291
  */
282
- 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, showCardBrandIcons, cardFieldPlaceholders, cardAutoFocus, onCardFieldsReady, onCardFieldsFailed, cardFieldsTimeoutMs, cardPreFormSlot, avsLayout, submitLabel, className, initialErrorMessage, initialPayPalOrderId, children, checkoutMode: checkoutModeProp, confirmLabel, renderConfirmButton, onSessionCompleted, }: FloPayCheckoutProps): React.ReactElement;
292
+ 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, showCardBrandIcons, showCardFieldLabels, cardFieldLabels, cardFieldPlaceholders, cardAutoFocus, onCardFieldsReady, onCardFieldsFailed, cardFieldsTimeoutMs, cardPreFormSlot, avsLayout, submitLabel, className, initialErrorMessage, initialPayPalOrderId, children, checkoutMode: checkoutModeProp, confirmLabel, renderConfirmButton, onSessionCompleted, }: FloPayCheckoutProps): React.ReactElement;