Customize your checkout
Apply consistent themes, order payment methods by buyer country, and add automatic payment buttons for focused purchase flows.
Customize your checkout
Use checkout themes to match your product experience, choose which payment methods each buyer sees first, then add automatic payment buttons when a buyer should complete a focused purchase without opening a full checkout first.
Who this is for
This guide is for developers and designers who need consistent checkout styling, reusable theme bundles, or a compact payment action for upgrades, add-ons, and saved-payment-method flows.
Choose the checkout surface
Start with FloPayCheckout when buyers need to review or enter payment details. Use FloPayAutomaticPaymentButton for a focused action that can charge a saved method and fall back to checkout when authentication or new details are required. The same theme can cover both surfaces.
Apply a checkout theme
FloPay ships six first-class theme bundles plus a 'classic' no-op marker. A single theme value on FloPayCheckout, FloPayAutomaticPaymentButton, or SplitCardForm paints both sides of the integration in one go:
- the Stripe-side appearance (palette + nested-input
rules) - the React-rendered wrapper, title, submit button, and inputs
- on
FloPayAutomaticPaymentButton, the fallbackFloPayCheckoutmodal that opens when the saved-payment charge needs user interaction
Build a theme visually in the theme editor on our playground, then drop the resulting theme value (or copy custom appearance / buttonsStyles overrides) into your app.
Theme Bundles
theme value | ThemeBundleId | Aesthetic |
|---|---|---|
'modern-light' | ✓ | Clean & airy: Inter, soft shadows, generous spacing, FloPay-blue accents |
'modern-dark' | ✓ | Modern light with a dark surface |
'bold-light' | ✓ | Saturated FloPay blue, gradient pill submit, heavy borders |
'bold-dark' | ✓ | Bold light on a dark surface |
'glass-light' | ✓ | Translucent surfaces with backdrop blur on a blue gradient |
'glass-dark' | ✓ | Glass light on a dark surface |
'classic' | Not applicable | Marker that preserves the historic FloPay look (#EDEDFF wrapper, #4A49FF indigo submit) so consumers can declare a default explicitly |
All bundles are built around FloPay blue: #1785E0 on light bundles, #60A5FA on dark bundles for contrast.
One Prop, Everywhere
import { FloPayCheckout, FloPayAutomaticPaymentButton } from '@flopay/react';
// Same look across both components
<FloPayCheckout theme="bold-dark" sessionId={sessionId} onComplete={handleSuccess} />
<FloPayAutomaticPaymentButton theme="bold-dark" sessionId={upsellSessionId} onSuccess={handleSuccess}>
Add upsell
</FloPayAutomaticPaymentButton>SplitCardForm accepts the same theme prop when you want to render it manually inside FloPayProvider.
Resolution Precedence
When several styling props are present, the SDK resolves them from highest priority to lowest:
- Explicit
appearance: overrides the theme bundle's appearance (palette + Striperules). - Explicit
buttonsStyles: merges per-field on top of the theme bundle's button-layout styles. themebundle.- Legacy
buttonsThemepreset (back-compat for older integrations). - Hardcoded defaults.
You can drop a theme on the component and surgically override only the fields you need:
<FloPayCheckout
sessionId={sessionId}
theme="modern-light"
buttonsStyles={{
submitButton: { backgroundColor: '#0F172A' },
}}
/><FloPayCheckout
sessionId={sessionId}
theme="glass-dark"
appearance={{
variables: { colorPrimary: '#22D3EE' },
rules: { '.Input': { border: '1px solid rgba(255,255,255,0.3)' } },
}}
/>Reading A Bundle From @flopay/shared
The bundle map is exported so you can render swatches, preview cards, or merge an appearance into another system without re-implementing the look:
import {
THEMES,
resolveTheme,
MODERN_LIGHT_APPEARANCE,
BUTTONS_LAYOUT_MODERN_LIGHT,
} from '@flopay/shared';
const glassDark = THEMES['glass-dark'];
// { appearance: FloPayAppearance, buttonsLayout: ButtonsLayoutStyles }
const maybeBundle = resolveTheme('bold-light');
if (maybeBundle) {
console.log(maybeBundle.appearance.variables?.colorPrimary);
}
// Direct constant access: handy when you want to merge two themes
const merged = {
...MODERN_LIGHT_APPEARANCE,
variables: { ...MODERN_LIGHT_APPEARANCE.variables, colorPrimary: '#FF7A1A' },
};resolveTheme('classic') returns undefined: 'classic' is a marker, not a bundle, so the SDK falls through to its hardcoded defaults.
Runtime Theme Swapping
StripeAdapter.getElements() detects appearance changes between calls and live-updates the cached Stripe Elements group via elements.update({ appearance }). That makes runtime theme swaps actually re-style mounted card iframes:
const [mode, setMode] = useState<'light' | 'dark'>('light');
<FloPayCheckout
sessionId={sessionId}
theme={mode === 'dark' ? 'modern-dark' : 'modern-light'}
onComplete={handleSuccess}
/>Previously the Stripe iframe kept its stale styling because the elements group was cached. With the new adapter behavior, swapping theme (or appearance) at runtime takes effect on mounted inputs.
Appearance Derivation
When you pass appearance without a matching buttonsStyles, SplitCardForm now derives its React-side styling from appearance.variables:
- wrapper background falls back to
appearance.variables.colorBackground(the SDK default#FFFFFFis skipped so the historic#EDEDFFtint is preserved for'classic') - submit-button background falls back to
appearance.colorPrimary - title color, input color, border radius, and font family all derive from
appearance.variables
In practice, passing a custom appearance alone now produces a visibly themed form across layout="default" and layout="buttons".
Theme Variables Reference
| Variable | Type | Description |
|---|---|---|
colorPrimary | CSS color | Buttons, links, focus rings |
colorBackground | CSS color | Element backgrounds |
colorText | CSS color | Labels and input text |
colorDanger | CSS color | Error messages and invalid states |
borderRadius | CSS length | Corner rounding for inputs and buttons |
fontFamily | CSS font-family | Font stack for all elements |
fontSizeBase | CSS length | Base font size |
spacingUnit | CSS length | Base spacing multiplier |
appearance.rules accepts CSS-like blocks keyed by Stripe Element selectors (.Input, .Input:focus, .Label, .Tab, .Tab--selected) for fine-grained styling inside the iframe.
The hosted card form asks for the expiry in one expiry field with the placeholder MM / YY. The expiry field follows the same theme settings as the other card fields, so it needs no setting of its own.
Buttons Layout Slots
When you use FloPayCheckout with layout="buttons", the expanded card form supports content slots for the card button, back button label, and title:
<FloPayCheckout
sessionId={sessionId}
layout="buttons"
cardButtonContent="Pay by card"
cardBackButtonContent=""
cardTitleContent="Enter card details"
onComplete={handleSuccess}
/>Pass any ReactNode to these props. Passing '' removes the text completely. The demo /theme playground includes controls for these slot props alongside theme and buttonsStyles.
Migrating From buttonsTheme
Legacy values still resolve via resolveButtonsLayoutTheme() for back-compat. Older integrations keep working untouched: the prop is silently ignored if theme is also supplied: but new code should use theme:
| Old | New |
|---|---|
buttonsTheme="default" | theme="classic" |
buttonsTheme="minimal" | theme="modern-light" |
buttonsTheme="rounded" | theme="modern-light" or theme="bold-light" |
buttonsTheme="dark" | theme="bold-dark" |
See Also
- Custom Theme example: side-by-side bundles plus override snippets
- Shared constants reference: every
*_APPEARANCE,BUTTONS_LAYOUT_*, andTHEMESexport - Shared types reference:
ThemeBundleId,ThemeId,ThemeBundle
Order payment methods
Choose which payment methods a buyer sees first, put the ones that convert poorly for you behind a closed More payment options link, and use different rules for buyers in different countries. FloPay applies your rules to each buyer and the checkout shows the result. These options need @flopay/react 1.16.0 or newer. Without them, the checkout looks and behaves exactly as before and makes no extra request.
These options are available in the React SDK. Vue gets them with the next major version of the SDK.
Payment method groups
The checkout orders four groups of payment methods. Ordering works on whole groups, not on individual methods within a group.
| Group | What it shows |
|---|---|
'card' | The card form. On layout="buttons" it is the Credit / Debit Card button. |
'paypal' | PayPal |
'wallets' | Apple Pay and Google Pay |
'apms' | Alternative payment methods, such as Klarna, iDEAL or SEPA Direct Debit |
Set the order
Pass paymentMethodLayout to FloPayCheckout (or SplitCardForm) with an order:
<FloPayCheckout
sessionId={sessionId}
nonce={nonce}
layout="buttons"
paymentMethodLayout={{ order: ['card', 'wallets', 'apms', 'paypal'] }}
/>- Groups you leave out follow the ones you list, in the default order, so
order: ['card']puts card first and keeps the rest as they were. The default order is PayPal, wallets, APMs, then card. - On
layout="buttons", all four groups follow the order. - On the default layout, PayPal, wallets and APMs follow the order among the buttons. With
'card'first, the card form moves above the buttons with an "or pay another way" divider. Anywhere else, the card form stays below "or pay with card". - Unknown or repeated values are ignored, and a console warning says what was ignored.
Put methods behind "More payment options"
Add moreOptions to list the groups that should stay available without competing for the buyer's first tap:
paymentMethodLayout={{
order: ['card', 'wallets', 'apms', 'paypal'],
moreOptions: ['paypal'],
}}- Placement. On
layout="buttons", the link sits under the buttons, and any group can go behind it, card included. On the default layout, it sits under the buttons and above "or pay with card". The card form always stays in view there, so'card'inmoreOptionsapplies to the buttons layout only. - Opening. The link is closed at first. Opening it reveals the groups behind it in place, in your order, and they stay revealed. They load while the link is closed, so PayPal and the wallets are ready the moment the buyer opens it, and they work exactly as they do in view, including PayPal's popup or redirect.
- Edge cases. If nothing available would stay in view, every group shows and there is no link. If nothing behind the link is available (hidden by a show/hide prop, or no wallet on the buyer's device), there is no link.
- Text and look. The link reads "More payment options". Set
moreOptionsLabelto your own final, already-translated text. The link takes your theme's accent color (appearance.variables.colorPrimary) and font. - Accessibility. The link is a button: buyers reach it with Tab, open it with Enter or Space, and screen readers announce it as collapsed. Opening it moves focus to the revealed methods, which are labeled with the link's text.
Rules by buyer country
Add countryRules to give buyers in some countries their own order and moreOptions:
paymentMethodLayout={{
order: ['card', 'wallets', 'apms', 'paypal'],
moreOptions: ['paypal'],
countryRules: [
{ countries: ['US', 'GB', 'CA', 'AU', 'NZ', 'IE'], order: ['paypal'], moreOptions: [] },
],
}}- Each rule lists ISO 3166-1 alpha-2
countries, in any case. The first rule that names the buyer's country applies. A country named by an earlier rule stays with that rule. You can set up to 50 rules. - A field a rule leaves out uses your default: a rule without
moreOptionskeeps the defaultmoreOptions, andmoreOptions: []shows every group. - FloPay picks the buyer's country in this order:
- the country you sent on the checkout session (the buyer's address country);
- if you sent none, the country of the buyer's own connection (their IP country), where FloPay can determine it;
- if neither is known, your default
orderandmoreOptionsapply.
- Send the buyer's country on the checkout session whenever you know it. It is the most reliable way to get the right rule.
- The IP country is used only to pick the rule. It never reaches your page, and FloPay does not store it or use it for anything else, such as routing or fraud checks.
The checkout sends your rules to FloPay once the checkout session exists, and again if they change. While it waits, the payment methods show placeholders, so nothing moves once it is on screen. If FloPay does not answer within 1.5 seconds, your default order and moreOptions apply without country rules. The SDK makes this request for you; the endpoint (POST /v1/checkouts/sessions/{id}/payment-method-layout) is in the API reference.
How it works with other props
- Show and hide. Hiding a group is still the job of
showPayPal,showStripe,showApplePay,showGooglePayandenabledPaymentMethods. A hidden or unavailable group is skipped and leaves no gap, wherever your order puts it. - Layout.
paymentMethodLayoutworks with both values oflayout, and with runtime layout switches. - Changing the rules. The rules can change after the checkout mounts. The checkout asks FloPay again and keeps the current order until the new one is known. A group that moves is mounted again rather than moved, so a provider button never breaks. Set the rules before the buyer starts paying, because a moved card form reloads its fields.
- Custom layouts.
FloPayCheckoutpassespaymentMethodLayoutandmoreOptionsLabelinto custom-layoutSplitCardFormchildren that do not set their own. - Themes. The placeholders and the link follow the theme you set with
themeandappearance; see Apply a checkout theme.
Events
onInstrumentreceivesmore_options_openedwhen a buyer opens the link, at most once per checkout, so you can measure how often buyers use it. See Checkout analytics.- Problems in your rules (an unknown group, an invalid country code, a repeated entry) are logged to the browser console as
[FloPay] paymentMethodLayout: …warnings. The rest of your rules still apply. - The checkout does not tell your page which country picked the rule, because the IP country stays on FloPay's servers.
Complete example
Card, Apple Pay, Google Pay and alternative payment methods first for most buyers, with PayPal behind "More payment options". Buyers in the United States, the United Kingdom, Canada, Australia, New Zealand and Ireland see PayPal first, with no link.
import { FloPayCheckout, type PaymentMethodLayoutRules } from '@flopay/react';
const paymentMethodLayout: PaymentMethodLayoutRules = {
order: ['card', 'wallets', 'apms', 'paypal'],
moreOptions: ['paypal'],
countryRules: [
{
countries: ['US', 'GB', 'CA', 'AU', 'NZ', 'IE'],
order: ['paypal', 'card', 'wallets', 'apms'],
moreOptions: [],
},
],
};
export function Checkout({ sessionId, nonce }: { sessionId: string; nonce: string }) {
return (
<FloPayCheckout
sessionId={sessionId}
nonce={nonce}
layout="buttons"
paymentMethodLayout={paymentMethodLayout}
onInstrument={(event) => {
if (event.name === 'more_options_opened') analytics.track('More payment options opened');
}}
onComplete={handleSuccess}
/>
);
}Send the buyer's country on the checkout session when you know it, so the rule follows their address and does not depend on their connection.
Show card brand icons
Set showCardBrandIcons to show Visa, Mastercard, Amex and Discover icons inside the card number field, right-aligned. Once the buyer types, only the detected brand's icon stays. The icons are off by default: only true turns them on. This option needs @flopay/react or @flopay/vue 1.17.0 or newer. An older hosted card form ignores it, and the card number field looks as it did before.
<FloPayCheckout
sessionId={sessionId}
nonce={nonce}
showCardBrandIcons
onComplete={handleSuccess}
/>In React, SplitCardForm and FloPayCheckout take the same prop, and so does the Vue checkout. See the FloPayCheckout props and the SplitCardForm props. If you mount the hosted card form yourself with @flopay/js, call setCardBrandIcons(show) to turn the icons on or off without remounting.
Change the card field placeholders
Set cardFieldPlaceholders to replace the placeholder text inside the hosted card fields. It takes four keys, and every key is optional: number for the card number, expiry for the expiry date, cvv for the security code and name for the cardholder name. This option needs @flopay/react or @flopay/vue 1.18.0 or newer.
<FloPayCheckout
sessionId={sessionId}
nonce={nonce}
cardFieldPlaceholders={{
number: 'Card number',
name: 'Name as it appears on the card',
}}
onComplete={handleSuccess}
/>A field you do not set shows the default wording:
| Key | Field | Default wording |
|---|---|---|
number | Card number | Card Number |
expiry | Expiry date | MM / YY |
cvv | Security code | CVV |
name | Cardholder name | Full name on Card |
- Empty string. An empty string shows no placeholder. The field keeps its accessible name, so screen readers still announce it.
- Long or unusual text. The hosted form shows the text literally, never as HTML, and removes control characters. Text longer than 64 characters is cut to 64 characters, never rejected. The limit counts Unicode code points, so an emoji is never split.
- Updates. When the prop changes, the fields update live, without remounting the form or clearing what the buyer typed. Each update replaces the previous set as a whole: a key the new value leaves out goes back to its default wording.
- Scope. The text is bound to the checkout session and sent only to the hosted form's own origin. If you do not set the prop, the card form looks as it did before.
In React, SplitCardForm and FloPayCheckout take the same prop, and so does the Vue checkout. See the FloPayCheckout props and the SplitCardForm props. If you mount the hosted card form yourself with @flopay/js, call setCardFieldPlaceholders(placeholders) to change the text without remounting.
Show labels above the card fields
Set showCardFieldLabels to show a visible label above each hosted card field: the card number, the expiry date, the security code and the name on the card. The labels are off by default: only true turns them on. Set cardFieldLabels to change their text. It takes four keys, and every key is optional: number for the card number, expiry for the expiry date, cvv for the security code and name for the cardholder name. This option needs @flopay/react 1.19.0 or newer.
<FloPayCheckout
sessionId={sessionId}
nonce={nonce}
showCardFieldLabels
cardFieldLabels={{
number: 'Card number',
name: 'Name as it appears on the card',
}}
onComplete={handleSuccess}
/>A label without text of its own shows the default text:
| Key | Field | Default text |
|---|---|---|
number | Card number | Card number |
expiry | Expiry date | Expiry date |
cvv | Security code | Security code |
name | Cardholder name | Name on card |
- Empty or missing text. An empty or missing text shows the default label, and so does text the hosted form cannot show. Placeholders work the other way: there, an empty string shows no placeholder.
- Long or unusual text. The hosted form shows the text literally, never as HTML. Text longer than 64 characters is cut to 64 characters.
- Updates. Turning the labels on or off, or changing their text, updates the form live, without remounting it or clearing what the buyer typed. Each update replaces the previous set as a whole: a key the new value leaves out goes back to its default text.
- Hidden fields. A label is hidden together with its field. When the name field is hidden, its label is hidden too.
- Scope. If you do not set
showCardFieldLabels, the card form looks as it did before.
In React, SplitCardForm and FloPayCheckout take the same props. See the FloPayCheckout props and the SplitCardForm props. If you mount the hosted card form yourself with @flopay/js, call setShowCardFieldLabels(show) and setCardFieldLabels(labels) to change them without remounting.
Style the card field labels
Style the labels with the .Label rule of appearance.rules. The hosted card form takes six properties of that rule and applies them to every label at once. Label styles show only while the labels are on. This needs @flopay/react 1.19.0 or newer.
<FloPayCheckout
sessionId={sessionId}
nonce={nonce}
showCardFieldLabels
appearance={{
rules: {
'.Label': {
color: '#c2185b',
fontSize: '13px',
fontWeight: '700',
letterSpacing: '0.08em',
textTransform: 'uppercase',
marginBottom: '10px',
},
},
}}
onComplete={handleSuccess}
/>| Property | Accepted values | What it sets |
|---|---|---|
color | #RRGGBB, rgb(r, g, b) or rgba(r, g, b, a) | The label text color. Other color forms, such as color names, are ignored. |
fontSize | 10 to 32 px, for example '13px' | The label font size. |
fontWeight | Whole numbers from 100 to 900, or normal (400) and bold (700) | The label font weight. |
letterSpacing | -0.1 to 0.5 em, for example '0.08em' | The space between letters. |
textTransform | none, uppercase, lowercase or capitalize | The letter case of the label text. |
marginBottom | 0 to 48 px, for example '10px' | The gap between each label and its field. |
- Out-of-range values. A value outside its range, or of the wrong type, is ignored and that property keeps its default. The other properties of the rule still apply.
- Unset properties. A property you leave unset follows the form's own text color and font.
- Other properties. The hosted card form uses only these six properties of the
.Labelrule. - Updates. A new style applies live, without reloading the form or clearing what the buyer typed.
Add automatic payment buttons
FloPayAutomaticPaymentButton turns FloPay's backend-driven auto checkout mode into a client component you can place anywhere in your UI. It is designed for upsells, add-ons, renewals, and other saved-payment journeys where you want a single button instead of a full checkout form.
The button keeps the user on the current page while still giving you FloPay's shared processing, success, and decline modal states.
When To Use It
Use FloPayAutomaticPaymentButton when you want to:
- trigger a saved-payment purchase from a success page or account area
- fetch a server-minted one-click session from your server with
getSession(recommended) - reuse an existing
sessionIdcreated elsewhere - style the button with the same theme system as the embedded buttons layout
- receive explicit
onClick,onSuccess,onError, andonDeclineevents
Basic Example
The recommended setup is a server-minted session. Your server mints the one-click session with @flopay/node checkout.sessions.createOneClick and your merchant credentials, taking the buyer from your own login session rather than the request body. The button fetches the session with getSession when the buyer clicks. See the createOneClick reference for the server endpoint.
'use client';
import { FloPayAutomaticPaymentButton } from '@flopay/react';
export function UpsellButton() {
return (
<FloPayAutomaticPaymentButton
getSession={async ({ signal }) => {
// Your endpoint calls createOneClick and returns { sessionId, nonce }.
const response = await fetch('/api/one-click-session', { method: 'POST', signal });
return response.json();
}}
theme="bold-dark"
onClick={() => {
console.log('automatic payment button clicked');
}}
onSuccess={({ result, sessionId }) => {
console.log('payment succeeded', result.status, sessionId);
}}
onError={(error) => {
console.error(error.message);
}}
onDecline={(decline) => {
console.log('payment declined', decline.code);
}}
>
Purchase Item
</FloPayAutomaticPaymentButton>
);
}Session Sources
Pass exactly one of these input shapes:
getSession(recommended), a function the button calls on click to fetch a server-minted one-click session that your server created withcreateOneClicksessionId(plus itsnonce) when your backend already created the checkout session- inline session data via
createSession - direct convenience props for inline creation:
clientId,currency,products,account,successUrl,cancelUrl,couponCodes,tagsData,utmMetadata
The getSession prop needs @flopay/react 1.10 or later. On SDK versions before 1.10, fetch the server-minted session yourself and pass its sessionId and nonce.
A keyless inline create, made in the browser without your merchant credentials, falls back to Full checkout instead of one click. For inline drafts the component forces checkoutMode="auto" under the hood.
The backend resolves the customer's saved card and chooses the gateway for the payment from current eligibility and your preference order, then reuses or prepares that card's binding on the chosen account. The saved card does not decide the gateway. You no longer pass paymentMethodId or checkoutMethod from the client: the backend orchestrates gateway selection and the tokenizedData shape per provider ({ id: vaultToken } for Stripe, { userPaymentMethodId: uuid } for PayPal). See Gateway selection.
Reuse An Existing Session
Pass the session's nonce alongside sessionId. Your backend returns it on the create response (see Checkout Session Token); the SDK forwards it as the x-checkout-session-token header on the session read and /process. Without it, current backends reject both with 401 "Missing checkout session token.".
<FloPayAutomaticPaymentButton
sessionId="sess_abc123"
nonce="nonce_abc123"
onSuccess={() => window.location.reload()}
>
Purchase Item
</FloPayAutomaticPaymentButton>On the inline-creation path (createSession or the convenience props) you do not pass a nonce: the SDK mints it from the create response and threads it through every continuation call, including the fallback FloPayCheckout modal that opens when the charge needs extra authentication.
Create The Session Inline
Inline creation is not recommended for one-click. A keyless inline create falls back to Full checkout, so use it only when you accept that fallback.
<FloPayAutomaticPaymentButton
createSession={{
clientId: 'client_123',
currency: 'USD',
account: {
userId: 'user_123',
email: 'customer@example.com',
},
products: [{ code: 'upsell_ai_pack' }],
successUrl: `${window.location.origin}/success`,
cancelUrl: `${window.location.origin}/success`,
}}
>
Purchase Item
</FloPayAutomaticPaymentButton>Do not pass both sessionId and inline session-creation props at the same time.
Styling And Slot Content
The button shares the same theme system as FloPayCheckout. One theme value styles the button and the fallback FloPayCheckout modal that opens when the saved-payment charge needs user interaction:
themeaccepts anyThemeId('classic' | 'modern-light' | 'modern-dark' | 'bold-light' | 'bold-dark' | 'glass-light' | 'glass-dark')appearanceandbuttonsStylesare still available as per-field overrides on top of the theme bundlechildrenrender inside the button, so you can treat them as the button slot content
<FloPayAutomaticPaymentButton
sessionId="sess_abc123"
theme="bold-dark"
buttonsStyles={{
cardButtonFontSize: '1rem',
}}
>
<span style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}>
<strong>Add AI Supercharger Pack</strong>
<span style={{ opacity: 0.72 }}>$0.80 today</span>
</span>
</FloPayAutomaticPaymentButton>If children are omitted, the default embedded button content is rendered for you. See the Theming guide for the resolution precedence (appearance > buttonsStyles > theme > legacy buttonsTheme > defaults).
Events
| Prop | Purpose |
|---|---|
onClick | Fires when the button is pressed, before the automatic payment flow begins |
onSuccess | Fires after the success modal state completes; includes the payment result and resolved session details |
onError | Fires when the automatic payment flow fails with a FloPayError |
onDecline | Fires when FloPay can classify the failure as a decline or cancellation event |
FloPayAutomaticPaymentButton also extends the standard React button props, so disabled, className, aria-*, and similar attributes work as expected.
Authentication And Redirect Handling
Automatic Payment Buttons do 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 payment provider returns a redirect-capable auth flow such as 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 modal inherits the samethemeyou passed to the button
This makes the component a better fit for upsells than raw backend-only auto mode.
See Also
- Cascading Processing: how auto-checkout cascades across a returning customer's saved payment methods behind
autocheckout - Automatic Payment Buttons Example
- FloPayCheckout Guide
- Theming Guide
Complete theme example
FloPay ships six first-class theme bundles plus a 'classic' no-op marker. Pass a single theme value to FloPayCheckout, FloPayAutomaticPaymentButton, or SplitCardForm and the SDK styles both the Stripe-rendered fields and the React-rendered wrapper, submit button, and inputs from the same source.
Design your theme visually in the Theme Playground. Pick a bundle, tweak overrides, and copy the props straight into your code.
Bundled Themes
theme value | Aesthetic |
|---|---|
'modern-light' / 'modern-dark' | Clean & airy: Inter, soft shadows, generous spacing, FloPay-blue accents |
'bold-light' / 'bold-dark' | Saturated FloPay blue with a gradient pill submit and heavy borders |
'glass-light' / 'glass-dark' | Translucent surfaces with backdrop blur over a blue gradient |
'classic' | No-op marker that preserves the historic FloPay look (#EDEDFF wrapper, #4A49FF indigo submit) |
All bundles are built around FloPay blue (#1785E0 on light bundles, #60A5FA on dark bundles).
One Prop, Consistent Look
'use client';
import { FloPayCheckout } from '@flopay/react';
export default function ThemedCheckoutPage() {
return (
<FloPayCheckout
sessionId="your-session-uuid"
theme="bold-dark"
onComplete={(result) => console.log('Paid!', result)}
/>
);
}The same theme value styles the Stripe Elements inside the iframe and the React-rendered wrapper, title, submit button, and name input. No second prop to keep in sync.
Switching Bundles Side-By-Side
'use client';
import { FloPayCheckout } from '@flopay/react';
export function ThemeGallery({ sessionId }: { sessionId: string }) {
return (
<div
style={{
display: 'grid',
gap: '1.5rem',
gridTemplateColumns: 'repeat(auto-fit, minmax(280px, 1fr))',
}}
>
<section>
<h3>Modern Light</h3>
<FloPayCheckout sessionId={sessionId} theme="modern-light" />
</section>
<section>
<h3>Bold Dark</h3>
<FloPayCheckout sessionId={sessionId} theme="bold-dark" />
</section>
<section>
<h3>Glass Dark</h3>
<FloPayCheckout sessionId={sessionId} theme="glass-dark" />
</section>
</div>
);
}Resolution Precedence
When multiple styling props are present, the SDK resolves them from highest priority to lowest:
- Explicit
appearance: overrides the theme's appearance (palette + Striperules). - Explicit
buttonsStyles: merges per-field on top of the theme's button layout. themebundle.- Legacy
buttonsThemepreset (back-compat for older integrations). - Hardcoded defaults.
This means you can drop a theme onto the component and then surgically override just the fields you need:
<FloPayCheckout
sessionId={sessionId}
theme="modern-light"
buttonsStyles={{
submitButton: { backgroundColor: '#0F172A' },
}}
/><FloPayCheckout
sessionId={sessionId}
theme="glass-dark"
appearance={{
rules: {
'.Input': { border: '1px solid rgba(255,255,255,0.3)' },
},
}}
/>Picking A Bundle Programmatically
Import the bundle map from @flopay/shared if you need to reference the appearance or button-layout directly (for example, to render a preview swatch outside the SDK):
import { THEMES, resolveTheme } from '@flopay/shared';
const glassDark = THEMES['glass-dark'];
// { appearance: FloPayAppearance, buttonsLayout: ButtonsLayoutStyles }
const bundle = resolveTheme('bold-light');
if (bundle) {
console.log(bundle.appearance.variables?.colorPrimary);
}resolveTheme('classic') returns undefined: 'classic' is a marker, not a bundle, so the SDK falls through to its hardcoded defaults.
Migrating From buttonsTheme
Legacy values still resolve via the back-compat shim, but new code should use theme:
| Old | New |
|---|---|
buttonsTheme="default" | theme="classic" |
buttonsTheme="minimal" | theme="modern-light" |
buttonsTheme="rounded" | theme="modern-light" (rounded corners) or theme="bold-light" |
buttonsTheme="dark" | theme="bold-dark" |
buttonsTheme is silently ignored when theme is supplied alongside it, so a single-line swap is safe.
See Also
- Theming guide: full reference for
theme,appearance, andbuttonsStyles - Shared constants reference: every
*_APPEARANCE,BUTTONS_LAYOUT_*, andTHEMESexport
Complete automatic payment button example
This example shows a same-page upsell on a success screen. The user keeps their original purchase details in view, clicks a single saved-payment button, and successful upsells are appended back into the page state. It uses the recommended server-minted session: the /api/upsell-session endpoint calls createOneClick with your merchant credentials and the buyer from your own login session, and the button fetches it with getSession.
'use client';
import { useMemo, useState } from 'react';
import { FloPayAutomaticPaymentButton } from '@flopay/react';
type PurchaseEntry = {
name: string;
amount: number;
currency: string;
};
const upsellProduct = {
code: 'upsell_ai_pack',
name: 'AI Supercharger Pack',
totalAmount: 249,
quantity: 1,
};
const upsellCurrency = 'USD';
function formatAmount(amount: number, currency: string) {
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency,
}).format(amount);
}
export default function UpsellSection() {
const [upsells, setUpsells] = useState<PurchaseEntry[]>([]);
const buttonLabel = useMemo(() => {
const amount = upsellProduct.totalAmount;
return `Add ${upsellProduct.name} for ${formatAmount(amount, upsellCurrency)}`;
}, []);
return (
<section style={{ display: 'grid', gap: '1rem' }}>
<div>
<h2>Original Purchase</h2>
<p>Core Plan - {formatAmount(49, 'USD')}</p>
</div>
<div style={{ display: 'grid', gap: '0.5rem' }}>
{upsells.map((item, index) => (
<p key={`${item.name}-${index}`}>
Upsell purchase {index + 1}: {item.name} - {formatAmount(item.amount, item.currency)}
</p>
))}
</div>
<FloPayAutomaticPaymentButton
getSession={async ({ signal }) => {
// Your server mints the session with createOneClick for the signed-in buyer.
const response = await fetch('/api/upsell-session', { method: 'POST', signal });
return response.json(); // { sessionId, nonce }
}}
theme="bold-dark"
onSuccess={() => {
setUpsells((current) => [
...current,
{
name: upsellProduct.name,
amount: upsellProduct.totalAmount,
currency: upsellCurrency,
},
]);
}}
onDecline={(decline) => {
console.log('payment declined', decline.code);
}}
onError={(error) => {
console.error(error.message);
}}
>
{buttonLabel}
</FloPayAutomaticPaymentButton>
</section>
);
}Why This Pattern Works
- the page stays on the original success route instead of redirecting to a separate checkout screen
- the button gets FloPay's shared processing, success, and decline modal states automatically
- if authentication is required, the SDK opens the fallback
FloPayCheckoutmodal on the same page using the sametheme, so the upsell button and its recovery modal stay visually consistent - successful upsells can update your local React state immediately
Backend Picks The Saved Payment Method
FloPayAutomaticPaymentButton no longer needs paymentMethodId or checkoutMethod. The backend's auto-checkout branch now:
- resolves the customer's saved card, preferring the customer's preferred card, then the one used successfully most recently, then the newest
- chooses the gateway for this payment from current eligibility and your preference order, independently of where the card was first saved, then reuses or prepares that card's binding on the chosen account (see Gateway selection)
- builds the correct
tokenizedDatashape per provider ({ id: vaultToken }for Stripe,{ userPaymentMethodId: uuid }for PayPal)
Your server passes only the customer identity (account.userId) and the upsell line items to createOneClick; the backend takes care of the rest.
To let customers add, replace, or remove the methods they keep on file, without a purchase, see Save and manage payment methods.
Reusing A Session Created On Your Backend
If your backend creates the upsell session first, switch the button to sessionId mode. Forward the session's nonce alongside it: your backend returns it on the create response, and the SDK needs it to authenticate the session read and /process (omit it and current backends return 401 "Missing checkout session token."). The same theme still propagates to the fallback modal if authentication is required:
<FloPayAutomaticPaymentButton
sessionId={upsellSessionId}
nonce={upsellSessionNonce}
theme="bold-dark"
onSuccess={() => {
setUpsells((current) => [
...current,
{
name: 'AI Supercharger Pack',
amount: 80,
currency: 'USD',
},
]);
}}
>
Purchase Item
</FloPayAutomaticPaymentButton>