A webhook is a message we send to your server when something happens on your account, such as a payment succeeding, a refund being paid or a subscription changing. Set an endpoint up under Developer Portal → Webhooks, verify each delivery's signature, and treat the event, not the customer's redirect, as proof of payment.
Why use webhooks
A payment can finish after your customer has left your site, so a redirect proves nothing. A webhook tells your server what actually happened, so use it to grant access or ship an order.
Sandbox and live endpoints are separate, so set one up in each.
Add an endpoint
In the sidebar, open Developer Portal and go to Webhooks.
Click Add destination and enter the endpoint's URL. It must be public HTTPS and accept POST requests. We don't follow redirects, so use the final address.
Name the endpoint, choose the events you want, and save. It starts receiving events straight away.
Open the endpoint from the list and copy its signing secret from the detail page. Keep it on your server.
You can also create endpoints through the API with a key that has the webhooks:write permission. The Owner, Super Admin and Developer roles can manage webhooks. Finance and Customer Support can't.
Verify the signature
Every delivery carries an X-Bachs-Timestamp header and an X-Bachs-Signature header. The signature is a hex HMAC-SHA256 of the timestamp, a full stop and the raw request body, keyed with your signing secret. Reject any delivery whose timestamp is more than 300 seconds old.
Newer integrations should use the X-Bachs-Signature-V2 header, which reads t=<timestamp>,v1=<signature>. It may carry more than one v1 value while a secret is being rotated. Accept the delivery if any of them matches.
import hmac, hashlib, time
def verify(header, raw_body: bytes, secret: str, tolerance=300): parts = [p.split("=", 1) for p in header.split(",")] t = int(next(v for k, v in parts if k == "t")) if abs(time.time() - t) > tolerance: return False digest = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest() return any(hmac.compare_digest(digest, v) for k, v in parts if k == "v1")
Use the secret exactly as the dashboard shows it. Our Node.js and Python SDKs verify signatures for you.
Test on your own machine
Install the Bachs CLI and run
bachs login.Run
bachs listen --forward-to localhost:3000/webhooks. Add--events collection.succeeded,refund.paidto forward only some events. Each session prints its own secret, separate from your endpoint's.In a second terminal, run
bachs trigger collection.succeededto send a sample event. Triggering works only in the sandbox.
Forwarded deliveries aren't retried. See sandbox and test mode.
Why it might not work
"The URL is invalid" or "the URL cannot be reached" when saving
The address isn't public HTTPS. A local address such as localhost won't work, and neither will plain http. Use the CLI for local testing, or a deployed address. If you can't see Webhooks or Add destination, check your role.
You can't find the signing secret
It exists only once you've saved the endpoint. Open the endpoint from the list and reveal and copy it on its detail page. If you rotate the secret, the old one keeps working for 24 hours while you deploy the new one.
Signature verification fails
The most common cause is parsing the JSON before checking. Re-serialising changes the bytes and breaks the signature, so verify against the raw body. The next causes are a secret from a different endpoint or environment, a server clock more than 300 seconds out, and, with the V2 header, checking only the first v1 value.
Events arrive but nothing happens in your app
If our side shows the event delivered and your server returned 200, the gap is in your handler. Match the event to your order using data.reference, data.checkout_id or data.charge_id, and log what the handler does. Return a 2xx only once the event is stored. Deliveries are at least once, so deduplicate on the event id.
Nothing arrives at all
Check the Events and Logs tabs in the Developer Portal for delivery attempts. Then check that the endpoint is enabled and subscribed to the event you expect. A payment that never completed sends no success event, so a stuck payment is a different problem. See why a customer's payment failed. If you're a Connect platform, set the endpoint's event_source to connect or all. The default, account, sends nothing about connected accounts.
"Your webhook endpoint was disabled"
Your endpoint kept failing. We email the account owner and admins after 24 hours of failures and disable the endpoint after 72 hours. Payments aren't affected, only the notifications. Fix the cause, then click Enable endpoint. Events from while it was off aren't sent automatically, but you can resend them. Note the disabled_at time before you re-enable, because enabling clears it.
Redelivering a failed event
We retry a failed delivery up to five times over about 80 minutes. Timeouts, 5xx, 408 and 429 replies are retried, and other 4xx replies and redirects aren't. After that, resend the event from the dashboard or the API, or run bachs events replay <event_id>. A resend is a single attempt.
Deleting an endpoint
To stop an endpoint receiving events, switch off Enabled on it. To delete it, use the Delete a webhook endpoint call in the API reference.
Other situations
To change a URL, edit the endpoint and save, in the right environment. Bank transfer payments send the same collection.succeeded event. M-Pesa receipt numbers aren't in the webhook payload.
If an API call fails while you're handling an event, see what API errors mean.
Still stuck?
Message us from the chat in your dashboard with the endpoint name, the event ID, the time it should have arrived and what your server returned.
Never send your secret API key, signing secret, password or a one-time code in chat or by email. We'll never ask for them.
