@flopay/react 1.16.3 → 1.16.5
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 +60 -1
- package/dist/automatic-payment-button.d.ts +9 -2
- package/dist/flopay-checkout.d.ts +8 -2
- package/dist/index.cjs +9 -9
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +7 -7
- package/dist/one-click-warnings.d.ts +12 -0
- package/dist/split-card-form.d.ts +12 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -283,6 +283,31 @@ Sentry.init({ beforeSend: dropThirdPartyOnlyError });
|
|
|
283
283
|
|
|
284
284
|
It drops only complete exception stacks with no app or `@flopay/*` frame and at least one recognized browser-extension or Stripe controller frame; every other error passes through unchanged.
|
|
285
285
|
|
|
286
|
+
#### Card-field lifecycle
|
|
287
|
+
|
|
288
|
+
`onCardFieldsReady` is called once per hosted card form, when the card fields are on screen and the buyer can type in them (not when the form's markup is inserted), with `{ type: 'card_fields_ready', elapsedMs }`: the milliseconds since that card form mounted. `onCardFieldsFailed` is called when the card fields fail to load, or are not ready within `cardFieldsTimeoutMs` (default 15 000 ms, the same on every device; a value that is not a positive number keeps the default), with `{ type: 'card_fields_failed', reason, elapsedMs }`. `reason` is always one of:
|
|
289
|
+
|
|
290
|
+
| Reason | When |
|
|
291
|
+
|--------|------|
|
|
292
|
+
| `load_error` | The card form failed to load, for example its network request failed |
|
|
293
|
+
| `timeout` | The card fields were not interactive within `cardFieldsTimeoutMs` |
|
|
294
|
+
| `blocked` | A content-security policy blocked the card form's own script or frame |
|
|
295
|
+
| `other` | Any other failure, such as the card form not mounting at all |
|
|
296
|
+
|
|
297
|
+
A card-field failure is not a declined or failed payment: it never calls `onDecline`, and on `onInstrument` it is `card_fields_failed`, never `checkout_error`. If the fields become ready after a `timeout`, `onCardFieldsReady` still follows, with no second failure. Both events also reach `onInstrument` as `{ schemaVersion: 1, name: 'card_fields_ready', elapsedMs }` and `{ schemaVersion: 1, name: 'card_fields_failed', reason, elapsedMs }`, and Flo's SDK telemetry with the checkout session id. They never carry card data, a throwing callback does not affect the checkout, and nothing changes if you use neither.
|
|
298
|
+
|
|
299
|
+
`onError` is unchanged: it is still called, as before, when the hosted form itself reports that it failed to load. A timeout, a blocked form or any other failure the SDK detects reaches only `onCardFieldsFailed`. With an older hosted form that does not report when its fields become interactive, `onCardFieldsReady` is called when that form reports its own ready instead.
|
|
300
|
+
|
|
301
|
+
```tsx
|
|
302
|
+
<FloPayCheckout
|
|
303
|
+
sessionId={sessionId}
|
|
304
|
+
nonce={nonce}
|
|
305
|
+
cardFieldsTimeoutMs={20_000}
|
|
306
|
+
onCardFieldsReady={({ elapsedMs }) => track('card_fields_ready', { elapsedMs })}
|
|
307
|
+
onCardFieldsFailed={({ reason, elapsedMs }) => track('card_fields_failed', { reason, elapsedMs })}
|
|
308
|
+
/>
|
|
309
|
+
```
|
|
310
|
+
|
|
286
311
|
### FloPayCardSetup
|
|
287
312
|
|
|
288
313
|
`FloPayCardSetup` lets a customer add or verify a card without a purchase or charge. Your trusted server first calls the merchant-authenticated card-setup endpoint and passes only its opaque `sessionId` and bound `nonce` to the browser; never send API credentials or a customer identifier to this component. See the [payment methods reference](https://flopay.com/docs/technical-reference/rest/payment-methods) for listing, setup, and deletion.
|
|
@@ -352,6 +377,28 @@ export function AddBrandedCard(props: { sessionId: string; nonce: string; theme:
|
|
|
352
377
|
|
|
353
378
|
When the saved payment method cannot complete silently, the button opens a `FloPayCheckout` with the same `theme`. The `paymentMethodId` and `checkoutMethod` props are deprecated and ignored: the billing API selects the payment method and gateway.
|
|
354
379
|
|
|
380
|
+
Give exactly one of `sessionId`, `getSession` or an inline draft (`createSession` or the session-creation props); a click with more than one reports a `validation_error` through `onError` and makes no request. Inline creation is deprecated: the billing API may create a Full checkout for a keyless Auto session, and outside production the button logs a one-time warning pointing at `getSession`.
|
|
381
|
+
|
|
382
|
+
The recommended one-click path is a server-minted session. Your server mints it with `@flopay/node`'s `checkout.sessions.createOneClick()`, taking the buyer from its own login session, and the button fetches it with `getSession` when the buyer clicks:
|
|
383
|
+
|
|
384
|
+
```tsx
|
|
385
|
+
import { FloPayAutomaticPaymentButton } from '@flopay/react';
|
|
386
|
+
|
|
387
|
+
<FloPayAutomaticPaymentButton
|
|
388
|
+
getSession={async ({ signal }) => {
|
|
389
|
+
const response = await fetch('/api/flopay/one-click-session', { method: 'POST', signal });
|
|
390
|
+
if (!response.ok) throw new Error('Could not start the payment');
|
|
391
|
+
return response.json(); // { sessionId, nonce } from createOneClick
|
|
392
|
+
}}
|
|
393
|
+
onSuccess={() => showThankYou()}
|
|
394
|
+
onError={(error) => reportError(error)}
|
|
395
|
+
>
|
|
396
|
+
Add to my order
|
|
397
|
+
</FloPayAutomaticPaymentButton>;
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Nothing is fetched at render. `getSession` is called once per click (a double click starts one fetch) with an `AbortSignal` that aborts on unmount or after 15 seconds; the button then charges the returned `sessionId` with the returned `nonce`. A rejection, an invalid answer or the timeout reports `session_fetch_failed` through `onError`, with no fallback checkout and no `onDecline`. When the billing API refuses the merchant authentication (`merchant_auth_required`), `onError` receives an `authentication_error`, `onDecline` is not called, no 3DS challenge starts, and the Full fallback checkout opens so the buyer can still pay.
|
|
401
|
+
|
|
355
402
|
### Composing your own checkout
|
|
356
403
|
|
|
357
404
|
`FloPayProvider`, `SplitCardForm`, and the hooks let you compose the provider and session yourself. Card checkout still uses the hosted card form: supply the session (with its `vault` block) and nonce, or a session whose `gateways.stripe.enabledPaymentMethods` includes `card` so the form can be fetched on demand. A session with neither never calls the recovery endpoint; its other methods remain usable, and if none remain `onError` receives `UnsupportedBackendVaultCapability`. `FloPayCheckout` and `SplitCardForm` never fall back to Stripe card fields.
|
|
@@ -661,6 +708,9 @@ export function ComposedCheckout({ session, nonce }: { session: CheckoutSession;
|
|
|
661
708
|
| `avsLayout` | `'row' \| 'column'` | AVS field layout |
|
|
662
709
|
| `cardFieldOrder` | `VaultCardFieldKey[]?` | Order of the hosted card rows |
|
|
663
710
|
| `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 |
|
|
711
|
+
| `cardFieldsTimeoutMs` | `number?` | Milliseconds the card fields may take to become interactive before `onCardFieldsFailed` reports `timeout` (default 15 000) |
|
|
712
|
+
| `onCardFieldsReady` | `(event: CardFieldsReadyEvent) => void` | The hosted card fields are interactive; once per card form, with `elapsedMs` since it mounted |
|
|
713
|
+
| `onCardFieldsFailed` | `(event: CardFieldsFailedEvent) => void` | The card fields failed to load or were not ready in time; not a decline or payment error |
|
|
664
714
|
| `cardPreFormSlot` | `ReactNode?` | Content rendered above the hosted card form |
|
|
665
715
|
| `cardButtonContent` | `ReactNode?` | Card tile content in `layout="buttons"` |
|
|
666
716
|
| `cardBackButtonContent` | `ReactNode?` | Back-button label in `layout="buttons"` |
|
|
@@ -732,7 +782,8 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
|
|
|
732
782
|
| Prop | Type | Description |
|
|
733
783
|
|------|------|-------------|
|
|
734
784
|
| `sessionId` / `nonce` | `string?` | Reuse an existing auto-mode session |
|
|
735
|
-
| `
|
|
785
|
+
| `getSession` | `({ signal }: { signal: AbortSignal }) => Promise<OneClickSession>` | Fetches a server-minted `{ sessionId, nonce }` (from `@flopay/node` `createOneClick`) on click. 15s timeout, aborted on unmount |
|
|
786
|
+
| `createSession` | `InlineSessionDraft?` | Inline draft for the session to create (deprecated: use `getSession`) |
|
|
736
787
|
| `clientId` | `string?` | Merchant client id for inline creation |
|
|
737
788
|
| `items` / `subscriptions` / `products` | arrays | Cart for inline creation |
|
|
738
789
|
| `account` | `object?` | Buyer account; `userId` required, `email` optional |
|
|
@@ -770,6 +821,8 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
|
|
|
770
821
|
| `enableAVS` | `boolean \| AVSFieldConfig` | Collect and validate the billing address |
|
|
771
822
|
| `cardFieldOrder` | `VaultCardFieldKey[]?` | Order of the hosted card rows |
|
|
772
823
|
| `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 |
|
|
824
|
+
| `cardFieldsTimeoutMs` | `number?` | Milliseconds the card fields may take to become interactive before `onCardFieldsFailed` reports `timeout` (default 15 000) |
|
|
825
|
+
| `onCardFieldsReady` / `onCardFieldsFailed` | callbacks | Card-field lifecycle; see **Card-field lifecycle** above |
|
|
773
826
|
| `onBuyerIdentityReady` | `(identity) => MaybePromise<void>` | Attach a buyer identity collected by the form; `FloPayCheckout` wires its late-buyer claim here |
|
|
774
827
|
| `onTokenizedBody` | `(body: TokenizedBody) => void` | Take over non-card backend submission yourself |
|
|
775
828
|
| `onComplete` / `onDecline` / `onError` | callbacks | Checkout outcomes |
|
|
@@ -824,6 +877,10 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
|
|
|
824
877
|
| `PaymentMethodLayoutRules` | `{ order?: PaymentMethodGroup[]; moreOptions?: PaymentMethodGroup[]; countryRules?: PaymentMethodCountryRule[] }`, the merchant's layout rules |
|
|
825
878
|
| `PaymentMethodCountryRule` | `{ countries: string[]; order?: PaymentMethodGroup[]; moreOptions?: PaymentMethodGroup[] }`, a rule for buyers in the listed ISO 3166-1 alpha-2 countries |
|
|
826
879
|
| `FloInstrumentEvent` | Versioned merchant instrument union |
|
|
880
|
+
| `CardFieldsReadyEvent` | `{ type: 'card_fields_ready', elapsedMs }`, the payload of the onCardFieldsReady callback |
|
|
881
|
+
| `CardFieldsFailedEvent` | `{ type: 'card_fields_failed', reason, elapsedMs }`, the payload of the onCardFieldsFailed callback |
|
|
882
|
+
| `CardFieldsFailureReason` | `'load_error'`, `'timeout'`, `'blocked'` or `'other'` |
|
|
883
|
+
| `CardFieldsEvent` | `CardFieldsReadyEvent \| CardFieldsFailedEvent` |
|
|
827
884
|
|
|
828
885
|
## Errors
|
|
829
886
|
|
|
@@ -847,6 +904,8 @@ Checkout errors reach `onError` (and the `error` render prop) as `FloPayError` v
|
|
|
847
904
|
| `checkout_processing_timeout` | `api_error` | The payment's outcome is not known yet: the SDK could not confirm it in time and it may still complete. Do not resubmit; reconcile from `payment.*` webhooks. `FloPayAutomaticPaymentButton` reports it through `onError`, not `onDecline`, shows a "don't pay again" notice under the button, and opens no fallback checkout. |
|
|
848
905
|
| `stored_payment_method_unsupported` | `api_error` | The backend-selected saved method cannot be used for this transaction. Show the supplied buyer-safe instruction and let the buyer choose another method. |
|
|
849
906
|
| `InvalidPaymentProcessResponse` | `api_error` | Saved-payment processing returned a response the SDK could not use. |
|
|
907
|
+
| `session_fetch_failed` | `api_error` | `FloPayAutomaticPaymentButton`'s `getSession` rejected, resolved without a `sessionId` and `nonce`, or did not resolve within 15 seconds. No session exists, so no fallback checkout opens and `onDecline` is not called. `cause` holds the rejection. |
|
|
908
|
+
| `merchant_auth_required` | `authentication_error` | The billing API did not accept the merchant authentication for a one-click session and created a Full checkout instead. Reported through `onError` once, never `onDecline`; no 3DS challenge starts, and the button opens the Full fallback checkout (`FloPayCheckout` switches to Full). Mint the session with `@flopay/node` `createOneClick` and `getSession`. |
|
|
850
909
|
|
|
851
910
|
Every `external_payment_method_failed` keeps that code and the existing buyer
|
|
852
911
|
message. Its optional `details` object contains only bounded support fields:
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ButtonsLayoutStyles, ButtonsLayoutTheme, CheckoutButtonMethod, CheckoutItem, CheckoutProduct, CheckoutSession, CheckoutSubscription, DeclineEvent, FloPayAppearance, InlineSessionDraft, PaymentResult, ThemeId } from '@flopay/shared';
|
|
1
|
+
import type { ButtonsLayoutStyles, ButtonsLayoutTheme, CheckoutButtonMethod, CheckoutItem, CheckoutProduct, CheckoutSession, CheckoutSubscription, DeclineEvent, FloPayAppearance, InlineSessionDraft, OneClickSession, PaymentResult, ThemeId } from '@flopay/shared';
|
|
2
2
|
import { FloPayError } from '@flopay/shared';
|
|
3
3
|
import type React from 'react';
|
|
4
4
|
export interface FloPayAutomaticPaymentSuccessEvent {
|
|
@@ -19,6 +19,13 @@ export interface FloPayAutomaticPaymentButtonProps extends Omit<React.ButtonHTML
|
|
|
19
19
|
*/
|
|
20
20
|
nonce?: string;
|
|
21
21
|
createSession?: InlineSessionDraft;
|
|
22
|
+
/**
|
|
23
|
+
* Called on click to fetch a server-minted one-click session (`{ sessionId, nonce }`).
|
|
24
|
+
* Give exactly one of `sessionId`, `getSession` or an inline draft.
|
|
25
|
+
*/
|
|
26
|
+
getSession?: (options: {
|
|
27
|
+
signal: AbortSignal;
|
|
28
|
+
}) => Promise<OneClickSession>;
|
|
22
29
|
/**
|
|
23
30
|
* @deprecated Ignored. The backend now picks the customer's most recent
|
|
24
31
|
* vaulted payment method via `getLatestByUserId` and rebinds the session's
|
|
@@ -78,4 +85,4 @@ export interface FloPayAutomaticPaymentButtonProps extends Omit<React.ButtonHTML
|
|
|
78
85
|
onDecline?: (decline: DeclineEvent) => void;
|
|
79
86
|
children?: React.ReactNode;
|
|
80
87
|
}
|
|
81
|
-
export declare function FloPayAutomaticPaymentButton({ sessionId, nonce, createSession, paymentMethodId: _deprecatedPaymentMethodId, checkoutMethod: _deprecatedCheckoutMethod, clientId, products, items, subscriptions, account, successUrl, cancelUrl, couponCodes, tagsData, utmMetadata, billingApiUrl, locale, theme, appearance, buttonsTheme, buttonsStyles: stylesOverride, onSuccess, onError, onDecline, children, disabled, type, style, ...buttonProps }: FloPayAutomaticPaymentButtonProps): React.JSX.Element;
|
|
88
|
+
export declare function FloPayAutomaticPaymentButton({ sessionId, nonce, createSession, getSession, paymentMethodId: _deprecatedPaymentMethodId, checkoutMethod: _deprecatedCheckoutMethod, clientId, products, items, subscriptions, account, successUrl, cancelUrl, couponCodes, tagsData, utmMetadata, billingApiUrl, locale, theme, appearance, buttonsTheme, buttonsStyles: stylesOverride, onSuccess, onError, onDecline, children, disabled, type, style, ...buttonProps }: FloPayAutomaticPaymentButtonProps): React.JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BeforeButtonClickEvent, CheckoutButtonMethod, CheckoutMode, DeclineEvent, FloInstrumentEvent, FloPayAppearance, FloPayPaymentCancelEvent, InlineSessionDraft, InlineSessionPatch, PaymentMethodLayoutRules, PaymentResult, WalletPresentation } from '@flopay/shared';
|
|
1
|
+
import type { BeforeButtonClickEvent, 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. */
|
|
@@ -40,6 +40,12 @@ export interface FloPayCheckoutProps {
|
|
|
40
40
|
onInstrument?: (event: FloInstrumentEvent) => void;
|
|
41
41
|
/** Called when a payment is declined or the authentication step fails. */
|
|
42
42
|
onDecline?: (decline: DeclineEvent) => void;
|
|
43
|
+
/** Called once per card form when the hosted card fields are interactive. */
|
|
44
|
+
onCardFieldsReady?: (event: CardFieldsReadyEvent) => void;
|
|
45
|
+
/** Called when the hosted card fields fail to load or are not ready within the timeout. */
|
|
46
|
+
onCardFieldsFailed?: (event: CardFieldsFailedEvent) => void;
|
|
47
|
+
/** Milliseconds the card fields may take to become ready before a `timeout` failure. */
|
|
48
|
+
cardFieldsTimeoutMs?: number;
|
|
43
49
|
/**
|
|
44
50
|
* Called once when the buyer closes or leaves the direct PayPal button's
|
|
45
51
|
* PayPal window without approving. Never called for an approval, a decline
|
|
@@ -259,4 +265,4 @@ export interface FloPayCheckoutProps {
|
|
|
259
265
|
* />
|
|
260
266
|
* ```
|
|
261
267
|
*/
|
|
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;
|
|
268
|
+
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, onCardFieldsReady, onCardFieldsFailed, cardFieldsTimeoutMs, cardPreFormSlot, avsLayout, submitLabel, className, initialErrorMessage, initialPayPalOrderId, children, checkoutMode: checkoutModeProp, confirmLabel, renderConfirmButton, onSessionCompleted, }: FloPayCheckoutProps): React.ReactElement;
|