horse revenue Docs

Integrations

Webhooks

Horse posts each subscription event to your server as it happens, so you can unlock something server-side, update a CRM, or report to an ad network Horse doesn't talk to.

#Add an endpoint

On the app's Developer → Webhooks tab, add your endpoint's URL (it must be https) and pick the events to send, or leave all of them on. The signing secret is shown once: save it in your server's secrets. Send test posts a TEST event.

#Events

EventWhen
INITIAL_PURCHASEA first purchase, including the start of a free trial
RENEWALA subscription renewed
TRIAL_CONVERTEDA free trial turned into a paid subscription
NON_RENEWING_PURCHASEA lifetime unlock, consumable or non-renewing subscription
PRODUCT_CHANGEAn upgrade, downgrade or crossgrade
CANCELLATIONAuto-renew turned off. Access lasts until the period ends.
UNCANCELLATIONAuto-renew turned back on
BILLING_ISSUEA renewal payment failed
GRACE_PERIODThe subscription entered Apple's billing grace period
EXPIRATIONAccess ended
REFUNDApple refunded a purchase
REFUND_REVERSEDApple reversed a refund
TRANSFERPurchases moved from one customer to another (for example after a restore)

#The request

POST https://your.server/horse
Content-Type: application/json
User-Agent: Tally-Webhooks/1.0
X-Tally-Event: RENEWAL
X-Tally-Delivery: <delivery id>
X-Tally-Signature: t=1792900000,v1=<hex>
{
  "id": "…", "type": "RENEWAL", "at": 1792900000000, "createdAt": 1792900000412,
  "environment": "Production", "source": "asn",
  "app": { "id": "app_…", "bundleId": "com.example.app", "name": "Example" },
  "customer": { "id": "…", "appUserId": "…", "aliases": [] },
  "productId": "com.example.app.yearly", "entitlementIds": ["pro"], "periodType": "normal",
  "originalTransactionId": "…", "transactionId": "…",
  "price": { "amount": 39.99, "currency": "USD", "usd": 39.99 },
  "meta": {}
}
  • periodType is trial, intro, promo or normal.
  • source says who told Horse: asn (Apple's notifications), sdk (the app), admin (the dashboard) or api.
  • Sandbox events are sent too, marked "environment": "Sandbox".

#Check the signature

The signature is an HMAC-SHA256 of <t>.<raw body> with your signing secret, in hex. Compare in constant time, and refuse a t more than a few minutes old:

verify.ts
import { createHmac, timingSafeEqual } from "node:crypto";

export function verify(rawBody: string, header: string, secret: string): boolean {
  const { t, v1 } = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  if (!t || !v1 || Math.abs(Date.now() / 1000 - Number(t)) > 300) return false;
  const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
  return v1.length === expected.length && timingSafeEqual(Buffer.from(v1), Buffer.from(expected));
}

Use the raw body exactly as received. A body that was parsed and serialised again won't match.

#Answer quickly

  • Answer with a 2xx status within 4 seconds, and do the work afterwards.
  • Anything else, including a 4xx, is retried with growing gaps for about a day (12 tries), then given up. Each delivery's result is on the Webhooks tab.
  • An event can arrive more than once. Use its id to ignore repeats.