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

# Quickstart: Webhooks

> Configura un endpoint HTTPS, verifica SimplePay-Signature y procesa eventos de forma idempotente.

Los webhooks son la fuente recomendada para confirmar pagos, reservas, expiraciones, refunds y cambios de estado asincronos.

## 1. Crea endpoint

```bash terminal theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -sS -X POST "https://api.simplepay.mx/v1/webhook_endpoints" \
  -H "Authorization: Bearer $SIMPLEPAY_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: webhook_endpoint_prod_v1" \
  -d '{
    "url": "https://example.com/api/simplepay/webhook",
    "enabled_events": [
      "booking.confirmed",
      "booking.expired",
      "booking.cancelled"
    ],
    "description": "Production webhook"
  }'
```

## 2. Verifica firma

```ts verify-simplepay.ts theme={"theme":{"light":"github-light","dark":"github-dark"}}
import crypto from "node:crypto";

export function verifySimplePaySignature(args: {
  rawBody: string;
  signatureHeader: string;
  secret: string;
}) {
  const parts = Object.fromEntries(
    args.signatureHeader.split(",").map((part) => {
      const [key, value] = part.split("=");
      return [key, value];
    }),
  );

  const signedPayload = `${parts.t}.${args.rawBody}`;
  const expected = crypto
    .createHmac("sha256", args.secret)
    .update(signedPayload)
    .digest("hex");

  return crypto.timingSafeEqual(
    Buffer.from(expected, "hex"),
    Buffer.from(parts.v1, "hex"),
  );
}
```

## 3. Procesa idempotente

* Persiste `event.id` con unique constraint.
* Responde `2xx` solo despues de guardar el evento.
* Si tu handler falla, usa replay.

## Siguiente

* Guia completa: [Webhooks](/webhooks/overview)
* Eventos: [Webhook events](/webhooks/events)
* Endpoint create: [POST /v1/webhook\_endpoints](/api-reference/endpoints/webhooks-events/create-webhook-endpoint)
