> ## Documentation Index
> Fetch the complete documentation index at: https://better-auth-razorpay.amankushwaha.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Resource hooks

> Query and mutate Razorpay payments, orders, refunds, invoices, items, add-ons, customers, and transfers with TanStack Query hooks.

The resource hooks let you work with Razorpay entities from React components. Query hooks fetch data and cache it through TanStack Query. Mutation hooks wrap create, update, and delete actions, and they invalidate related query keys on success.

## Payment hooks

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayPaymentList` | `(authClient, query?)` | Paginated list of payments |
| `useRazorpayPayment` | `(authClient, paymentId)` | Single payment details |

### Payment list example

```tsx theme={null}
"use client";

import { useRazorpayPaymentList } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function PaymentHistory() {
  const { data, isLoading } = useRazorpayPaymentList(authClient, {
    count: 20,
    skip: 0,
  });

  if (isLoading) return <p>Loading payments...</p>;

  return (
    <ul>
      {data?.items?.map((payment) => (
        <li key={payment.id}>
          {payment.id} — {(payment.amount / 100).toFixed(2)} {payment.currency} — {payment.status}
        </li>
      ))}
    </ul>
  );
}
```

## Order hooks

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayOrderList` | `(authClient, query?)` | Paginated list of orders |
| `useRazorpayOrderPayments` | `(authClient, orderId)` | Payments for a specific order |

### Order payments example

```tsx theme={null}
"use client";

import { useRazorpayOrderPayments } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function OrderPayments({ orderId }: { orderId: string }) {
  const { data, isLoading } = useRazorpayOrderPayments(authClient, orderId);

  if (isLoading) return <p>Loading...</p>;

  return (
    <ul>
      {data?.items?.map((payment) => (
        <li key={payment.id}>{payment.id} — {payment.status}</li>
      ))}
    </ul>
  );
}
```

## Refund hooks

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayRefundList` | `(authClient, query?)` | Paginated list of refunds |
| `useRazorpayRefund` | `(authClient, refundId, { paymentId? })` | Single refund details |
| `useEditRefund` | `(authClient, { mutationOptions? })` | Mutation to edit refund notes |

### Refund list example

```tsx theme={null}
"use client";

import { useRazorpayRefundList, useEditRefund } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function RefundManager() {
  const { data, isLoading } = useRazorpayRefundList(authClient, { count: 10 });
  const edit = useEditRefund(authClient);

  if (isLoading) return <p>Loading refunds...</p>;

  return (
    <ul>
      {data?.items?.map((refund) => (
        <li key={refund.id} style={{ marginBottom: 8 }}>
          {refund.id} — {(refund.amount / 100).toFixed(2)} {refund.currency} — {refund.status}
          <button
            onClick={() => edit.mutate({ refundId: refund.id, notes: { reason: "updated" } })}
            disabled={edit.isPending}
          >
            Edit notes
          </button>
        </li>
      ))}
    </ul>
  );
}
```

## Invoice hooks

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayInvoiceList` | `(authClient, query?)` | Paginated list of invoices |
| `useRazorpayInvoice` | `(authClient, invoiceId)` | Single invoice details |
| `useCreateInvoice` | `(authClient, { mutationOptions? })` | Mutation to create an invoice |
| `useEditInvoice` | `(authClient, { mutationOptions? })` | Mutation to edit a draft invoice |
| `useIssueInvoice` | `(authClient, { mutationOptions? })` | Mutation to issue a draft invoice |
| `useDeleteInvoice` | `(authClient, { mutationOptions? })` | Mutation to delete a draft invoice |
| `useCancelInvoice` | `(authClient, { mutationOptions? })` | Mutation to cancel an issued invoice |
| `useNotifyByInvoice` | `(authClient, { mutationOptions? })` | Mutation to notify by email or SMS |

### Invoice creation example

```tsx theme={null}
"use client";

import { useCreateInvoice, useRazorpayInvoiceList } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function InvoiceCreator() {
  const { data: invoices, isLoading } = useRazorpayInvoiceList(authClient, { count: 10 });
  const create = useCreateInvoice(authClient);

  const handleCreate = () => {
    create.mutate({
      type: "invoice",
      description: "Monthly retainer",
      customer: {
        name: "Acme Inc",
        email: "billing@acme.com",
        contact: "+919000090000",
      },
      line_items: [
        { name: "Consulting", amount: 50000, currency: "INR", quantity: 1 },
      ],
      currency: "INR",
      sms_notify: true,
      email_notify: true,
    });
  };

  return (
    <div>
      <button onClick={handleCreate} disabled={create.isPending}>
        {create.isPending ? "Creating..." : "Create invoice"}
      </button>

      {isLoading ? <p>Loading...</p> : (
        <ul>
          {invoices?.items?.map((inv) => (
            <li key={inv.id}>{inv.id} — {inv.status}</li>
          ))}
        </ul>
      )}
    </div>
  );
}
```

## Add-on hooks

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayAddonList` | `(authClient, query?)` | Paginated list of add-ons |
| `useRazorpayAddon` | `(authClient, addonId)` | Single add-on details |
| `useCreateSubscriptionAddon` | `(authClient, { mutationOptions? })` | Mutation to add an add-on to a subscription |
| `useDeleteAddon` | `(authClient, { mutationOptions? })` | Mutation to delete an add-on |

### Add-on example

```tsx theme={null}
"use client";

import { useRazorpayAddonList, useCreateSubscriptionAddon } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function AddonManager({ subscriptionId }: { subscriptionId: string }) {
  const { data } = useRazorpayAddonList(authClient);
  const addAddon = useCreateSubscriptionAddon(authClient);

  return (
    <ul>
      {data?.items?.map((addon) => (
        <li key={addon.id}>
          {addon.item?.name} — {(addon.item?.amount / 100).toFixed(2)} {addon.item?.currency}
          <button
            onClick={() =>
              addAddon.mutate({
                subscriptionId,
                item: { id: addon.item?.id },
                quantity: 1,
              })
            }
            disabled={addAddon.isPending}
          >
            Add to subscription
          </button>
        </li>
      ))}
    </ul>
  );
}
```

## Item hooks

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayItemList` | `(authClient, query?)` | Paginated list of items |
| `useRazorpayItem` | `(authClient, itemId)` | Single item details |
| `useCreateItem` | `(authClient, { mutationOptions? })` | Mutation to create an item |
| `useEditItem` | `(authClient, { mutationOptions? })` | Mutation to edit an item |
| `useDeleteItem` | `(authClient, { mutationOptions? })` | Mutation to delete an item |

### Item management example

```tsx theme={null}
"use client";

import { useRazorpayItemList, useCreateItem, useDeleteItem } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function ItemManager() {
  const { data, isLoading } = useRazorpayItemList(authClient, { active: 1 });
  const create = useCreateItem(authClient);
  const remove = useDeleteItem(authClient);

  const handleCreate = () => {
    create.mutate({
      name: "Pro seat",
      amount: 29900,
      currency: "INR",
      description: "Monthly pro seat",
    });
  };

  return (
    <div>
      <button onClick={handleCreate} disabled={create.isPending}>
        {create.isPending ? "Creating..." : "Create item"}
      </button>

      {isLoading ? <p>Loading...</p> : (
        <ul>
          {data?.items?.map((item) => (
            <li key={item.id}>
              {item.name} — {(item.amount / 100).toFixed(2)} {item.currency}
              <button
                onClick={() => remove.mutate({ itemId: item.id })}
                disabled={remove.isPending}
              >
                Delete
              </button>
            </li>
          ))}
        </ul>
      )}
    </div>
  );
}
```

## Customer, token, and bank account hooks

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayCustomerTokens` | `(authClient, customerId)` | Tokens for a customer |
| `useRazorpayCustomerToken` | `(authClient, customerId, tokenId)` | Single token details |
| `useAddBankAccount` | `(authClient, { mutationOptions? })` | Mutation to add a bank account |
| `useDeleteBankAccount` | `(authClient, { mutationOptions? })` | Mutation to delete a bank account |
| `useDeleteToken` | `(authClient, { mutationOptions? })` | Mutation to delete a token |

### Bank account example

```tsx theme={null}
"use client";

import { useAddBankAccount, useDeleteBankAccount, useRazorpayCustomerTokens } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function CustomerBankAccounts({ customerId }: { customerId: string }) {
  const { data } = useRazorpayCustomerTokens(authClient, customerId);
  const add = useAddBankAccount(authClient);
  const remove = useDeleteBankAccount(authClient);

  const handleAdd = () => {
    add.mutate({
      customerId,
      ifsc_code: "HDFC0000123",
      account_number: "123456789012",
      beneficiary_name: "Aman Kushwaha",
    });
  };

  return (
    <div>
      <button onClick={handleAdd} disabled={add.isPending}>
        {add.isPending ? "Adding..." : "Add bank account"}
      </button>
      <ul>
        {data?.items?.map((token) => (
          <li key={token.id}>
            {token.id} — {token.method}
            <button
              onClick={() => remove.mutate({ customerId, bankAccountId: token.id })}
              disabled={remove.isPending}
            >
              Remove
            </button>
          </li>
        ))}
      </ul>
    </div>
  );
}
```

## Transfer hooks (Razorpay Route)

| Hook | Signature | Returns |
| - | - | - |
| `useRazorpayTransfer` | `(authClient, transferId)` | Single transfer details |
| `useRazorpayTransferList` | `(authClient, { paymentId?, limit?, from?, to? })` | Paginated list of transfers |
| `useCreateTransfer` | `(authClient, { mutationOptions? })` | Mutation to create transfers |
| `useEditTransfer` | `(authClient, { mutationOptions? })` | Mutation to edit a transfer |
| `useReverseTransfer` | `(authClient, { mutationOptions? })` | Mutation to reverse a transfer |

### Transfer list example

```tsx theme={null}
"use client";

import { useRazorpayTransferList, useCreateTransfer } from "@amank-root/better-auth-razorpay/react";
import { authClient } from "@/lib/auth-client";

export function TransferDashboard({ paymentId }: { paymentId: string }) {
  const { data, isLoading } = useRazorpayTransferList(authClient, { paymentId, limit: 20 });
  const create = useCreateTransfer(authClient);

  const handleCreate = () => {
    create.mutate({
      paymentId,
      transfers: [
        {
          account: "acc_XXXX",
          amount: 25000,
          currency: "INR",
          notes: { reason: "vendor payout" },
        },
      ],
    });
  };

  return (
    <div>
      <button onClick={handleCreate} disabled={create.isPending}>
        {create.isPending ? "Creating..." : "Create transfer"}
      </button>

      {isLoading ? <p>Loading transfers...</p> : (
        <ul>
          {data?.items?.map((transfer) => (
            <li key={transfer.id}>
              {transfer.id} — {(transfer.amount / 100).toFixed(2)} {transfer.currency} — {transfer.status}
            </li>
          ))}
        </ul>
      )}
    </div>
  );
}
```

> [!NOTE]
>
> Transfer endpoints require Razorpay Route to be enabled on your account. If Route is not active, transfer creation will fail with a Razorpay error.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.