supastarter for Next.jsPayments
Check for purchases or subscriptions
Learn how to check for purchases or subscriptions in your application to provide access to premium features.
One of the most common use cases for payments is to provide access to premium features.
Plan ID
The plan id is used to identify a plan. It is defined in the key property of the plan object from the config file like free
, pro
, enterprise
or lifetime
from the example config.
Check for purchases or subscriptions on client side
You can check if a user has a purchase or subscription by using the usePurchases
hook.
The usePurchases
hook returns the following properties:
activePlan
: The active plan of the userpurchases
: An array of all the purchases of the userhasSubscription
: A function to check if the user has an active subscription. Optionally takes a plan id or an array of plan ids as argument to check for specific plans.hasPurchase
: A function to check if the user has a specifc purchase for a given plan id
Check for purchases on server side
You can also check for purchases and get the active plan on the server side by using the getPurchases
function.
Check for purchases of organization
Both usePurchases
and getPurchases
also support organizations. Simply pass the organization id as an argument.