Skip to main content
The Razorpay plugin supports organization-level subscriptions when you enable the Better Auth organization() plugin. This lets you bill teams instead of individual users, sync seat quantities as members join or leave, and manage a dedicated Razorpay customer per organization.
1

Enable the organization plugin on the server

Import organization from better-auth/plugins and add it to your betterAuth plugins array before razorpay.
auth.ts
2

Enable the organization client plugin

Import organizationClient from better-auth/client/plugins and add it to your client plugins.
client.ts
3

Define authorizeReference

Organization subscriptions require subscription.authorizeReference. This callback receives the user, session, reference id, and action. Return true to allow the action, or false to deny it.The example below uses a helper you define against your own database. Replace getMemberRole with your actual membership lookup.
auth.ts

Organization plugin options

boolean
required
Must be true to enable organization support.
function
Async function that receives (organization, ctx) and returns partial Razorpay customer create params. Use this to attach custom notes or set a display name.
function
Callback invoked after a Razorpay customer is created for an organization. Receives ({ razorpayCustomer, organization }, ctx).

Upgrading and managing organization subscriptions

From the client, pass customerType: "organization" and optionally referenceId (the organization id). If you omit referenceId, the plugin uses the active organization from the session.

Built-in sync hooks

When organization support is enabled, the plugin automatically keeps Razorpay customer data in sync and protects against invalid operations:
  • Organization name update: changing the organization name updates the linked Razorpay customer name.
  • Member add / remove / invitation accept: on quantity-based plans, the plugin recalculates seat quantity and updates the Razorpay subscription to match the current member count.
  • Organization deletion guard: deleting an organization that has an active subscription is blocked.

Error codes

Always define authorizeReference when using organization subscriptions. Without it, the plugin returns AUTHORIZE_REFERENCE_REQUIRED and blocks subscription operations.