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 spec, so you verify it in a few lines with the official
standardwebhookslibrary 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.objectis exactly whatGET /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, 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.The event
Every delivery is aPOST with a JSON body:
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:
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.
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 any2xx status within 10 seconds. Anything else (a 4xx or 5xx, a timeout, a refused connection) is retried with growing waits:
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
Deduplicate on the event id
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.Do not rely on the order
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.Answer first, process later
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.Ignore types you do not know
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
data.object is a payment.
One-time payments
data.object is a one-time payment.
Refunds
data.object is the refund. amount is the whole amount the customer was charged:
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
data.object is a payment intent.
Subscriptions
data.object is a subscription. Use GET /developer/v1/subscription/{id}/payment for the charge itself.
Saved cards
data.object is a saved card.
Deposits
data.object is the deposit:
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. 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.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.
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 sameid, again right away.