Skip to main content
This guide shows you how to accept one-time payments using the better-auth-razorpay plugin. You will create a Razorpay order from your server, render Razorpay Checkout on the client, verify the payment signature, and fulfill the purchase using the order.paid webhook.
1

Create a Razorpay order

On the server, call authClient.razorpay.createOrder or auth.api.createRazorpayOrder to create a Razorpay order. The amount must be an integer in the smallest currency unit (paise for INR). The minimum amount for INR is 100 (₹1).
server.ts
The response is a Razorpay order object containing id, amount, currency, receipt, status, and other fields.
2

Collect payment with Razorpay Checkout

On the client, load Razorpay Checkout and pass the order_id returned from the server. After the user completes payment, the handler callback receives razorpay_order_id, razorpay_payment_id, and razorpay_signature.
checkout.tsx
3

Verify the payment on the server

The verifyPayment endpoint checks the payment signature, confirms the payment is captured, and optionally validates the amount. Call it from the client as shown above, or directly on the server.
server-verify.ts
The response contains:
boolean
True only when the signature is valid, the payment is captured, the order matches, and the expected amount matches (if provided).
string
The Razorpay payment status, for example “captured”.
string
One of: invalid_signature, order_mismatch, amount_mismatch, or payment_not_captured. Only present when valid is false.
4

Fulfill on the order.paid webhook

Client-side verification helps the UI respond quickly, but you should treat the order.paid webhook as the source of truth for fulfillment. Configure the plugin’s onOrderPaid callback to deliver purchases, update inventory, or send confirmation emails.
auth.ts

Partial payments

You can allow customers to pay an order in multiple installments by enabling partialPayment and setting firstPaymentMinAmount.
firstPaymentMinAmount requires partialPayment: true. Without it, the server returns INVALID_PARTIAL_PAYMENT.

Guest checkout (requireSession: false)

If you want to accept payments from users who are not signed in, set requireSession: false in the plugin options. This removes the session middleware from one-time payment and transfer endpoints.
auth.ts
Disabling session requirements means anyone can call createOrder and other payment endpoints. Protect your business logic by validating the request payload, rate-limiting, and verifying payments on the server before fulfillment.

Listing orders and payments

Use the list and fetch endpoints to manage orders and payments from your dashboard or admin panel.

Error handling

Common errors you may encounter: