Receive BillDog webhooks on your server
To receive BillDog webhooks, add an HTTPS endpoint under Integration & Data → Webhooks, pick its environment and events, and save the whsec_ signing secret it shows once. Each delivery is a JSON POST signed with HMAC-SHA256 over {X-BillDog-Timestamp}.{raw body}; check it against webhook-signature or X-BillDog-Signature, then deduplicate on X-BillDog-Event-ID, because failed deliveries are retried for about 2.5 hours.
Steps last checked against the SDK source on 16 Nov 2026.
What you'll build
- A sandbox webhook endpoint subscribed to subscription events
- A Node or Python handler that rejects unsigned or replayed requests
- Idempotent processing that survives retries and out-of-order events
- A test event and a real sandbox purchase event delivered end to end
What you'll need
- A BillDog project where you have write access
- A server that can receive public HTTPS requests (a tunnel such as ngrok or cloudflared is fine for local work)
- Node 18+ or Python 3.9+ for the examples
1. Expose an HTTPS endpoint
5 minBillDog only delivers to public https:// URLs. It refuses private and local addresses, so http://localhost:3000 won't work even for testing. While developing, run a tunnel and use its HTTPS address, for example https://abc123.ngrok.app/billdog/webhook.
- Respond within 10 seconds. BillDog stops waiting after that and counts the attempt as failed. If your work takes longer, store the event and return
200straight away. - Any
2xxresponse counts as delivered. - A
4xxresponse is treated as permanent: that event is not retried. Use5xxfor errors that a retry could fix, such as your database being down.
2. Add the endpoint in the dashboard
4 min- Open Integration & Data → Webhooks and stay on the Your Webhooks tab. Click Add Webhook.
- Enter the Endpoint URL.
- Set Environment to Sandbox for now. An endpoint receives events from one environment only, and you can't change it later; add a separate Production endpoint before launch.
- Optional: under Custom headers, add one
Name: valueper line, such asAuthorization: Bearer your-token. They're sent with every delivery and stored encrypted. - Choose events. Quick Event Presets → Paywall Events selects every subscription, trial, purchase and entitlement event. Or tick events one by one under Granular Event Subscriptions.
- Click Create Webhook. The Webhook Secret dialog shows a secret starting with
whsec_. Copy it now: it is never shown again. Store it on your server asBILLDOG_WEBHOOK_SECRET.
Lost the secret? Click the rotate icon on the endpoint's row (Regenerate secret). The old secret keeps signing deliveries for 24 hours, so you can deploy the new one without dropping events (see step 3).
3. Verify every delivery's signature
12 minAnyone can POST to your URL, so check the signature before you trust a delivery. Every request carries these headers:
X-BillDog-Signature: <hex HMAC-SHA256, current secret>
X-BillDog-Timestamp: 1763280000 (Unix seconds)
X-BillDog-Event: subscription.renewed
X-BillDog-Event-ID: <stable ID, the same on every retry>
webhook-signature: v1,<hex> ("v1,<new> v1,<old>" during a rotation)The signature is the lowercase hex HMAC-SHA256 of the timestamp header, a full stop, and the raw request body, keyed with the whole secret string (including whsec_, as UTF-8 bytes). Hash the body exactly as received: parsing the JSON and serializing it again changes the bytes and breaks the check. Then reject anything older than five minutes, so a captured request can't be replayed later.
import crypto from "node:crypto";
import express from "express";
const app = express();
const SECRET = process.env.BILLDOG_WEBHOOK_SECRET; // whsec_...
function isValid(req) {
const timestamp = req.get("X-BillDog-Timestamp") ?? "";
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
if (!/^\d+$/.test(timestamp) || age > 300) return false;
const expected = crypto
.createHmac("sha256", SECRET)
.update(`${timestamp}.`)
.update(req.body) // the raw Buffer from express.raw
.digest();
// Every valid signature: one normally, two during a secret rotation.
const candidates = (req.get("webhook-signature") ?? "")
.split(" ")
.filter((s) => s.startsWith("v1,"))
.map((s) => Buffer.from(s.slice(3), "hex"));
return candidates.some((sig) => sig.length === expected.length && crypto.timingSafeEqual(sig, expected));
}
app.post("/billdog/webhook", express.raw({ type: "application/json" }), async (req, res) => {
if (!isValid(req)) return res.status(401).send("invalid signature");
const eventId = req.get("X-BillDog-Event-ID");
const eventType = req.get("X-BillDog-Event");
const payload = JSON.parse(req.body.toString("utf8"));
await handleEvent(eventId, eventType, payload); // your code, step 4
res.sendStatus(200);
});
app.listen(3000);import hashlib
import hmac
import json
import os
import time
from flask import Flask, abort, request
app = Flask(__name__)
SECRET = os.environ["BILLDOG_WEBHOOK_SECRET"].encode() # the whole whsec_... string
def is_valid(req) -> bool:
timestamp = req.headers.get("X-BillDog-Timestamp", "")
if not timestamp.isdigit() or abs(time.time() - int(timestamp)) > 300:
return False
expected = hmac.new(SECRET, timestamp.encode() + b"." + req.get_data(), hashlib.sha256).hexdigest()
candidates = [s[3:] for s in req.headers.get("webhook-signature", "").split(" ") if s.startswith("v1,")]
return any(hmac.compare_digest(sig, expected) for sig in candidates)
@app.post("/billdog/webhook")
def billdog_webhook():
if not is_valid(request):
abort(401)
event_id = request.headers["X-BillDog-Event-ID"]
event_type = request.headers["X-BillDog-Event"]
payload = json.loads(request.get_data())
handle_event(event_id, event_type, payload) # your code, step 4
return "", 200webhook-signature borrows the Standard Webhooks header shape but not its algorithm (Standard Webhooks signs the message ID and uses base64). A Standard Webhooks library will reject every delivery, so use your own check like the ones above.
Why read webhook-signature instead of X-BillDog-Signature? For 24 hours after you regenerate the secret, deliveries are signed with both secrets. X-BillDog-Signature carries only the new one, while webhook-signature lists both, so the code above keeps working whether your server holds the old or the new secret.
4. Handle events once, in order
10 minThe body is the event's own JSON object, with no shared wrapper. App Store and Google Play subscription events are flat and include the event type and ID. A renewal looks like this (trimmed):
{
"event_type": "subscription.renewed",
"event_id": "4f0b2c9e-...",
"app_user_id": "user_123",
"customer_id": "c2f7...",
"store_purchase_id": "9a1d...",
"state_version": 2,
"platform": "ios",
"store": "app_store",
"product_kind": "auto_renewable",
"store_product_id": "com.example.premium.monthly",
"product_id": "premium_monthly",
"store_transaction_id": "2000000812345678",
"transaction_type": "renewal",
"is_trial": false,
"revenue_usd": 9.99,
"price_local": 9.99,
"currency": "USD",
"purchased_at": "2026-11-15T10:00:00+00:00",
"is_sandbox": true
}app_user_idis the ID your app passed tologIn.customer_idis BillDog's internal ID;product_idis the dashboard Product Identifier.- Purchase events:
trial.started,subscription.started,subscription.renewed,purchase.completed(one-time products),subscription.product_changed,purchase.refunded, andsubscription.transferredorpurchase.transferredwhen a purchase moves to another customer. - State changes:
subscription.canceled(auto-renew turned off),subscription.uncanceled,subscription.billing_issue,subscription.expired,subscription.paused,subscription.resumed, andsubscription.updatedfor anything else, such as entering a grace period. These carrystate,will_auto_renewandexpires_at. - Stripe web purchases, BillDog Auth (
user.*,session.*) and organization events have different fields. CheckX-BillDog-Eventbefore you read the body.
Delivery is at least once. A retry, or a slow first attempt, can bring the same event twice, and events for one purchase can arrive out of order. Two rules cover both:
- Deduplicate on `X-BillDog-Event-ID`. It's the same on every retry of an event. Insert it into a table with a unique constraint before acting, and return
200if it's already there. - Order by `state_version`. It goes up with each change to a purchase. Store the highest you've applied per
store_purchase_idand ignore lower ones.
If your endpoint doesn't answer 2xx, BillDog tries three times straight away (2 and 4 seconds apart), then five more times after 5, 10, 20, 40 and 80 minutes: 8 attempts over about 2.5 hours. A 4xx stops this at once. After 10 deliveries in a row fail, the endpoint is disabled and the project owner is emailed. Turn it back on with the switch on its row.
5. Send a test event and read the delivery log
4 minOn the Your Webhooks tab, click the paper-plane icon (Test fire) on your endpoint's row. BillDog sends one signed request with X-BillDog-Event: test and shows Test webhook delivered if your server returned 2xx, or Test webhook failed with the status code if not. The test body is shaped differently from real events:
{
"event_type": "test",
"project_id": "…",
"timestamp": "2026-11-16T09:30:00.000Z",
"data": {
"message": "This is a test event from BillDog to verify webhook connectivity.",
"webhook_endpoint_id": "…",
"sent_by": "you@example.com"
}
}Answer 200 to event types you don't handle, including test, so they aren't counted as failures.
Open the Delivery History tab to see each delivery's Event Type, Status, Response code and Attempts. Click a row for the error message and Payload Preview. After fixing a bug in your handler, click Replay on a failed row to queue it again with its original event ID; it's sent within about a minute.
6. Send a real sandbox event, then go live
5 minTest fire proves the connection and your signature check. To see a real event shape, create a sandbox purchase: open /dashboard/test-store, create a mock purchase with Successful purchase, and within about a minute your sandbox endpoint receives subscription.started (or trial.started for a trial product). Use Time Travel to produce subscription.renewed. See Test purchases without a store account.
- Sandbox events from App Store sandbox, Play licence testers and the Test Store go only to Sandbox endpoints, and live App Store and Play purchases only to Production endpoints. These payloads also carry
is_sandbox. - Before launch, add a Production endpoint. It gets its own secret, so store both and pick the right one per endpoint URL.
Webhooks are not a replacement for reading entitlements. For a definitive answer about one user, call POST /v1/get-customer-info with a secret key, as shown in Test purchases without a store account.