FloPayPaymentMethodSetup
Reference for the React component that lets a customer save a card, a wallet, PayPal, or a bank method without a purchase.
FloPayPaymentMethodSetup
FloPayPaymentMethodSetup renders every payment method a setup session advertises and saves the customer's choice without a purchase or a charge. It takes the sessionId and nonce of a setup session that your server created with POST /v1/checkouts/sessions/setup.
For the full server and browser workflow, see Save and manage payment methods.
Import
import { FloPayPaymentMethodSetup } from '@flopay/react/payment-method-setup';The @flopay/react/payment-method-setup entry loads a provider's script only when the session advertises one of that provider's methods. A session that advertises only a card requests no provider script at all. The component is also exported from @flopay/react, which suits a page that already renders FloPayCheckout.
The component is browser-only and does not need FloPayProvider.
Usage
import { FloPayPaymentMethodSetup } from '@flopay/react/payment-method-setup';
export function AddPaymentMethod({ sessionId, nonce }: { sessionId: string; nonce: string }) {
return (
<FloPayPaymentMethodSetup
sessionId={sessionId}
nonce={nonce}
onComplete={({ paymentMethod }) => {
// Verified by FloPay. `paymentMethod` is present for a card.
// List the customer's methods again from your server for every type.
console.log('Saved', paymentMethod?.brand ?? 'payment method');
}}
onDecline={({ message }) => console.warn(message)}
onError={(error) => console.error(error.code, error.retryable)}
onCancel={() => console.log('Setup closed before it finished')}
/>
);
}Props
| Prop | Type | Required | Description |
|---|---|---|---|
sessionId | string | Yes | Opaque id returned by the merchant-authenticated setup-session endpoint. |
nonce | string | Yes | Session-bound token returned alongside sessionId. |
billingApiUrl | string | No | Billing API base URL. Defaults to the configured FloPay environment URL. |
telemetry | boolean | No | Flo-owned privacy-safe telemetry. Enabled by default; set false to opt out. |
theme | ThemeId | VaultCardThemeColors | No | The same theme bundle FloPayCheckout resolves, or raw colors for the hosted card form. Defaults to 'modern-light'. |
containerStyle | React.CSSProperties | No | Inline styles for the hosted card-form container. |
loading | React.ReactNode | No | Content shown while the session and its methods load. |
onReady | () => void | No | Fired once the hosted card form has mounted and can accept card input. |
onComplete | (event: FloPayPaymentMethodSetupCompleteEvent) => void | No | Fired once, only after FloPay reports the method verified and usable. |
onDecline | (event: FloPayPaymentMethodSetupDeclineEvent) => void | No | Fired when verification terminally declines. Never paired with onComplete. |
onCancel | (event: FloPayPaymentMethodSetupCancelEvent) => void | No | Fired exactly once if the component unmounts before a terminal outcome. |
onValidation | (message: string | null) => void | No | Live validation message, or null when validation clears. |
onError | (error: FloPayCardSetupError) => void | No | Fired for session validation, transport, provider, or card-form failures. |
Events
| Event type | Shape |
|---|---|
FloPayPaymentMethodSetupCompleteEvent | { status: 'succeeded', sessionId, paymentMethod? }. paymentMethod carries the saved card's display fields (id, brand, lastFour, expiryMonth, expiryYear, status) for a card. It is absent for a wallet, PayPal, or a bank method. |
FloPayPaymentMethodSetupDeclineEvent | { status: 'declined', sessionId, reason?, message? } |
FloPayPaymentMethodSetupCancelEvent | { status: 'cancelled', sessionId } |
onComplete is FloPay's decision, not the provider's. After a wallet, PayPal, or a bank method is approved, the component reads the setup session again until FloPay reports it completed, and only then fires onComplete.
What the component renders
The setup session is the single source of truth. The component renders exactly the methods the session lists in advertisedPaymentMethods and nothing else. It does no gateway selection, filtering, or inference, and there is no prop that adds or removes a method.
Methods are laid out the way FloPayCheckout lays them out, using the same components:
- Wallets, such as Apple Pay and Google Pay.
- PayPal.
- One tile for each bank method. Pressing a tile opens that method's form and its
Savebutton. Pressing it again closes the form. - An
or add a cardrule. - FloPay's hosted card form.
A session that advertises only a card renders the hosted card form alone, with no rule above it, exactly like FloPayCardSetup.
Methods that are left out
A method the provider cannot offer in this browser is not drawn, and onError is not called:
- a wallet the device or browser does not have
- a method the provider does not support in the session currency, such as SEPA Direct Debit outside EUR
A bank method's tile appears only once the provider has confirmed that it can render the method. Only when no advertised method can be offered at all does onError receive payment_method_setup_unavailable.
Currency
Stripe wallets and bank methods are given the currency the setup session carries, never a guessed one. FloPay returns the currency it resolved for the customer, or the currency of the card gateway it selected when none was resolved. To offer a currency-bound method, send the customer's currency when your server creates the setup session.
Errors
onError receives a FloPayCardSetupError, which adds retryable to FloPayError. Keep the component mounted on a retryable error: the customer can try again, or choose another method.
| Code | Retryable | Meaning |
|---|---|---|
InvalidPaymentMethodSetupSession | No | The session is not a no-charge, product-free setup session. |
NoAdvertisedPaymentMethods | No | The session advertises no payment method, or only Stripe wallets or bank methods while it carries no currency. |
payment_method_setup_unavailable | No | None of the advertised methods can be offered in this browser. |
payment_method_setup_unverified | Yes | The provider accepted the method, but FloPay had not verified it in time. The method may still become active, so list the customer's methods again from your server. |
payment_method_setup_expired | No | The setup session expired before the method was verified. Create a new session. |
payment_method_setup_failed | Yes | A wallet or bank method failed technically. |
payment_method_setup_provider_failed | Yes | The provider reported a technical failure while saving the method. |
payment_method_setup_load_failed | While another method is usable | The code for a wallet, a bank method, or PayPal could not be loaded, or failed while rendering. That method is removed and the others stay usable. |
paypal_setup_failed | Yes | The PayPal flow failed technically. |
popup_blocked | Yes | PayPal could not open its approval window. Allow pop-ups and retry. |
card_setup_widget_failed | Yes | The hosted card form failed at runtime. |
card_setup_load_failed | Depends on the cause | Loading the session or the card form failed. |
A failing wallet, bank method, or PayPal never takes the card form down. The failed method is removed, the others stay mounted, and the error is retryable: true while another advertised method is still usable.
Returning from a provider redirect
Some methods send the customer to the provider and back to the same page. To finish that setup, mount the component again with the same sessionId and nonce when the customer returns. It reads the provider's return parameters from the URL, removes them, and resolves the outcome through the same callbacks: a completed session fires onComplete, and a failed return fires onDecline.
Keep the open setup's sessionId and nonce somewhere that survives the navigation, such as the tab's session storage, and mount the component from them on return.
Wording
The outcome overlay reads SAVING CARD..., CARD SAVED, and CARD NOT SAVED for a card, and SAVING PAYMENT METHOD..., PAYMENT METHOD SAVED, and PAYMENT METHOD NOT SAVED for every other method.
Each rendered method sits in a wrapper with a data-flopay-payment-method attribute naming the method, such as card, apple_pay, or paypal. Use it in your own tests to check which methods a session offered.
Related
- Save and manage payment methods: the full workflow, including consent, listing, replacing, and removing.
- Payment methods REST reference: the setup-session, list, and delete contracts.
FloPayCheckout: the purchase component.