Skip to Content
Documentation
Technical ReferenceReact SDK

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

PropTypeDefaultDescription
sessionIdstring—Reuse a session your backend already created. Mutually exclusive with getSession, createSession and the inline-creation convenience props.
noncestring—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.
createSessionInlineSessionDraft—Create the session inline. Not recommended for one-click: a keyless inline create falls back to Full checkout. Prefer getSession.
clientIdstring—Inline-creation convenience prop forwarded onto the session draft.
currencystring—Inline-creation convenience prop.
productsCheckoutProduct[]—Inline-creation convenience prop.
accountCheckoutAccount—Inline-creation convenience prop.
successUrlstring—Inline-creation convenience prop.
cancelUrlstring—Inline-creation convenience prop.
couponCodesstring[]—Inline-creation convenience prop.
tagsDataTagsData—Inline-creation convenience prop.
utmMetadataRecord<string, string | null | undefined>[]—Inline-creation convenience prop.
themeThemeId—Styles the button and the fallback FloPayCheckout modal that opens when extra authentication is required. See Theming guide.
appearanceFloPayAppearance—Stripe-side appearance overrides. Wins over the resolved theme bundle's appearance.
buttonsStylesButtonsLayoutStyles—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.
childrenReactNode—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.

PropReplacementNotes
buttonsThemethemeLegacy preset ('default' | 'minimal' | 'rounded' | 'dark') still resolves via resolveButtonsLayoutTheme() for back-compat.
paymentMethodIdRemoved (backend orchestration)The backend resolves the customer's saved card server-side.
checkoutMethodRemoved (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.

app/api/one-click-session/route.ts
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 }
}
Fetch the session when the buyer clicks
<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

Reuse a session created on your backend
<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.

Create the session inline
<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_secret URL-param watcher or sessionStorage handshake to wire up
  • when FloPay returns authentication_required without a direct redirect token, the button opens an inline FloPayCheckout modal on the same page so the user can finish authentication without navigating away; that fallback inherits the same theme passed to the button

See Also

On this page