useCustomer hook fetches customer data and provides billing actions like attaching plans and checking feature access.
Parameters
Whether to throw an error if the customer is not found. Defaults to
false.Array of additional data to include in the response. Options:
invoices, trials_used, rewards, entities, referrals, payment_method, subscriptions.plan, purchases.plan, balances.feature.Optional TanStack Query options to customize caching and refetching behavior.
Returns
data
The customer object containing subscriptions, purchases, and balances.
attach()
Attaches a plan to the customer. Handles new subscriptions, upgrades, and downgrades. Automatically redirects to checkout if payment is required.
The ID of the plan to attach.
URL to redirect to after successful checkout.
Open checkout URL in a new tab instead of redirecting.
check()
Checks feature access and balance for the customer locally (no API call).
This reads from the local
data state. Combine with a backend check call for security.The ID of the feature to check access for.
The ID of the entity to check access for.
The required balance amount to check against.
openCustomerPortal()
Opens the Stripe customer billing portal for managing subscriptions and payment methods.
URL to redirect to when the customer exits the billing portal.
Open portal in a new tab instead of redirecting.