UNPKG

autumn-js

Version:
81 lines (78 loc) 2.92 kB
import { UseCustomerParams, UseCustomerResult } from './useCustomerBase.js'; import '../error-DHbclCVh.js'; import '../genTypes-CY6GNiAn.js'; import '../prodTypes-C4aZSZfO.js'; import 'zod/v4'; import '../attachTypes-CKp1KMwX.js'; import '../entTypes-n2T2wpRx.js'; import '../cusTypes-D3QQXjif.js'; import '../ReactAutumnClient-DkAcY1X2.js'; import 'react'; import 'swr'; import '../client/types/clientAttachTypes.js'; import '../client/types/clientGenTypes.js'; import '../client/ConvexAutumnClient.js'; import '../client/types/clientEntTypes.js'; import '../client/types/clientReferralTypes.js'; /** * React hook for managing customer billing, subscriptions, and feature access. * * Provides access to all Autumn billing functions including product attachment, * subscription management, usage tracking, and feature gating. Automatically * handles customer data fetching and caching. * * @param params - Optional configuration for the hook * @returns Object containing customer data and billing functions * * @example * ```tsx * import { useCustomer } from "autumn-js/react"; * * function MyComponent() { * const { * customer, * isLoading, * attach, * cancel, * check, * track, * checkout, * openBillingPortal, * setupPayment, * createReferralCode, * redeemReferralCode, * createEntity, * refetch * } = useCustomer(); * * return ( * <div> * <button onClick={() => attach({ productId: "pro" })}> * Upgrade to Pro * </button> * <button onClick={() => cancel({ productId: "pro" })}> * Cancel Subscription * </button> * </div> * ); * } * ``` * * @returns {Object} Hook result object * @returns {Customer | null} returns.customer - Current customer data with subscription info * @returns {boolean} returns.isLoading - Whether customer data is loading * @returns {AutumnError | null} returns.error - Any error from customer data fetching * @returns {Function} returns.attach - Attach product to customer with billing * @returns {Function} returns.cancel - Cancel customer subscription/product * @returns {Function} returns.check - Check feature access and show paywalls * @returns {Function} returns.track - Track feature usage events * @returns {Function} returns.checkout - Initiate product checkout flow * @returns {Function} returns.openBillingPortal - Open Stripe billing portal * @returns {Function} returns.setupPayment - Setup payment method * @returns {Function} returns.createReferralCode - Create referral codes * @returns {Function} returns.redeemReferralCode - Redeem referral codes * @returns {Function} returns.createEntity - Create entities for granular tracking * @returns {Function} returns.refetch - Manually refetch customer data */ declare const useCustomer: (params?: UseCustomerParams) => UseCustomerResult; export { useCustomer };