> ## Documentation Index
> Fetch the complete documentation index at: https://docs.crispstats.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> CrispStats is a hosted, privacy-first web analytics product. It has no self-hosted edition, no session replay, no heatmaps, no A/B testing, no mobile SDKs and no data import except a site's history from a Plausible export (Settings, Import and export).
> The script global is crispstats(...), site keys start with cs_pk_ and secret API keys start with cs_sk_. The script is served from https://in.crispstats.com/d.js and the REST API lives at https://crispstats.com/api/v1.
> There is no npm package to install. Integrations copy the script tag, the queue stub, crispstats.d.ts and proxy code from these docs or from Settings, Tracking code in the dashboard. A first-party proxy forwards one path of the site to https://in.crispstats.com/p/ and forwards only content-type, user-agent, accept-language, referer, origin, if-none-match and x-forwarded-for, never cookies.

# Connect Razorpay revenue to CrispStats

> Connect Razorpay with your live key ID and key secret: CrispStats imports past payments, checks for new ones every 2 minutes and ties each to a visit through order or subscription notes.

Connect Razorpay by pasting your live key ID and key secret. CrispStats imports your past payments and refunds, then reads new ones from Razorpay every 2 minutes. Put the visitor id in the order's or subscription's `notes` and each payment is tied to the visit that led to it.

| | |
| - | - |
| You paste | Your live key ID (`rzp_live_`) and its key secret |
| New payments | Within 2 minutes |
| History | Every payment since your first |
| Test mode | A `rzp_test_` key connects in test mode |
| Linked to a visit | When `crispstats_visitor_id` is in the order's or subscription's `notes` |

## What is recorded

| Razorpay object | Recorded as |
| - | - |
| A captured payment of an order | `one_time` |
| A subscription charge | The first charge is `subscription_new`, later ones are `subscription_renewal` |
| A captured payment of a Razorpay Invoice | `one_time`, with the invoice's notes |
| A processed refund | `refund`, for the amount refunded. Refunds of payments that were never captured are skipped |
| A dispute the business lost | `refund` of the disputed payment, read when past payments are imported. Open, won and closed disputes change nothing |

Only captured payments count. Every payment is read from Razorpay's API with your key, so each one is verified. Amounts are in the currency's smallest unit (`49900` is ₹499.00). Each payment is stored under its payment id (`pay_…`) and each refund under its refund id (`rfnd_…`).

## Connect Razorpay

**1. Open the Razorpay panel**

In CrispStats, open the site's **Settings**, then **Integrations**. Select **Connect a payment provider** and choose **Razorpay**.

**2. Find your key**

Under **Razorpay key ID**, select **Open API keys in Razorpay**. Then:

1. Switch to **Live mode**, then open **Account and Settings**, then **API keys**. You need the Owner or Admin role.
2. Copy the key ID, and the key secret you saved when you created it.
3. If you no longer have the secret, generate a new one. Choose to keep the old key for 24 hours if Razorpay offers it, and update your checkout before then.
4. Keep the key active so CrispStats can keep reading payments.

If the link does not open the API keys page, use the menu path in step 1.

**3. Paste the key ID and secret**

Paste the key ID into **Razorpay key ID** and the secret into **Razorpay key secret**. CrispStats checks them with Razorpay at once.

**4. Connect**

Select **Connect Razorpay**. The row shows **Connected. Checks Razorpay every 2 minutes.**

**5. Pass the visitor id at checkout**

See [pass the visitor id at checkout](#pass-the-visitor-id-at-checkout) below.

If Razorpay refuses the pair, the panel says "Razorpay did not accept this key ID and secret. Check both are from Live mode and copied in full." A key ID pasted into the secret field is refused with a message saying which field it belongs in.

## What the key can do

Razorpay keys cannot be limited: they can do anything your account can through the API, including refunds. CrispStats only reads payments and refunds with them. The secret is stored encrypted, used only on CrispStats' servers with Razorpay's API, and never shown again. The key ID is not secret: Razorpay shows it in your checkout pages.

## How fresh the numbers are

Razorpay does not let an account's own keys create a webhook, so CrispStats reads new payments and refunds every 2 minutes. A sale appears within 2 minutes.

Razorpay lists payments by when they were created. A payment created earlier and captured later is caught because each check looks 30 minutes further back, and a daily check reads the last 48 hours again. A payment seen twice is stored once.

## Past payments

When you connect, CrispStats imports every captured payment and processed refund since your first. See [revenue history](https://docs.crispstats.com/revenue/history.md).

## Test mode

A key ID that starts with `rzp_test_` connects in test mode. The panel says "This is a test key. Test payments show with a Test tag and never count as verified revenue." and offers **Connect in test mode** or **Use a live key**.

## Pass the visitor id at checkout

Add the id from `crispstats.id()` to the order's `notes` as `crispstats_visitor_id`. For a subscription, put it in the subscription's `notes`:

```js theme={"theme":{"light":"github-light","dark":"github-dark"}}
// In the browser, before you open Checkout
const visitorId = await crispstats.id();

// On your server, when you create the order
const order = await razorpay.orders.create({
  amount: 49900,
  currency: "INR",
  notes: { crispstats_visitor_id: visitorId },
});

// Subscriptions: in the subscription's notes instead
const subscription = await razorpay.subscriptions.create({
  plan_id: "plan_...",
  total_count: 12,
  notes: { crispstats_visitor_id: visitorId },
});
```

The notes of the payment, its order, its subscription or invoice, and the refund are all read. A payment without a visitor id is still recorded and counted, without a visit.

## Disconnect

Select **Disconnect** on the Razorpay row. CrispStats stops reading payments and destroys the saved secret. Payments already recorded stay. CrispStats created nothing in your Razorpay account, so there is nothing to delete there. You can regenerate the key in Razorpay if you no longer want it to work.

> [!NOTE]
>
> Connections made earlier with a webhook you added in Razorpay keep working. They cannot import history or verify payments: connect again with your key ID and secret to add both. A payment seen by the webhook and by a check is stored once.

## Next steps

> [card] [Pass the visitor id](https://docs.crispstats.com/revenue/visitor-id-at-checkout.md)
>
> When there is no id, and attributing across days.

> [card] [Refunds and renewals](https://docs.crispstats.com/revenue/refunds-and-renewals.md)
>
> How payment kinds are recorded across providers.

> [card] [Revenue history](https://docs.crispstats.com/revenue/history.md)
>
> What the import reads and how it avoids counting twice.


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