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

# Razorpay Connection Webhook

> Receive Razorpay webhook events for a workspace's own connected Razorpay account.

Per-connection variant of the [Razorpay webhook receiver](/api-reference/webhooks/razorpay)
for workspaces that connected their own Razorpay account with
[Connect a Gateway](/api-reference/gateways/connect). The event is verified
with that connection's own webhook secret (resolved from `connID`) before the
payload is trusted. Invoice, refund and virtual-account events are bound to
the connection's workspace; `token.confirmed` is not (see below). Event
handling is otherwise identical to the platform receiver.

<Note>
  Each connection has its own URL. Read `webhook_path` from
  [List Gateway Connections](/api-reference/gateways/list) (for example
  `/webhooks/razorpay/{connID}`), append it to `https://api.recurso.dev`, and
  register that URL in the Razorpay Dashboard under **Settings > Webhooks**
  using the `webhook_secret` you supplied when connecting, or set later with
  [Set Gateway Webhook Secret](/api-reference/gateways/webhook-secret). A
  connection without a webhook secret cannot verify deliveries and rejects them.
</Note>

## Parameters

| Parameter              | Type                | Required | Description                                                                                                         |
| ---------------------- | ------------------- | -------- | ------------------------------------------------------------------------------------------------------------------- |
| `connID`               | string (UUID, path) | Yes      | The workspace's Razorpay gateway-connection id.                                                                     |
| `X-Razorpay-Signature` | string (header)     | Yes      | HMAC-SHA256 hex signature of the raw request body, computed with the connection's webhook secret.                   |
| `X-Razorpay-Event-Id`  | string (header)     | No       | Razorpay's event id, used as the deduplication key. When absent, a SHA-256 hash of the signed body is used instead. |

## Request Body

The raw Razorpay event payload. The `event` field selects the handler:

| Event                               | Effect                                                                                                                                       |
| ----------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `payment.captured`, `order.paid`    | Settles the invoice named in `notes.invoice_id` (`open` → `paid`), stores the `pay_*` id for later refunds, and records the dunning success. |
| `payment.failed`                    | Marks the invoice in `notes.invoice_id` `past_due`, records the dunning failure, and triggers the dunning campaign.                          |
| `refund.processed`, `refund.failed` | Advances the [credit note](/api-reference/credit-notes/get) that owns the refund (`pending` → `processed` or `refund_failed`).               |
| `token.confirmed`                   | Activates the [UPI mandate](/api-reference/mandates/create) authorized by the customer.                                                      |
| `virtual_account.credited`          | Reconciles an offline payment against the [virtual account](/api-reference/virtual-accounts/list) it landed in.                              |

Any other event is acknowledged with `status: "ignored"`. An invoice,
refund or virtual account that belongs to a different workspace than the
connection is never applied: an invoice is acknowledged as `ignored` with
reason `unknown invoice_id`, while a refund or virtual account is acknowledged
with `status: "ok"` and no `reason`, exactly as if it had been applied.
`token.confirmed` resolves the mandate by its Razorpay token id alone and is
not checked against the connection's workspace.

## Example Request

Razorpay sends a POST request with event data:

```bash theme={null}
curl -X POST https://api.recurso.dev/webhooks/razorpay/7c9e6679-7425-40de-944b-e07fc1f90ae7 \
  -H "Content-Type: application/json" \
  -H "X-Razorpay-Signature: 3f1a9c0e7b2d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b" \
  -H "X-Razorpay-Event-Id: Rzp9ABCDEF123456" \
  -d '{
    "entity": "event",
    "event": "payment.captured",
    "payload": {
      "payment": {
        "entity": {
          "id": "pay_RzpABC123",
          "amount": 249900,
          "currency": "INR",
          "status": "captured",
          "order_id": "order_RzpDEF456",
          "notes": {
            "invoice_id": "1c1b3a5e-4d7f-4c1a-9f2e-6b8d0a3c5e71"
          }
        }
      }
    }
  }'
```

## Response

Returns `200 OK` on successful processing. A `payment.captured` or
`order.paid` whose `invoice_id` matches no invoice is acknowledged as
`ignored`; a `payment.failed` whose `invoice_id` matches no invoice is treated
as an error and returns `500`, so Razorpay keeps redelivering it.

```json theme={null}
{
  "status": "ok"
}
```

When the event is acknowledged but deliberately not applied, `reason` says
why:

```json theme={null}
{
  "status": "ignored",
  "reason": "unknown invoice_id"
}
```

## Fields

| Field    | Type   | Description                                                                                                                                                                                                                                                     |
| -------- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `status` | string | `ok` when the event was applied (or, for a refund or virtual account owned by another workspace, silently not applied), `ignored` when it was acknowledged without side effects. A redelivery of an event that was already applied returns `duplicate ignored`. |
| `reason` | string | Present on some ignored events: `no invoice_id`, `invalid invoice_id`, `unknown invoice_id` (also used for an invoice owned by another workspace), `no refund_id`, `unknown refund_id`, `no token_id`, or `no va_id`. Absent for unhandled event types.         |

<Warning>
  Deduplication keys on `X-Razorpay-Event-Id`. When the header is missing, the
  delivery is deduplicated on a hash of the signed body instead, so a
  byte-identical replay is still ignored. An event is only recorded as processed
  after a 2xx response; a delivery that fails with 5xx is retried by Razorpay and
  reprocessed.
</Warning>

## Errors

| Status | Code                | When                                                                                                                                                                       | Fix                                                                                                                                                                           |
| ------ | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `400`  | `validation_failed` | `connID` in the path is not a UUID                                                                                                                                         | Use the connection's `webhook_path` from [List Gateway Connections](/api-reference/gateways/list)                                                                             |
| `400`  | `validation_failed` | Request body could not be read, is not valid JSON, or the event-specific payload (token, refund, virtual account) cannot be parsed                                         | Check the delivery in the Razorpay Dashboard; Recurso expects the raw event payload                                                                                           |
| `401`  | `unauthorized`      | `X-Razorpay-Signature` is missing or does not match the HMAC-SHA256 of the raw body under this connection's secret                                                         | Make sure the secret registered in Razorpay matches the connection's `webhook_secret`                                                                                         |
| `404`  | `not_found`         | No active Razorpay connection has this id (a missing, disconnected, or non-Razorpay connection all return 404)                                                             | Reconnect the gateway and register the new `webhook_path`                                                                                                                     |
| `500`  | `internal_error`    | The invoice could not be loaded; settling, reconciling, or advancing the refund failed; or a `payment.failed` names an `invoice_id` that matches no invoice                | Razorpay retries the delivery; the event is not recorded as processed until it succeeds                                                                                       |
| `503`  | `internal_error`    | The connection has no webhook secret (the receiver fails closed), per-connection webhooks are not configured on the API, or the inbound-webhook dedup store is unavailable | Store the secret with [Set Gateway Webhook Secret](/api-reference/gateways/webhook-secret) (the connection id and `webhook_path` stay the same); otherwise let Razorpay retry |

Errors use the standard envelope — see [Errors](/api-reference/errors).


## OpenAPI

````yaml POST /webhooks/razorpay/{connID}
openapi: 3.1.0
info:
  title: Recurso API
  version: 1.0.0
  description: |
    The Recurso billing engine REST API.

    Authenticate by passing your API key as a bearer token:

        Authorization: Bearer <api_key>

    Obtain an API key by registering a tenant via `POST /auth/register`.
    All authenticated endpoints live under the `/v1` prefix. Mutating
    endpoints support idempotency via the `Idempotency-Key` header.
  license:
    name: MIT
    identifier: MIT
servers:
  - url: https://billing.example.com
    description: >-
      Example deployment — substitute the base URL of your own Recurso
      deployment.
security:
  - bearerAuth: []
tags:
  - name: System
    description: Health, version, and API metadata
  - name: Auth
    description: Tenant registration
  - name: Plans
    description: Product catalog plans
  - name: Customers
    description: Customer management
  - name: Subscriptions
    description: Subscription lifecycle
  - name: Invoices
    description: Invoices, PDFs, and Indian GST e-invoicing
  - name: Coupons
    description: Discounts
  - name: Usage
    description: Metered usage events
  - name: Credit Notes
    description: Customer credits
  - name: Quotes
    description: Quote-to-invoice lifecycle
  - name: Webhooks
    description: Webhook endpoint management and event feed
  - name: Analytics
    description: Revenue analytics
  - name: Checkout
    description: Public hosted checkout for invoices
  - name: Payments
    description: Payment order creation
  - name: Inbound Webhooks
    description: Receivers for payment-gateway callbacks (Razorpay, Stripe)
  - name: Customer Portal
    description: Customer-facing portal — magic-link auth and session-scoped data
  - name: Developer
    description: API key management
  - name: Account
    description: Tenant account settings
  - name: Finance
    description: Ledger accounts, entries, reconciliation, and revenue recognition
  - name: Settings
    description: Tax (GST) and e-invoicing (IRP) configuration
  - name: Consents
    description: Consent records for RBI-compliant recurring billing
  - name: Referrals
    description: Customer referral program
  - name: Gifts
    description: Gift subscriptions
  - name: Mandates
    description: UPI Autopay mandates
  - name: Offline Payments
    description: Virtual accounts and manually recorded payments
  - name: Organizations
    description: Multi-entity organizations grouping several tenants
  - name: Accounting
    description: QuickBooks / Xero accounting integrations
  - name: Churn
    description: Churn risk scoring and alerts
  - name: Cancel Flows
    description: Configurable retention flows shown at cancellation time
  - name: Dunning
    description: Dunning analytics and multi-channel dunning campaigns
paths:
  /webhooks/razorpay/{connID}:
    post:
      tags:
        - Inbound Webhooks
      summary: Razorpay webhook receiver (per-connection, BYO)
      description: |
        Per-connection variant of the Razorpay webhook receiver for tenants who
        connected their own Razorpay account. The event is verified with THAT
        connection's own signing secret (resolved from `connID`) before the
        payload is trusted. Called by Razorpay, not by API consumers.
      operationId: handleRazorpayWebhookForConnection
      parameters:
        - name: connID
          in: path
          required: true
          description: The tenant's Razorpay gateway-connection id.
          schema:
            type: string
            format: uuid
        - name: X-Razorpay-Signature
          in: header
          required: true
          description: HMAC-SHA256 signature of the raw request body.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: Raw Razorpay event payload.
      responses:
        '200':
          description: Event processed (or deliberately ignored).
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - ok
                      - ignored
                  reason:
                    type: string
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
      security: []
components:
  responses:
    BadRequest:
      description: The request body or parameters are invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid credentials (API key or session cookie).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: The requested resource does not exist.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          description: Structured error detail.
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Stable machine-readable error code.
              examples:
                - validation_failed
                - unauthorized
                - forbidden
                - not_found
                - conflict
                - rate_limited
                - internal_error
                - invalid_api_key
                - key_mode_mismatch
                - over_refund
                - invoice_not_paid
                - invoice_already_paid
            message:
              type: string
              description: Human-readable explanation.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: >-
        Tenant API key obtained from `POST /auth/register` or `POST
        /v1/developer/keys`.

````