FloPay
API Reference@flopay/react

CheckoutForm

Drop-in checkout form component that handles the full payment lifecycle.

CheckoutForm

Drop-in checkout form that handles the full payment lifecycle by default. Renders a PaymentElement, optional AddressElement, error display, and a submit button.

const CheckoutForm: React.ForwardRefExoticComponent<
  CheckoutFormProps & React.RefAttributes<CheckoutFormRef>
>

Modes

  • Self-contained mode (default): Provide sessionId, billingApiUrl, email, userId, and onComplete. The form handles tokenization, intent creation, confirmation, 3DS, and backend submission automatically.
  • Override mode: Provide onTokenizedBody to handle backend submission yourself. The form tokenizes and confirms the payment, then delegates the final step to your callback.

Props

NameTypeRequiredDefaultDescription
sessionIdstringYes--Checkout session ID (UUID from billing API).
billingApiUrlstringYes--Billing API base URL.
emailstringNo--User's email (required for creating payment intents).
userIdstringNo--User ID (required for processing payments).
onComplete(result: PaymentResult) => voidNo--Called when payment completes successfully.
onError(error: FloPayError) => voidNo--Called when a payment error occurs.
onTokenizedBody(tokenizedBody: TokenizedBody) => voidNo--Override: delegates backend submission to the caller.
layout'tabs' | 'accordion' | 'auto'No'auto'Layout style for the PaymentElement.
submitLabelstringNo'Pay'Label for the submit button.
showAddressboolean | 'billing' | 'shipping'NofalseWhether to show an address element. true defaults to 'billing'.
classNamestringNo--Additional CSS class for the form wrapper.
childrenReact.ReactNodeNo--Custom children (e.g. a custom submit button). Overrides the default button.
firstNamestringNo--First name for billing.
lastNamestringNo--Last name for billing.
chvstringNo--Checkout version for A/B tracking.
isProcessingbooleanNo--External processing state (used with onTokenizedBody).
errorstring | nullNo--External error message (used with onTokenizedBody).
onErrorChange(error: string | null) => voidNo--Called when internal error state changes.

CheckoutFormRef

Methods exposed via ref for external 3DS handling.

MethodSignatureDescription
handleNextAction(clientSecret: string) => Promise<void>Trigger 3DS authentication with the given client secret. On success, dispatches the tokenized body.

Self-Contained Example

<CheckoutForm
  sessionId="uuid-xxx"
  billingApiUrl="https://api.example.com"
  email="user@example.com"
  userId="user_1"
  onComplete={(result) => router.push('/success')}
  onError={(err) => console.error(err)}
/>

Override Example

const formRef = useRef<CheckoutFormRef>(null);
 
<CheckoutForm
  ref={formRef}
  sessionId="uuid-xxx"
  billingApiUrl="https://api.example.com"
  email="user@example.com"
  onTokenizedBody={(body) => {
    myCustomProcessPayment(body).then((res) => {
      if (res.requires3DS) {
        formRef.current?.handleNextAction(res.clientSecret);
      }
    });
  }}
  isProcessing={loading}
  error={errorMsg}
/>

Internal Flow

  1. Validate elements via submitElements()
  2. Tokenize card via createPaymentMethod()
  3. Create PaymentIntent via POST /v1/checkouts/payments/intents
  4. Confirm card payment (handles 3DS automatically)
  5. Submit token to POST /v1/checkouts/sessions/process
  6. Handle 3ds_required responses with re-confirmation
  7. Resume wallet payments after redirect (PayPal, etc.)

On this page