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.Setup
In the Playto Dashboard, open Configuration in the sidebar, then the Webhooks section:- Set your endpoint: the URL Playto should POST events to. Clear it to stop deliveries.
- 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. - 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.
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 aPOST 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_idis the payment that paid the invoice. It is theidof the matching row in/v1/transactions/. It isnullonly if no payment record was available to name.invoice_idis the invoice’sidin/v1/invoices/.reference_idis the one you set when you created the invoice, ornull.amount_centsis 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_idis theidof the matching row in/v1/transactions/, andproduct_idis the product’sidin/v1/products/.reference_idis alwaysnullfor 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_idis theidof the disputed payment in/v1/transactions/.evidence_due_bycan benull.- If we first hear of a dispute after it has been decided, you get either one
dispute.createdwith statuswonorlost, ordispute.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
raisedandunder_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
timestampis when we recorded that change, and it only increases for a given disputeid: parse it as a date-time (don’t compare the strings), and ignore an event whosetimestampis not newer than the last one you applied for that dispute. If in doubt, read the current state fromGET /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 theX-Playto-Signature header. Reject the request if the header is missing. Never grant entitlements based on the payload alone.
Handling events
- Respond fast. Return a 2xx within 10 seconds, then do the slow work in the background.
- Skip repeats. Store the
idof every event you have handled, and ignore an event whoseidyou have seen. Retries, redeliveries and replays of the same event all carry the sameid(also sent asX-Playto-Event-Id). Don’t key offinvoice_idorpayment_id; theidis 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/.
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.