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

# Webhooks

> Get told the moment a payment, refund, subscription or deposit changes, signed so you know it came from Compago

## Overview

Instead of asking the API every few minutes whether something changed, register an HTTPS endpoint and Compago sends it an event the moment it happens: a payment is approved, a subscription charge is declined, a deposit reaches your bank account.

Every event is:

* **Signed** with the [Standard Webhooks](https://www.standardwebhooks.com) spec, so you verify it in a few lines with the official `standardwebhooks` library of your language.
* **Retried** for about three days until your endpoint answers `2xx`, so an outage on your side does not lose anything.
* **The same object the API returns.** `data.object` is exactly what `GET /developer/v1/...` returns for that object at that moment, so the code that reads the API reads the webhook.
* **Readable again** for 30 days with [`GET /developer/v1/event`](#reconcile-with-the-events-api), to fill any gap after your server was down.

## Add an endpoint

In the dashboard, go to **Configuración › Desarrollador › Webhooks** and choose **Agregar webhook**.

**1. Enter your URL**

A public `https` address, such as `https://example.com/webhooks/compago`. Addresses on a private network, `localhost` and URLs with a username or password are refused.

**2. Choose the events**

Pick the events you handle, or **Todos los eventos** to also receive the ones added later. Deposit events need permission to see settlements.

**3. Save the signing secret**

The secret (`whsec_...`) is shown **once**. Store it in your server's secrets. If you lose it, rotate it from the endpoint's page.

**4. Send a test event**

**Enviar evento de prueba** sends a `webhook_endpoint.test` event right away and shows what your server answered.

An organization can have up to 10 endpoints, for example one per environment or integration.

## The event

Every delivery is a `POST` with a JSON body:

```json theme={null}
{
  "id": "evt_5f0c8f0e1b2a4c6d8e9f00112233aabb",
  "type": "payment.succeeded",
  "apiVersion": "2026-11-01",
  "createdAt": "2026-11-05T18:04:31.120Z",
  "livemode": true,
  "data": {
    "object": {
      "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
      "operationCode": 61695145722,
      "status": "CONFIRMED",
      "amount": 1500,
      "chargedAmount": 1500,
      "currency": "MXN",
      "fee": 3.5,
      "terms": 3,
      "source": "SHAREPAY_PAYMENT_LINK",
      "createdAt": "2026-11-05T18:04:30.871Z"
    }
  }
}
```

| Field | Meaning |
| - | - |
| `id` | Unique per event and the same on every retry and resend. **Deduplicate on it.** Also sent as the `webhook-id` header |
| `type` | What happened. See [the catalog](#event-catalog) |
| `apiVersion` | The shape of `data.object`. It only changes with a new version |
| `createdAt` | When it happened |
| `livemode` | Always `true` today: every event is about real money |
| `data.object` | The object it happened to, as the developer API returns it. The example above is shortened: see [Payments](https://docs.compago.com/developer/payments.md) for every field |

> [!NOTE]
>
> A Super MSI payment that Compago is still collecting is reported as `CONFIRMED`, as it is everywhere else: you were paid in full when it was approved.

## Verify the signature

Each request carries three headers:

| Header | Content |
| - | - |
| `webhook-id` | The event id |
| `webhook-timestamp` | Unix seconds when this attempt was signed |
| `webhook-signature` | `v1,<base64>`, the HMAC-SHA256 of `{webhook-id}.{webhook-timestamp}.{body}` with your secret. During a secret rotation it holds two signatures separated by a space, and either one is valid |

Verify with the **raw body**, before parsing it: re-serializing the JSON changes it and breaks the signature. The libraries also refuse a timestamp more than five minutes old, which stops a captured request from being replayed.

```javascript Node.js theme={null}
import express from 'express';
import { Webhook } from 'standardwebhooks';

const webhook = new Webhook(process.env.COMPAGO_WEBHOOK_SECRET);
const app = express();

app.post('/webhooks/compago', express.raw({ type: 'application/json' }), async (req, res) => {
  let event;

  try {
    event = webhook.verify(req.body.toString('utf8'), req.headers);
  } catch {
    return res.status(400).send('Invalid signature');
  }

  // Answer first, then do the work: a slow answer counts as a failure and is retried.
  res.sendStatus(200);
  await queue.add(event);
});
```

```python Python theme={null}
import os
from flask import Flask, request
from standardwebhooks import Webhook

webhook = Webhook(os.environ["COMPAGO_WEBHOOK_SECRET"])
app = Flask(__name__)

@app.post("/webhooks/compago")
def compago_webhook():
    try:
        event = webhook.verify(request.get_data(), dict(request.headers))
    except Exception:
        return "Invalid signature", 400

    queue.enqueue(event)
    return "", 200
```

```php PHP theme={null}
<?php
use StandardWebhooks\Webhook;

$webhook = new Webhook(getenv('COMPAGO_WEBHOOK_SECRET'));

try {
    $event = $webhook->verify(file_get_contents('php://input'), getallheaders());
} catch (Exception $e) {
    http_response_code(400);
    exit('Invalid signature');
}

http_response_code(200);
```

Install the library with `npm install standardwebhooks`, `pip install standardwebhooks` or `composer require standard-webhooks/standard-webhooks`. There are libraries for Go, Ruby, Java, C# and Rust too.

## Respond and retry

Answer with any `2xx` status within **10 seconds**. Anything else (a `4xx` or `5xx`, a timeout, a refused connection) is retried with growing waits:

| Attempt | After the previous one |
| - | - |
| 2 | 1 minute |
| 3 | 5 minutes |
| 4 | 30 minutes |
| 5 | 2 hours |
| 6 | 6 hours |
| 7 | 12 hours |
| 8 | 24 hours |
| 9 | 24 hours |

That is nine attempts over about three days. Redirects are not followed: give the final URL.

If **every** delivery to an endpoint fails for three days, Compago turns it off and e-mails the people who manage webhooks. Fix your server, turn the endpoint back on from its page, and resend what you missed from its history or read it with the events API.

### Build a handler that holds up

> [accordion] Deduplicate on the event id
>
> Delivery is at least once: a retry after a timeout can reach you even though you processed the first attempt. Store the `id` of each event you handled and skip one you have already seen.

> [accordion] Do not rely on the order
>
> Events can arrive out of order, for example a `payment.refunded` before a delayed `payment.succeeded`. Every object carries its own `status` and timestamps: compare them with what you stored, or read the object again with the API when the order matters.

> [accordion] Answer first, process later
>
> Put the event on a queue and answer `200` right away. Work that takes longer than 10 seconds makes the attempt fail and the event come again.

> [accordion] Ignore types you do not know
>
> New event types are added over time. Answer `200` to a type your code does not handle, so it is not retried for days.

## Event catalog

### Payments

| Type | When |
| - | - |
| `payment.succeeded` | A payment was approved, on any channel: payment link, one-time payment, saved card, terminal, SPEI transfer |
| `payment.failed` | A payment was declined |
| `payment.canceled` | A payment was voided before it settled |
| `payment.refunded` | A payment was refunded. Compago may keep its fee: see [Refunds and fees](https://docs.compago.com/refunds/refunds-and-fees.md). The refund itself is told by the [refund events](#refunds) |
| `payment.authorized` | A hold was placed on a saved card. See [Hold and capture](https://docs.compago.com/payment-method/hold.md) |
| `payment.authorization_released` | A hold was released, or expired, without being captured |

`data.object` is a [payment](https://docs.compago.com/developer/payments.md).

### One-time payments

| Type | When |
| - | - |
| `one_time_payment.paid` | A one-time payment was paid, by card or SPEI |
| `one_time_payment.canceled` | A one-time payment was canceled |
| `one_time_payment.bank_transfer_received` | A transfer reached the one-time payment's CLABE, for the whole amount or a part of it. When it completes the amount, `payment.succeeded` and `one_time_payment.paid` follow |
| `one_time_payment.bank_transfer_expired` | The CLABE expired before the whole amount arrived. Anything that came in is sent back. The one-time payment can still be paid with a new CLABE |

`data.object` is a [one-time payment](https://docs.compago.com/one-time-payment/list.md).

### Refunds

| Type | When |
| - | - |
| `refund.created` | A refund was requested. Its `status` says whether the bank approved it (`SUCCEEDED`), declined it (`FAILED`) or it is on its way back to the customer (`PENDING`, a SPEI transfer being returned) |
| `refund.succeeded` | The money reached the customer: at once for a card, when the returned transfer arrives for SPEI |
| `refund.failed` | The bank declined the refund (`failureReason: DECLINED`), or the transfer could not be returned (`RETURN_FAILED`), in which case the payment is paid again |

`data.object` is the refund. `amount` is the whole amount the customer was charged:

```json theme={null}
{
  "id": "7d1e2c3b-4a5f-4e6d-8c7b-9a0f1e2d3c4b",
  "object": "refund",
  "paymentId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
  "amount": 1500,
  "currency": "MXN",
  "status": "SUCCEEDED",
  "failureReason": null,
  "createdAt": "2026-11-06T16:20:05.000Z",
  "updatedAt": "2026-11-06T16:20:05.000Z"
}
```

A card refund sends `refund.created` and then `refund.succeeded` or `refund.failed` right away. A SPEI refund sends `refund.created` with `PENDING`, and `refund.succeeded` when the money is back in the customer's account.

### Terminal

| Type | When |
| - | - |
| `payment_intent.succeeded` | A payment intent sent to a terminal was paid. `data.object.paymentId` is the payment |
| `payment_intent.canceled` | A payment intent was canceled on the terminal, by you, or expired |

`data.object` is a [payment intent](https://docs.compago.com/payment-intent/create.md).

### Subscriptions

| Type | When |
| - | - |
| `subscription.created` | A customer subscribed through a payment link |
| `subscription.updated` | The amount or the next billing date changed |
| `subscription.paused` | The subscription was paused |
| `subscription.resumed` | The subscription was resumed |
| `subscription.canceled` | The subscription was canceled, by you or after its retries ran out |
| `subscription.completed` | The subscription made its last charge |
| `subscription.payment_succeeded` | A recurring charge was approved |
| `subscription.payment_failed` | A recurring charge was declined |

`data.object` is a [subscription](https://docs.compago.com/developer/subscriptions.md). Use `GET /developer/v1/subscription/{id}/payment` for the charge itself.

### Saved cards

| Type | When |
| - | - |
| `payment_method.created` | A card was saved |
| `payment_method.revoked` | A saved card was removed |

`data.object` is a [saved card](https://docs.compago.com/payment-method/manage.md).

### Deposits

| Type | When |
| - | - |
| `payout.paid` | A deposit reached your bank account |
| `payout.failed` | A deposit failed, was rejected by the bank or came back |

`data.object` is the deposit:

```json theme={null}
{
  "id": "4c9a1f2e-7b3d-4e8a-9c1d-2f3a4b5c6d7e",
  "status": "PAID",
  "amount": 15230.5,
  "feeAmount": 0,
  "netAmount": 15230.5,
  "currency": "MXN",
  "trackingKey": "CMPG20261105001234",
  "bankAccountId": "0b8f6c1e-2d3a-4b5c-9e7f-1a2b3c4d5e6f",
  "periodFrom": "2026-11-03T06:00:00.000Z",
  "periodTo": "2026-11-04T06:00:00.000Z",
  "paidAt": "2026-11-05T15:02:11.000Z",
  "returnReason": null,
  "returnReasonCode": null,
  "createdAt": "2026-11-05T14:58:40.000Z"
}
```

`status` is `SCHEDULED`, `IN_TRANSIT`, `PAID`, `FAILED`, `RETURNED` or `IN_REVIEW` (the bank's answer is being checked by Compago). `bankAccountId` is one of your [bank accounts](https://docs.compago.com/api-reference/developer/bank-account/list.md). Bank account numbers are never sent.

## Reconcile with the events API

Every event of the last 30 days can be read again, exactly as it was delivered, with your API key. Use it after your server was down, or as a nightly check that nothing was missed.

```bash theme={null}
curl "https://api-harmony.compago.com/api/developer/v1/event?type=payment.succeeded&createdAtFrom=2026-11-04T00:00:00Z&limit=100" \
  -H "x-api-key: $COMPAGO_API_KEY"
```

```json theme={null}
{
  "data": [
    { "id": "evt_5f0c8f0e1b2a4c6d8e9f00112233aabb", "type": "payment.succeeded", "apiVersion": "2026-11-01", "createdAt": "2026-11-05T18:04:31.120Z", "livemode": true, "data": { "object": { "id": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee" } } }
  ],
  "pagination": { "limit": 100, "hasMore": false, "nextCursor": null }
}
```

Filter by `type` (repeat it for several), `objectId` and `createdAtFrom` / `createdAtTo`, and follow `pagination.nextCursor` as with every list. Process each event the way you process a delivery, deduplicating on `id`. Only events your organization had an endpoint listening for are kept, and test events are left out. The key needs the **Ver eventos** permission. Deposit events also need **Ver depósitos**, and without **Ver comisiones** a payment's `fee` reads `null`, as in the rest of the API. See [List events](https://docs.compago.com/api-reference/developer/event/list.md).

## Rotate the secret

On the endpoint's page, **Cambiar secreto de firma** creates a new secret and shows it once. For the next 24 hours every delivery is signed with both secrets, so you can deploy the new one without missing an event. If the old secret leaked, choose to stop using it right away instead.

## Endpoint history

The endpoint's page lists every delivery of the last 30 days with its status, each attempt and what your server answered (the first 1 KB of the body). **Reenviar** sends the same event, with the same `id`, again right away.


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