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

# GoCardless Connection Webhook

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

Per-connection variant of the [GoCardless webhook receiver](/api-reference/webhooks/gocardless)
for workspaces that connected their own GoCardless account with
[Connect a Gateway](/api-reference/gateways/connect). The batch is verified
with that connection's own webhook secret (resolved from `connID`) before any
event is trusted. Payment events are bound to the connection's workspace;
mandate events are 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/gocardless/{connID}`), append it to `https://api.recurso.dev`, and
  register that URL in the GoCardless Dashboard under
  **Developers > Webhook endpoints** 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 GoCardless gateway-connection id.                                                 |
| `Webhook-Signature` | string (header)     | Yes      | HMAC-SHA256 hex signature of the raw request body, computed with the connection's webhook secret. |

## Request Body

The raw GoCardless events payload: an object with an `events` array. Each event
is handled by its `resource_type` and `action`:

| Event                                       | Effect                                                                                                                       |
| ------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `billing_requests` / `fulfilled`            | Activates the local mandate and stores the real `MD...` mandate id that future debits reference.                             |
| `mandates` / any action                     | Keeps the local mandate status in sync with GoCardless.                                                                      |
| `payments` / `confirmed`, `paid_out`        | Settles the invoice that references this payment (`open` → `paid`) and records the dunning success.                          |
| `payments` / `failed`, `cancelled`          | No state change; the invoice stays `open` and dunning picks it up.                                                           |
| `payments` / `charged_back`, `late_failure` | Reverses a settled payment: the invoice reopens (`paid` → `past_due`) and the settlement cash leg is reversed in the ledger. |

Any other event is acknowledged and ignored. A payment event whose invoice
belongs to a different workspace than the connection is ignored, never
applied. `billing_requests` and `mandates` events are resolved by their
GoCardless id alone and are not checked against the connection's workspace.

## Example Request

GoCardless sends a POST request with a batch of events:

```bash theme={null}
curl -X POST https://api.recurso.dev/webhooks/gocardless/7c9e6679-7425-40de-944b-e07fc1f90ae7 \
  -H "Content-Type: application/json" \
  -H "Webhook-Signature: 3f1a9c0e7b2d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b" \
  -d '{
    "events": [
      {
        "id": "EV0123456789ABCD",
        "resource_type": "payments",
        "action": "confirmed",
        "links": {
          "payment": "PM0123456789ABCD"
        }
      }
    ]
  }'
```

## Response

Returns `200 OK` once the batch has been processed. `processed` counts every
event that was accepted on this delivery, including the ones acknowledged and
ignored (an unknown `resource_type`, a `billing_requests` action other than
`fulfilled`, a payment id that no invoice references, a payment for another
workspace's invoice). It is not a count of side effects. Events already
recorded by an earlier delivery are skipped silently and not counted, and an
event whose handler returned an error is not counted either.

```json theme={null}
{
  "status": "ok",
  "processed": 1
}
```

When mandate handling is not configured on the API, the batch is acknowledged
without processing:

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

## Fields

| Field       | Type    | Description                                                                                                                                                                                  |
| ----------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `status`    | string  | `ok` when the batch was processed, `ignored` when mandate handling is not configured.                                                                                                        |
| `processed` | integer | Number of events accepted on this delivery: the events in the batch minus duplicates minus events whose handler returned an error. Ignored events count. Present only when `status` is `ok`. |

<Warning>
  An event whose handler returns an error (for example, a transient database
  error while looking up the invoice for a payment id) is logged and left
  unrecorded rather than failing the batch, so the next redelivery retries it.
  A payment id that simply matches no invoice is not an error: it is
  acknowledged, counted in `processed`, and recorded, so it is never retried.
  Per-event deduplication skips the events that already completed, so nothing
  is processed twice.
</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, or is not valid JSON                                                                                                                       | Check the delivery in the GoCardless Dashboard; Recurso expects the raw events payload                                                                                          |
| `401`  | `unauthorized`      | `Webhook-Signature` does not match the HMAC-SHA256 of the raw body under this connection's secret                                                                          | Make sure the secret registered in GoCardless matches the connection's `webhook_secret`                                                                                         |
| `404`  | `not_found`         | No active GoCardless connection has this id (a missing, disconnected, or non-GoCardless connection all return 404)                                                         | Reconnect the gateway and register the new `webhook_path`                                                                                                                       |
| `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 GoCardless retry |

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


## OpenAPI

````yaml POST /webhooks/gocardless/{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/gocardless/{connID}:
    post:
      tags:
        - Inbound Webhooks
      summary: GoCardless webhook receiver (per-connection, BYO)
      description: |
        Per-connection variant of the GoCardless webhook receiver for tenants
        who connected their own GoCardless account. The batch is verified with
        THAT connection's own signing secret (resolved from `connID`) before
        any event is trusted. Called by GoCardless, not by API consumers.
      operationId: handleGoCardlessWebhookForConnection
      parameters:
        - name: connID
          in: path
          required: true
          description: The tenant's GoCardless gateway-connection id.
          schema:
            type: string
            format: uuid
        - name: Webhook-Signature
          in: header
          required: true
          description: HMAC-SHA256 hex signature of the raw request body.
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              description: Raw GoCardless events payload.
      responses:
        '200':
          description: Batch processed (individual events may be ignored).
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - ok
                      - ignored
                  processed:
                    type: integer
        '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`.

````