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

# Webhooks

> Receive signed, server-to-server events when payments happen — so you don't have to poll.

Playto POSTs an event to your server whenever a payment succeeds. This lets you grant access, fulfil an order, or update your records the moment a payment goes through.

> [!NOTE]
>
> Webhooks are optional. You can always confirm a payment on demand with `GET /v1/invoices/{id}/` and checking `is_paid`. Webhooks just save you from polling.

> [!WARNING]
>
> **Ignore event types and fields you don't recognise, and return a 2xx.** We add new events and new fields over time. A handler that fails on something it hasn't seen would break the day we ship it.

## Setup

In the Playto Dashboard, open **Configuration** in the sidebar, then the **Webhooks** section:

1. **Set your endpoint**: the URL Playto should POST events to. Clear it to stop deliveries.
2. **Copy your signing secret**: a secret that starts with `whsec_`, shown in the same section with a copy button. It belongs to your account only: you can verify your events, and no one else can forge them. It is there as soon as you open the section.
3. **Regenerate it if it leaks**: the **Regenerate** button creates a new secret. The old one stops verifying immediately, so update your server first or right after.

The section has a **Test / Live** switch. **Test** is the sandbox and **Live** is production, and each has its own URL and its own secret. Set up both, and use the secret that matches the environment an event came from (the `livemode` field tells you which, see below).

## Events

| Event | When it fires |
| - | - |
| `invoice.paid` | A one-time invoice is paid. |
| `payment.succeeded` | A payment link (a product) is paid. |
| `webhook.test` | You asked for a test event with [`POST /v1/webhooks/test/`](/api-reference/webhooks/test-event). It carries no payment. |
| `dispute.created` | A new dispute is opened against one of your payments. Its status is usually `raised` or `under_review`; see below for disputes we first see after a decision. |
| `dispute.updated` | An open dispute changes, for example it goes under review after evidence is submitted, or a bank warning becomes a chargeback. Also sent when a decided dispute is reopened. |
| `dispute.won` | A dispute is decided in your favour. |
| `dispute.lost` | A dispute is decided in the customer's favour. |
| `dispute.withdrawn` | The dispute was closed without a decision (for example the customer or bank withdrew it, or a bank warning closed without becoming a chargeback). |

An invoice payment sends `invoice.paid` only, and a payment-link sale sends `payment.succeeded` only. A single payment never sends both.

## Request format

Every request is a `POST` with a JSON body and these headers:

```
Content-Type:        application/json
X-Playto-Event:      invoice.paid
X-Playto-Event-Id:   evt_3f1c9a7e5b2d4c8aa0e61f4b7d9c2e10
X-Playto-Signature:  <hex HMAC-SHA256 of the raw request body>
```

| Header | What it is |
| - | - |
| `X-Playto-Event` | The event type, the same as the body's `event`. |
| `X-Playto-Event-Id` | The event's unique id, the same as the body's `id`. |
| `X-Playto-Signature` | HMAC-SHA256 of the exact raw body, keyed with your signing secret, as lowercase hex. There is no `sha256=` prefix. |

Every event body has these fields:

| Field | Meaning |
| - | - |
| `id` | The event's unique id, starting `evt_`. A retry or a replay of the same event keeps the same `id`. |
| `livemode` | `true` for an event from production, `false` for one from the sandbox. |
| `event` | The event type. |
| `timestamp` | When the event was created. It is saved with the event, so it is the same on every retry and replay. |

The examples below list the fields in the order we send them. Read fields by name and don't depend on their order.

### `invoice.paid` payload

```json
{
  "id": "evt_3f1c9a7e5b2d4c8aa0e61f4b7d9c2e10",
  "livemode": true,
  "event": "invoice.paid",
  "timestamp": "2026-06-10T12:00:03.412908+00:00",
  "payment_id": "8d0e4a52-6c1b-4f7e-9a3d-2b5c7e1f0a94",
  "invoice_id": "c3d4e5f6-a7b8-9012-cdef-123456789012",
  "invoice_number": "INV-20260610-C3D4E5F6",
  "reference_id": "booking_88213",
  "amount_cents": 120000,
  "currency": "USD",
  "customer_email": "jane@acme.com",
  "customer_name": "Jane Smith",
  "paid_at": "2026-06-10T12:00:02.871530+00:00"
}
```

* `payment_id` is the payment that paid the invoice. It is the `id` of the matching row in [`/v1/transactions/`](/api-reference/transactions/retrieve). It is `null` only if no payment record was available to name.
* `invoice_id` is the invoice's `id` in `/v1/invoices/`.
* `reference_id` is the [one you set when you created the invoice](/api-reference/invoices/create.md#param-reference-id), or `null`.
* `amount_cents` is in the currency's smallest unit (12000 = 120.00 for a two-decimal currency).

### `payment.succeeded` payload

```json
{
  "id": "evt_9b41d2c7a8e64f30b5d17c2e6a0f8d35",
  "livemode": true,
  "event": "payment.succeeded",
  "timestamp": "2026-06-10T15:30:41.220117+00:00",
  "payment_id": "g7h8i9j0-4b6c-4d8e-a1f2-567890123456",
  "product_id": "a1b2c3d4-5678-4a0b-8def-1234567890ab",
  "checkout_session_id": "5e6f7a8b-9c0d-4e1f-a2b3-c4d5e6f7a8b9",
  "reference_id": null,
  "amount_cents": 7500,
  "currency": "USD",
  "customer_email": "jane@acme.com",
  "customer_name": "Jane Smith",
  "paid_at": "2026-06-10T15:30:40.905342+00:00"
}
```

* It is sent for payment-link (product) sales only.
* `payment_id` is the `id` of the matching row in `/v1/transactions/`, and `product_id` is the product's `id` in `/v1/products/`.
* `reference_id` is always `null` for now. The field is there so your parser doesn't change when product sales can carry one.

### `webhook.test` payload

```json
{
  "id": "evt_0c5e8f2a1d7b4963a4e0b8d6f3c1a927",
  "livemode": true,
  "event": "webhook.test",
  "timestamp": "2026-06-10T09:15:00.118274+00:00",
  "message": "This is a test event from Playto. Your webhook URL is reachable and the signature verified. Nothing was paid.",
  "merchant_id": "2b9d7c4e-1f3a-4e68-b5a0-9c8d7e6f5a41"
}
```

### `dispute.*` payload

All five dispute events have the same shape: the `dispute` object is the one [`GET /v1/disputes/{id}/`](/api-reference/disputes/retrieve) returns, as it was when the event was created.

```json
{
  "id": "evt_230addb8e36a4153ad6bebaab0b7776f",
  "livemode": true,
  "event": "dispute.created",
  "timestamp": "2026-06-10T09:41:13.452119+00:00",
  "dispute": {
    "id": "9115896d-0097-47f1-8ece-6cb9ade7ea47",
    "status": "raised",
    "amount_cents": 7500,
    "currency": "USD",
    "reason": "Product not received",
    "is_warning": false,
    "evidence_due_by": "2026-06-24T23:59:59Z",
    "transaction_id": "4e9bfe28-41e5-468d-8bf9-d7b19b78f7d0",
    "invoice_id": null,
    "product_id": "a1b2c3d4-5678-4a0b-8def-1234567890ab",
    "customer_email": "jane@acme.com",
    "created_at": "2026-06-10T15:11:12+05:30",
    "resolved_at": null
  }
}
```

* `transaction_id` is the `id` of the disputed payment in [`/v1/transactions/`](/api-reference/transactions/retrieve).
* `evidence_due_by` can be `null`.
* If we first hear of a dispute after it has been decided, you get either one `dispute.created` with status `won` or `lost`, or `dispute.created` (`raised`) followed by its outcome event. Handle both.
* One event is sent per change. A repeated notice about a dispute that hasn't changed sends nothing. While a dispute is open, its status follows the latest notice we receive, so it can move between `raised` and `under_review`. A late notice that would reopen a decided dispute is ignored.
* A decided dispute can occasionally change again, for example when the dispute moves to a later stage. Events can arrive out of order or more than once. Each event's top-level `timestamp` is when we recorded that change, and it only increases for a given dispute `id`: parse it as a date-time (don't compare the strings), and ignore an event whose `timestamp` is not newer than the last one you applied for that dispute. If in doubt, read the current state from `GET /v1/disputes/{id}/`.
* To recover events you missed, read [`GET /v1/disputes/`](/api-reference/disputes/list).

## Verify the signature

Before trusting any webhook, recompute the signature over the **raw request body bytes** using your signing secret and compare it, in constant time, to the `X-Playto-Signature` header. Reject the request if the header is missing. Never grant entitlements based on the payload alone.

```python Python
import hmac, hashlib

def verify(raw_body: bytes, signature_header: str | None, secret: str) -> bool:
    if not signature_header:
        return False
    expected = hmac.new(secret.encode(), raw_body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, signature_header)
```

```javascript Node.js
const crypto = require("crypto");

function verify(rawBody, signatureHeader, secret) {
  if (!signatureHeader) return false;
  const expected = Buffer.from(
    crypto
      .createHmac("sha256", secret)
      .update(rawBody)        // the raw bytes, before JSON.parse
      .digest("hex")
  );
  const received = Buffer.from(signatureHeader);
  // timingSafeEqual throws if the lengths differ
  if (expected.length !== received.length) return false;
  return crypto.timingSafeEqual(expected, received);
}
```

> [!WARNING]
>
> Sign over the **exact bytes** you received. If your framework re-serializes the JSON before you hash it, the signature won't match. Capture the raw body first.

## Handling events

* **Respond fast.** Return a **2xx** within 10 seconds, then do the slow work in the background.
* **Skip repeats.** Store the `id` of every event you have handled, and ignore an event whose `id` you have seen. Retries, redeliveries and replays of the same event all carry the same `id` (also sent as `X-Playto-Event-Id`). Don't key off `invoice_id` or `payment_id`; the `id` is the one that identifies the delivery.
* **Don't rely on order.** A retry of an earlier event can arrive after a later one. If order matters to you, check the current state with `GET /v1/invoices/{id}/` or `/v1/transactions/` instead of trusting the order events arrive in.
* **Ignore what you don't know.** Skip event types and fields you don't recognise and still return a 2xx.

## Delivery & retries

Playto expects a **2xx** within **10 seconds**. Anything else counts as a failure and is retried: any non-2xx response (4xx included), a timeout, or a connection error.

Retries follow this schedule. The wait is counted from the failed attempt.

| Attempt | Sent |
| - | - |
| 1 | Right away |
| 2 | 1 minute after attempt 1 failed |
| 3 | 5 minutes after attempt 2 |
| 4 | 30 minutes after attempt 3 |
| 5 | 2 hours after attempt 4 |
| 6 | 5 hours after attempt 5 |
| 7 to 12 | 10 hours after the one before, each |

That is **12 attempts over about 68 hours**, so a server that is down for a deploy or a weekend still gets the event. A retry can start up to a minute after its time. Every attempt sends the same event: the same `id`, the same bytes and the same signature.

After the 12th failed attempt Playto stops sending that event. To catch up on anything you missed, read it from the API: [`/v1/invoices/`](/api-reference/invoices/list), [`/v1/transactions/`](/api-reference/transactions/list) and [`/v1/disputes/`](/api-reference/disputes/list).

> [!WARNING]
>
> **Point the URL at its final address.** Playto follows redirects, but a `301`, `302` or `303` turns our `POST` into a `GET` with no body. Your handler never sees the event, and if the page it lands on answers `200` we count the event as delivered. Don't rely on redirects.

## Test your endpoint

[`POST /v1/webhooks/test/`](/api-reference/webhooks/test-event) sends a signed test event to your webhook URL through the same pipeline as a real event: a real event `id`, the same three headers, a real signature, and the same retries. Use it to check that your URL is reachable and your signature check works.

In production it sends a `webhook.test` event only, which carries no payment. In the sandbox you can also ask for a sample `invoice.paid`, `payment.succeeded` or `dispute.created` with obviously fake ids and `livemode: false`, so you can run your real handler.
