Skip to main content
Razorpay plans define the billing interval, amount, and item details for subscriptions. The better-auth-razorpay plugin lets you create plans programmatically, list existing ones, and reference them in your subscription configuration.

Create a plan

Call auth.api.createPlan from the server to create a new Razorpay plan. This is typically an admin-only operation. Validate the caller’s role before invoking the endpoint.
app/api/admin/plans/route.ts
string
required
Billing frequency: "daily", "weekly", "monthly", "quarterly", or "yearly".
number
required
Interval count. For example, 1 with "monthly" means every month; 3 means every 3 months.
string
required
Display name for the plan item.
number
required
Amount in currency subunits (paise for INR).
string
default:"INR"
3-character ISO currency code.
string
Optional description for the plan item.
object
Up to 15 key-value pairs stored with the plan.
Plan creation is an admin operation. Always verify the caller’s permissions on the server before creating plans, because the endpoint does not enforce role checks internally.

List plans

Fetch all plans from your Razorpay account.

Fetch a single plan

Retrieve a specific plan by its Razorpay ID.

Use a created plan in plugin config

After creating a plan in Razorpay, copy its id into the plugin’s subscription.plans array so users can subscribe to it.
auth.ts
The name field is matched case-insensitively when users call authClient.subscription.upgrade({ plan: "pro" }). The plugin stores the plan name lowercased in the database.

Dynamic plans

If your application supports plan creation from an admin dashboard, you can fetch the latest plans from Razorpay at runtime and use them to populate your pricing page or plugin configuration.
app/admin/plans/page.tsx

React hook: useRazorpayPlans

useRazorpayPlans fetches the full list of Razorpay plans and caches it with TanStack Query. You can pass queryOptions to customize caching behavior.

Common errors