The `better-auth-razorpay` package provides a robust and type-safe integration of Razorpay payment functionalities into applications utilizing `better-auth`. As of version 2.0.7, it offers comprehensive support for the full Razorpay subscription lifecycle, including creation, upgrades, cancellations, pauses, and resumptions, alongside features like trial abuse prevention and automatic customer synchronization with user details. It caters to various billing models, including organization and seat-based billing, and provides secure, HMAC-SHA256 verified webhook processing for all critical Razorpay events. The plugin also ships with pre-built React hooks leveraging TanStack Query for seamless client-side integration and boasts end-to-end TypeScript coverage, ensuring type safety across its API. While a specific release cadence isn't published, it aligns with `better-auth` ecosystem updates and feature-driven development, often introducing new capabilities or refinements.
npm install better-auth-razorpayVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to initialize the `better-auth-razorpay` plugin on the server, configure the Razorpay client, set up webhooks, and define subscription plans with lifecycle callbacks.
Consult the `better-auth-razorpay` GitHub repository for specific migration instructions or breaking changes documentation associated with your target version.
Ensure `razorpayWebhookSecret` matches the secret configured in your Razorpay dashboard exactly. Store this secret securely in environment variables and never hardcode it.
Use a robust environment variable management system (e.g., `.env` files, cloud secrets managers) to inject these sensitive values at runtime. Never embed them directly in your codebase.
Carefully review the required webhook events in the `better-auth-razorpay` documentation and ensure all specified events are enabled and correctly configured in your Razorpay dashboard for the registered webhook URL.
Always use `import { razorpay } from 'better-auth-razorpay';` for server-side `betterAuth` configuration and `import { razorpayClient } from 'better-auth-razorpay/client';` for client-side `createAuthClient` configuration.Ensure `process.env.RAZORPAY_WEBHOOK_SECRET` exactly matches the secret in your Razorpay dashboard. If using a web framework like Express, ensure you are using `express.raw()` or similar middleware for the webhook endpoint to capture the raw request body before parsing.
Double-check all `planId` values in your `better-auth-razorpay` server-side configuration against active plans in your Razorpay dashboard. Ensure the `name` property for each plan is unique and correctly corresponds to the Razorpay `planId`.
Verify that `razorpay({...})` is included in the `plugins` array for `betterAuth` on the server, and `razorpayClient({...})` is included in the `plugins` array for `createAuthClient` on the client. Ensure all required configuration options are provided to the plugin.Ensure you are using the correct import statement: `import { razorpayClient } from 'better-auth-razorpay/client';`. If the issue persists, check your `tsconfig.json` for appropriate `moduleResolution` settings and ensure the package is correctly installed.