useCustomer
hook provides access to customer data and related operations. You can use it from your frontend to retrieve customer information, manage loading states, and create entities.
To use Autumn’s React hooks, you should set up the
autumnHandler
in your
backend and the <AutumnProvider />
in your frontend, as described in the
quickstart guide. This gives the hooks
access to the customerId making the request.Parameters
Array of additional data to include in the customer response. Options include
invoices
, rewards
, trials_used
, entities
, referrals
, payment_method
.customer
The customer object containing all customer data.
checkout()
Opens a checkout URL for the user to make a payment.
If the payment method already exists, purchase confirmation data will be returned.
If a dialog
is passed in, a payment confirmation dialog (CheckoutDialog
) will be opened.
The ID of the product being enabled.
A dialog that pops up to confirm the purchase (eg, for upgrades/downgrades).
See the billing flows page.
The ID of the entity (eg, user seat) to attach the product to.
Array of feature options to configure for the attachment. Each option contains
featureId
(string) and quantity
(number).Array of additional product IDs to attach simultaneously.
Whether to disable free trials for this product. Only applicable if the
product has a free trial.
URL to redirect to after successful attachment/checkout.
Additional metadata to pass onto Stripe.
Pass in Stripe checkout session fields and they will be forwarded on.
Whether to force the checkout flow even if the payment method already exists.
Not available for upgrades/downgrades.
Whether to open the checkout URL in a new tab.
attach()
Enables a product for a customer and handles a payment. Typically used after the checkout
function.
If the payment method is not on file, this function will also return a Checkout URL.
The ID of the product to attach.
The ID of the entity (eg, user seat) to attach the product to.
Array of feature options to configure for the attachment. Each option contains
featureId
(string) and quantity
(number).Array of additional product IDs to attach simultaneously.
Whether to disable free trials for this product. Only applicable if the
product has a free trial.
URL to redirect to after successful attachment/checkout.
Additional metadata to pass onto Stripe.
Whether to force the checkout flow even if the payment method already exists.
Not available for upgrades/downgrades.
Whether to open the checkout URL in a new tab.
check()
Check if a user has access to a specific feature or product.
This will be read from the local
customer
state object, so no API call to
Autumn is made. This should be combined with a backend check
call for
security.The ID of the feature to check access for.
The ID of the product to check access for.
A dialog that pops up to act as a paywall (eg, when a feature runs out). See
the billing flows page.
The ID of the entity (customer/user) to check access for.
The required balance/usage amount to check against.
Whether to send an event when checking access.
Return preview data to display to the user. Using this with a
featureID
will
return paywall data, and using it with a productId
will return
upgrade/downgrade data.track()
Track usage events for features or analytics.
Tracking usage client-side is not recommended, as a user in theory could stop
script execution and mess with your tracking data.
The ID of the feature to track usage for.
Custom event name for tracking.
The ID of the entity (customer/user) to track usage for.
The value/quantity to track (e.g., number of API calls, storage used).
Unique key to prevent duplicate tracking events.
openBillingPortal()
Open the billing portal for customers to manage their subscriptions, payment methods, and billing information.
URL to redirect to when the customer exits the billing portal.
cancel()
Cancel a product or subscription for a user/entity.
The ID of the product to cancel.
Whether to cancel the product immediately. If false, the product will be
cancelled at the end of the billing cycle.
The ID of the entity (customer/user) to cancel the product for.
refetch
Function to manually refetch the customer
data, eg when updating a customer’s usage or balance to display.
createEntity
Function to create one or more entities for the customer.
The ID of the entity to create.
Display name for the entity.
The feature ID for the entity being created. Must be a
continuous_use
feature.