@flopay/react 1.16.4 → 1.16.6
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 +26 -1
- package/dist/automatic-payment-button.d.ts +9 -2
- package/dist/index.cjs +9 -9
- package/dist/index.mjs +7 -7
- package/dist/one-click-warnings.d.ts +12 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -377,6 +377,28 @@ export function AddBrandedCard(props: { sessionId: string; nonce: string; theme:
|
|
|
377
377
|
|
|
378
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.
|
|
379
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
|
+
|
|
380
402
|
### Composing your own checkout
|
|
381
403
|
|
|
382
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.
|
|
@@ -760,7 +782,8 @@ Also accepts every standard `button` attribute, such as `onClick`, `disabled`, a
|
|
|
760
782
|
| Prop | Type | Description |
|
|
761
783
|
|------|------|-------------|
|
|
762
784
|
| `sessionId` / `nonce` | `string?` | Reuse an existing auto-mode session |
|
|
763
|
-
| `
|
|
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`) |
|
|
764
787
|
| `clientId` | `string?` | Merchant client id for inline creation |
|
|
765
788
|
| `items` / `subscriptions` / `products` | arrays | Cart for inline creation |
|
|
766
789
|
| `account` | `object?` | Buyer account; `userId` required, `email` optional |
|
|
@@ -881,6 +904,8 @@ Checkout errors reach `onError` (and the `error` render prop) as `FloPayError` v
|
|
|
881
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. |
|
|
882
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. |
|
|
883
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`. |
|
|
884
909
|
|
|
885
910
|
Every `external_payment_method_failed` keeps that code and the existing buyer
|
|
886
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;
|