Webhooks
Webhooks go both ways: Tanqory tells apps when a store's data changes, and Tanqory receives events from the payment and billing providers it works with.
Webhooks Tanqory sends to apps
An app subscribes to a topic, such as products/create, with
webhookSubscriptionCreate. Each event on that
topic is then sent to the subscription's endpoint as an HTTP POST whose body is the changed resource, in JSON
(or XML for a subscription in that format), with these headers:
| Header | Value |
|---|---|
Content-Type | application/json, or application/xml for a subscription in XML. |
User-Agent | Tanqory-Webhooks/1.0 |
X-Tanqory-Topic | The topic, such as products/create. |
X-Tanqory-Hmac-Sha256 | The signature of the body: see below. |
X-Tanqory-Shop-Domain | The store's domain. |
X-Tanqory-API-Version | The subscription's API version; the body follows that version. |
X-Tanqory-Webhook-Id | The id of this delivery. It stays the same when the delivery is retried. |
X-Tanqory-Event-Id | The id of the event. Every subscription to one event gets the same one. |
X-Tanqory-Triggered-At | When the change happened (ISO 8601). |
X-Tanqory-Name | The subscription's name, when it has one. |
Checking that a delivery comes from Tanqory
Compute an HMAC-SHA256 of the raw request body with your app's client secret, encode it in base64 and compare it with
X-Tanqory-Hmac-Sha256 in constant time. A webhook a merchant creates in the store's settings is signed with
the store's signing secret instead, shown on that settings page. Use the raw bytes of the body, before any JSON
parsing.
import { createHmac, timingSafeEqual } from 'node:crypto';
function fromTanqory(rawBody, header, secret) {
const expected = createHmac('sha256', secret).update(rawBody).digest();
const given = Buffer.from(header ?? '', 'base64');
return given.length === expected.length && timingSafeEqual(given, expected);
}
Answering and retries
- Answer with any 2xx status within 5 seconds. Do the work after answering.
- Any other answer, or none in time, is retried: up to 9 attempts in all, waiting 1, 2, 4, 8, 16, 32, 64, 128 minutes between them (about 4 hours 15 minutes in total).
- A retry carries the same
X-Tanqory-Webhook-Id. Use it to process each delivery once.
Webhooks Tanqory receives
Every webhook Tanqory receives from a third party has its address under one path:
https://api.tanqory.com/v1/webhooks/<provider>[/…]. These addresses are for the providers Tanqory works
with, not for apps.
| Method | Address | Receives |
|---|---|---|
| POST | https://api.tanqory.com/v1/webhooks/easyship | Provider events. |
| GET | https://api.tanqory.com/v1/webhooks/payments/{storeId}/{connectionId} | Events from a payment gateway account a store connected. Tanqory gives the gateway this address when the merchant connects the account. |
| POST | https://api.tanqory.com/v1/webhooks/payments/{storeId}/{connectionId} | Events from a payment gateway account a store connected. Tanqory gives the gateway this address when the merchant connects the account. |
| GET | https://api.tanqory.com/v1/webhooks/payments/{storeId}/{connectionId}/return | Provider events. |
| POST | https://api.tanqory.com/v1/webhooks/stripe | Stripe Billing events of Tanqory's own billing: store plans, charges and invoices. |
| POST | https://api.tanqory.com/v1/webhooks/stripe/connect | Stripe Connect events of stores' payment accounts. They finish payments the buyer completed away from checkout, such as PromptPay or 3-D Secure. |
- Each receiver checks the provider's signature over the raw body, and answers 401 when it does not verify, without saying whether the event, account or store exists.
- Each event is processed once: the same event delivered again answers 200 and changes nothing.