There are two ways for your server to learn that something changed in another service. It can ask again and again ("any new payments?"), which is called polling. Or the other service can tell it the moment something happens. That second way is a webhook: a "reverse API" where the other side makes the call.
How a webhook works
- You give the service an endpoint: a public HTTPS address on your server, such as
https://example.com/webhooks/reveata. - You choose the events you care about.
- When one happens, the service sends a
POSTwith details in the body. - Your server answers quickly with a
2xxstatus to say it received it. - If it does not, the service retries later.
Payment providers use webhooks to report charges and refunds, which is also how analytics tools that track revenue usually hear about payments.
Security: verify every delivery
Anyone who knows your endpoint address can send it a request, so a webhook must prove it came from the real sender. The usual method is a signature: the sender computes an HMAC of the request body with a secret only you and it know, and puts it in a header. Your server recomputes it and compares, in constant time. Adding a timestamp to what is signed, and refusing old ones, stops someone replaying a captured request.
Reveata's webhooks
An admin adds endpoints under Site settings → Developer → Webhooks (Webhooks). The events are:
| Event | Sent when |
|---|---|
payment.created |
A new payment or renewal is recorded, with the channel, source and campaign it is credited to |
payment.refunded |
A refund is recorded |
goal.completed |
A visitor completes a goal (at most one per goal per minute) |
alert.fired |
One of the website's alerts or reports fires |
summary.daily |
Once a day: yesterday's visitors, goals, new customers and net revenue |
Each delivery carries Reveata-Event-Id, Reveata-Event, Reveata-Timestamp and Reveata-Signature headers. The signature is a hex HMAC-SHA256 of <timestamp>.<raw body> keyed with the endpoint's whsec_ secret, and Reveata's docs suggest refusing timestamps more than 5 minutes off.
Answer with any 2xx within 10 seconds and do slow work afterwards. Failed deliveries are retried after 1 minute, 5 minutes, 30 minutes, 2 hours, 6 hours and 12 hours: 7 attempts over about 21 hours. Endpoints must be public https:// addresses; private and local addresses are refused.
Pitfalls
- Parsing before verifying. Verify the signature against the raw body. Re-serialised JSON will not match.
- Duplicates. Retries mean the same event can arrive twice. Store the event id and ignore repeats.
- Slow handlers. Doing heavy work before answering causes timeouts, which cause retries, which cause more load.
- Order. Do not assume events arrive in the order they happened.