FloPayAutomaticPaymentButton
One-click saved-payment button that runs FloPay's `auto` checkout mode inline and falls back to an in-page `FloPayCheckout` modal when authentication is required.
FloPayAutomaticPaymentButton
A client-side button that triggers FloPay's backend-driven auto checkout mode and keeps the user on the current page. Use it for upsells, add-ons, renewals, and other saved-payment journeys where you want a single button instead of a full checkout form.
import { FloPayAutomaticPaymentButton } from '@flopay/react';
<FloPayAutomaticPaymentButton
getSession={async ({ signal }) => {
const response = await fetch('/api/one-click-session', { method: 'POST', signal });
return response.json(); // { sessionId, nonce }
}}
theme="bold-dark"
onSuccess={({ result, sessionId }) => router.refresh()}
>
Add upsell — $0.80 today
</FloPayAutomaticPaymentButton>;The recommended way to give the button a session is a server-minted one-click session. Your server mints it with @flopay/node checkout.sessions.createOneClick and your merchant credentials, and the button fetches it with getSession when the buyer clicks. See Fetch a server-minted session for the full pattern.
The button shares FloPay's shared processing, success, and decline modal states. When the saved-payment charge requires user interaction, the button opens a fallback FloPayCheckout modal using the same theme, so the button and its recovery modal stay visually consistent.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
sessionId | string | — | Reuse a session your backend already created. Mutually exclusive with getSession, createSession and the inline-creation convenience props. |
nonce | string | — | Session-bound checkout token (the nonce returned when sessionId was created). Required alongside sessionId on post-#640 backends — without it the session read and /process are rejected with 401 "Missing checkout session token.". Ignored on the inline-creation path, where the SDK mints and forwards the nonce itself. See Checkout Session Token. |
getSession | (options: { signal: AbortSignal }) => Promise<{ sessionId: string; nonce: string }> | — | Recommended. Called when the buyer clicks the button. Fetch a server-minted one-click session from your server and resolve to its { sessionId, nonce }, as returned by checkout.sessions.createOneClick. The button aborts the request through signal if it takes too long or the button unmounts. |
createSession | InlineSessionDraft | — | Create the session inline. Not recommended for one-click: a keyless inline create falls back to Full checkout. Prefer getSession. |
clientId | string | — | Inline-creation convenience prop forwarded onto the session draft. |
currency | string | — | Inline-creation convenience prop. |
products | CheckoutProduct[] | — | Inline-creation convenience prop. |
account | CheckoutAccount | — | Inline-creation convenience prop. |
successUrl | string | — | Inline-creation convenience prop. |
cancelUrl | string | — | Inline-creation convenience prop. |
couponCodes | string[] | — | Inline-creation convenience prop. |
tagsData | TagsData | — | Inline-creation convenience prop. |
utmMetadata | Record<string, string | null | undefined>[] | — | Inline-creation convenience prop. |
theme | ThemeId | — | Styles the button and the fallback FloPayCheckout modal that opens when extra authentication is required. See Theming guide. |
appearance | FloPayAppearance | — | Stripe-side appearance overrides. Wins over the resolved theme bundle's appearance. |
buttonsStyles | ButtonsLayoutStyles | — | Per-field style overrides merged on top of the resolved theme bundle. |
onClick | () => void | — | Fires when the button is pressed, before the auto flow begins. |
onSuccess | (event: { result: PaymentResult; sessionId: string }) => void | — | Fires after the success modal state completes. |
onError | (error: FloPayError) => void | — | Fires when the auto flow fails. |
onDecline | (decline: DeclineEvent) => void | — | Fires when the failure can be classified as a decline or cancellation. |
children | ReactNode | — | Button slot content. When omitted, the default embedded button content renders. |
FloPayAutomaticPaymentButton also extends the standard React button props (disabled, className, aria-*, etc.).
Deprecated props
These props are accepted for back-compat and silently ignored. New code should not pass them.
| Prop | Replacement | Notes |
|---|---|---|
buttonsTheme | theme | Legacy preset ('default' | 'minimal' | 'rounded' | 'dark') still resolves via resolveButtonsLayoutTheme() for back-compat. |
paymentMethodId | Removed (backend orchestration) | The backend resolves the customer's saved card server-side. |
checkoutMethod | Removed (backend orchestration) | The backend chooses the gateway from current eligibility and the merchant's preference order, independently of where the card was first saved; see Gateway selection. The SDK no longer ships client-built tokenizedData to createSession. |
Pass userId via account.userId so the backend can resolve the customer's saved payment method. Do not pass paymentMethodId or checkoutMethod from the client: they are silently ignored, and the backend picks the payment method and the gateway.
Session Sources
Pass exactly one session source to the button: sessionId (with its nonce), getSession, or an inline draft (createSession or the inline-creation convenience props). If it receives more than one, the button reports a validation_error through onError and does not charge.
Fetch a server-minted session
The recommended session source is a server-minted one-click session. Your server mints it with @flopay/node checkout.sessions.createOneClick and the merchant credentials described on the API tokens page, then returns only { sessionId, nonce } to the browser. The button calls getSession when the buyer clicks and charges that session.
Take the buyer from your own login session on the server, never from the request body or any other browser input. The endpoint decides who is buying; the browser only asks for a session.
import { FloPay } from '@flopay/node';
import { getCurrentUser } from '@/lib/auth'; // your own login session
const flopay = new FloPay({
merchantCredentials: {
clientUuid: process.env.FLOPAY_CLIENT_ID!,
apiToken: process.env.FLOPAY_API_TOKEN!,
},
});
export async function POST() {
const user = await getCurrentUser();
if (!user) return new Response(null, { status: 401 });
const session = await flopay.checkout.sessions.createOneClick({
billingApiUrl: 'https://billing.example.com',
checkoutBaseUrl: 'https://checkout.example.com',
clientId: process.env.FLOPAY_CLIENT_ID!,
currency: 'USD',
account: { userId: user.id, email: user.email },
products: [{ code: 'upsell_ai_pack' }],
successUrl: 'https://shop.example.com/success',
cancelUrl: 'https://shop.example.com/cancel',
});
return Response.json(session); // { sessionId, nonce }
}<FloPayAutomaticPaymentButton
getSession={async ({ signal }) => {
const response = await fetch('/api/one-click-session', { method: 'POST', signal });
if (!response.ok) throw new Error('Could not start the purchase');
return response.json();
}}
theme="bold-dark"
onSuccess={() => router.refresh()}
>
Purchase Item
</FloPayAutomaticPaymentButton>The getSession prop needs @flopay/react 1.10 or later. On SDK versions before 1.10, mint the session on your server the same way, fetch it before you render the button, and pass its sessionId and nonce props instead.
If getSession rejects or does not resolve in time, the button reports the failure through onError and does not charge.
Reuse a session you already created
<FloPayAutomaticPaymentButton
sessionId="sess_abc123"
nonce="nonce_abc123"
theme="bold-dark"
onSuccess={() => router.refresh()}
>
Purchase Item
</FloPayAutomaticPaymentButton>When you reuse a backend-created sessionId, pass the session's nonce too. A session read does not echo the nonce back, so the SDK cannot recover it on its own — omit it and the session read and /process are rejected with 401 "Missing checkout session token.". On the inline-creation path the SDK mints the nonce from the create response and forwards it for you (including into the fallback modal), so you do not pass it there.
Create the session inline (Full checkout fallback)
An inline draft is not recommended for one-click. The browser creates the session without your merchant credentials, so a keyless Auto or Confirm create falls back to Full checkout instead of charging the saved payment method in one click. On this path the button forces checkoutMode="auto" under the hood.
<FloPayAutomaticPaymentButton
createSession={{
clientId: 'client_123',
currency: 'USD',
account: {
userId: 'user_123',
email: 'customer@example.com',
},
products: [
{
code: 'upsell_ai_pack',
name: 'AI Supercharger Pack',
totalAmount: 249,
quantity: 1,
},
],
successUrl: `${window.location.origin}/success`,
cancelUrl: `${window.location.origin}/cancel`,
}}
theme="bold-dark"
>
Purchase Item
</FloPayAutomaticPaymentButton>Do not pass both sessionId and inline-creation props at the same time.
Authentication And Redirect Handling
When a session is created without your merchant credentials, such as a keyless inline draft, FloPay demotes it to Full checkout and reports merchant_auth_required. The button then opens Full checkout so the buyer can still pay, and onError receives an authentication error with the code merchant_auth_required. It is not a decline and does not start 3DS recovery. To keep one-click, mint the session on your server and pass getSession.
The button does not hard-fail when extra authentication is needed:
- when the saved payment method can complete immediately, the button shows the shared processing and success modal states
- when the provider returns a redirect-capable flow (3DS or PayPal), the backend resumes and captures the result end-to-end — there is no longer a client-side
payment_intent_client_secretURL-param watcher or sessionStorage handshake to wire up - when FloPay returns
authentication_requiredwithout a direct redirect token, the button opens an inlineFloPayCheckoutmodal on the same page so the user can finish authentication without navigating away; that fallback inherits the samethemepassed to the button