Documentation
Technical ReferenceReact SDK

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

PropTypeRequiredDescription
sessionIdstringYesOpaque id returned by the merchant-authenticated setup-session endpoint.
noncestringYesSession-bound token returned alongside sessionId.
billingApiUrlstringNoBilling API base URL. Defaults to the configured FloPay environment URL.
telemetrybooleanNoFlo-owned privacy-safe telemetry. Enabled by default; set false to opt out.
themeThemeId | VaultCardThemeColorsNoThe same theme bundle FloPayCheckout resolves, or raw colors for the hosted card form. Defaults to 'modern-light'.
containerStyleReact.CSSPropertiesNoInline styles for the hosted card-form container.
loadingReact.ReactNodeNoContent shown while the session and its methods load.
onReady() => voidNoFired once the hosted card form has mounted and can accept card input.
onComplete(event: FloPayPaymentMethodSetupCompleteEvent) => voidNoFired once, only after FloPay reports the method verified and usable.
onDecline(event: FloPayPaymentMethodSetupDeclineEvent) => voidNoFired when verification terminally declines. Never paired with onComplete.
onCancel(event: FloPayPaymentMethodSetupCancelEvent) => voidNoFired exactly once if the component unmounts before a terminal outcome.
onValidation(message: string | null) => voidNoLive validation message, or null when validation clears.
onError(error: FloPayCardSetupError) => voidNoFired for session validation, transport, provider, or card-form failures.

Events

Event typeShape
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:

  1. Wallets, such as Apple Pay and Google Pay.
  2. PayPal.
  3. One tile for each bank method. Pressing a tile opens that method's form and its Save button. Pressing it again closes the form.
  4. An or add a card rule.
  5. 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.

CodeRetryableMeaning
InvalidPaymentMethodSetupSessionNoThe session is not a no-charge, product-free setup session.
NoAdvertisedPaymentMethodsNoThe session advertises no payment method, or only Stripe wallets or bank methods while it carries no currency.
payment_method_setup_unavailableNoNone of the advertised methods can be offered in this browser.
payment_method_setup_unverifiedYesThe 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_expiredNoThe setup session expired before the method was verified. Create a new session.
payment_method_setup_failedYesA wallet or bank method failed technically.
payment_method_setup_provider_failedYesThe provider reported a technical failure while saving the method.
payment_method_setup_load_failedWhile another method is usableThe 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_failedYesThe PayPal flow failed technically.
popup_blockedYesPayPal could not open its approval window. Allow pop-ups and retry.
card_setup_widget_failedYesThe hosted card form failed at runtime.
card_setup_load_failedDepends on the causeLoading 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.

On this page