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

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:
Every event body has these fields: 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

  • payment_id is the payment that paid the invoice. It is the id of the matching row in /v1/transactions/. 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, or null.
  • amount_cents is in the currency’s smallest unit (12000 = 120.00 for a two-decimal currency).

payment.succeeded payload

  • 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

dispute.* payload

All five dispute events have the same shape: the dispute object is the one GET /v1/disputes/{id}/ returns, as it was when the event was created.
  • transaction_id is the id of the disputed payment in /v1/transactions/.
  • 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/.

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.
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. 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/, /v1/transactions/ and /v1/disputes/.
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/ 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.