FloPayFloPay
API Reference@flopay/react

Hooks

React hooks for accessing FloPay SDK instances and checkout state.

useFloPay

Returns the current FloPay instance, or null if the provider is still loading (i.e. the loadFloPay() promise has not resolved yet).

function useFloPay(): FloPay | null

Must be called within a <FloPayProvider>.

Returns: FloPay | null

import { useFloPay } from '@flopay/react';

function RefreshSessionButton({ sessionId }: { sessionId: string }) {
  const flopay = useFloPay();

  const handleRefresh = async () => {
    if (!flopay) return;
    const session = await flopay.retrieveSession(sessionId);
    console.log(session.status);
  };

  return <button onClick={handleRefresh} disabled={!flopay}>Refresh session</button>;
}

useCheckout

Returns the current checkout session state. Must be called within the checkout context rendered by <FloPayCheckout>.

function useCheckout(): CheckoutState

CheckoutState

PropertyTypeDescription
sessionCheckoutSession | nullThe current checkout session, or null if not yet loaded.
loadingbooleanWhether the session is being fetched.
errorFloPayError | nullError that occurred during session retrieval.

Returns: CheckoutState

import { useCheckout } from '@flopay/react';

function OrderSummary() {
  const { session, loading, error } = useCheckout();

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error.message}</div>;
  if (!session) return null;

  return (
    <div>
      Total: {session.amount} {session.currency}
    </div>
  );
}

On this page