> ## 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.

# Manual capture

> Hold authorized funds and capture payments manually after verifying inventory or business rules.

Manual capture lets you authorize a payment from the customer first and capture it later after your server confirms inventory, fraud checks, or other business rules. This guide shows you how to create orders with `paymentCapture: false`, handle the `payment.authorized` webhook, and call the capture endpoint when you are ready.

**1. Create an order with paymentCapture disabled**

Pass `paymentCapture: false` when creating the order. Razorpay will authorize the customer's funds but will not automatically capture them.

```ts server.ts theme={null}
import { auth } from "./auth";

const { data: order, error } = await auth.api.createRazorpayOrder({
  body: {
    amount: 75000,           // ₹750
    currency: "INR",
    receipt: "rcpt_manual_01",
    paymentCapture: false,
  },
  headers: req.headers,
});
```

**2. Collect payment with Razorpay Checkout**

The client flow is the same as a normal one-time payment. The customer completes Checkout and the payment enters an `authorized` state instead of `captured`.

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

import { useState } from "react";
import { authClient } from "./auth-client";

export function ManualCaptureCheckout() {
  const [loading, setLoading] = useState(false);

  async function pay() {
    setLoading(true);
    const { data: order, error } = await authClient.razorpay.createOrder({
      amount: 75000,
      currency: "INR",
      receipt: "rcpt_manual_01",
      paymentCapture: false,
    });
    if (error || !order) {
      alert(error?.message ?? "Order failed");
      setLoading(false);
      return;
    }

    const rzp = new (window as any).Razorpay({
      key: process.env.NEXT_PUBLIC_RAZORPAY_KEY_ID!,
      order_id: order.id,
      amount: order.amount,
      currency: order.currency,
      name: "My Store",
      description: "Hold for manual capture",
      handler: (response: any) => {
        alert("Payment authorized. Awaiting capture.");
        setLoading(false);
      },
      modal: {
        ondismiss: () => setLoading(false),
      },
    });
    rzp.open();
  }

  return (
    <button onClick={pay} disabled={loading}>
      {loading ? "Processing..." : "Authorize ₹750"}
    </button>
  );
}
```

**3. Handle payment.authorized**

When the payment is authorized, the plugin fires the `onPaymentAuthorized` callback. Use this to run your business logic, for example checking stock levels or running a fraud review.

```ts auth.ts theme={null}
import { betterAuth } from "better-auth";
import { razorpay } from "@amank-root/better-auth-razorpay";

export const auth = betterAuth({
  plugins: [
    razorpay({
      keyId: process.env.RAZORPAY_KEY_ID!,
      keySecret: process.env.RAZORPAY_KEY_SECRET!,
      razorpayWebhookSecret: process.env.RAZORPAY_WEBHOOK_SECRET,
      onPaymentAuthorized: async ({ event, payment }) => {
        console.log("Authorized:", payment.id);
        // Check inventory, run fraud checks, etc.
      },
    }),
  ],
});
```

**4. Capture the payment**

Once your checks pass, call the capture endpoint to finalize the charge. You can capture the full amount or a smaller amount (partial capture).

```ts capture.ts theme={null}
import { auth } from "./auth";

const result = await auth.api.captureRazorpayPayment({
  body: {
    paymentId: "pay_XXXX",
    amount: 75000,
    currency: "INR",
  },
  headers: req.headers,
});
```

On the client:

```ts theme={null}
const { data, error } = await authClient.razorpay.payment.capture({
  paymentId: "pay_XXXX",
  amount: 75000,
  currency: "INR",
});
```

## Why use manual capture?

Manual capture is useful when you need time between authorization and fulfillment:

* **Inventory checks**: Confirm the item is in stock before charging the customer.
* **Fraud review**: Hold funds while you run risk checks.
* **Shipping confirmation**: Capture only after the order ships.

> [!NOTE]
>
> Razorpay automatically refunds authorized payments that are not captured within a certain window. Check the Razorpay documentation for the exact capture window for your account and payment method.

## Error handling

| Error code | Meaning |
| - | - |
| `PAYMENT_NOT_CAPTURED` | The payment exists but is not yet captured. This is expected before you call capture. |
| `PAYMENT_FETCH_FAILED` | The server could not retrieve the payment from Razorpay. |
| `INVALID_PAYMENT_SIGNATURE` | The signature check failed during verification. |


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