Webhooks
Order lifecycle events delivered to your endpoint with signed requests and retries.
The B2B platform delivers outbound webhooks for order lifecycle events to any endpoint you have registered internally (via the org's WebhookEndpoint record), using HMAC-SHA256 request signing and exponential-backoff retries (up to 6 attempts over roughly 13 hours before a delivery is dead-lettered).
StampMitra's own payment provider delivers its webhooks to POST /v1/payments/webhooks/:connectionId, which is server-to-server, signature-verified, and is not called by this frontend.
Exponential backoff, up to 6 attempts over roughly 13 hours, then the delivery is dead-lettered.
From order event to your endpoint
- Step 1
Order event
Something changes on an order
- Step 2
Signed request
HMAC-SHA256 + timestamp header
- Step 3
Your endpoint
Verify, then respond 2xx
- Step 4
Retries
Exponential backoff, up to 6 attempts
Check the signature
Every delivery is a POST with a JSON body and three headers. The signature is the hex-encoded HMAC-SHA256(secret, `${timestamp}.${rawBody}`), where rawBody is the request body exactly as received. Verify against the raw bytes: do not parse and re-serialise the JSON first.
| Header | Value |
|---|---|
X-Webhook-Signature | Hex-encoded HMAC-SHA256 of `${timestamp}.${rawBody}`, keyed with your endpoint secret. |
X-Webhook-Signatures | v1=<hex>, comma-separated: every currently valid signature. While you rotate a secret (24 hours by default) it carries one entry per secret, and X-Webhook-Signature stays signed with the old secret until the window ends. Accept the request if any entry matches a secret you hold. |
X-Webhook-Timestamp | Unix time in seconds when this attempt was signed. It is part of the signed string. |
X-Webhook-Event-Id | Stable id of the event. Use it to de-duplicate, because failed deliveries are retried. |
The platform does not define a timestamp tolerance. We recommend rejecting deliveries whose timestamp is more than 300 seconds from your clock (the official SDKs do this by default). Compare signatures in constant time.
import crypto from "node:crypto";
// rawBody: the request body exactly as received (string or Buffer), never re-serialised JSON.
// timestamp / signature: the X-Webhook-Timestamp and X-Webhook-Signature header values.
function isValid(secret, timestamp, rawBody, signature) {
if (!timestamp || !signature) return false; // header missing
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
if (!Number.isFinite(age) || age > 300) return false; // replay guard
const expected = crypto
.createHmac("sha256", secret)
.update(`${timestamp}.${rawBody}`)
.digest("hex");
const a = Buffer.from(expected);
const b = Buffer.from(signature);
// constant-time compare (lengths must match first)
return a.length === b.length && crypto.timingSafeEqual(a, b);
}import hashlib
import hmac
import time
def is_valid(secret: str, timestamp: str, raw_body: bytes, signature: str) -> bool:
# raw_body: the request body exactly as received (bytes), never re-serialised JSON.
if not timestamp or not signature: # header missing
return False
try:
if abs(time.time() - int(timestamp)) > 300: # replay guard
return False
except ValueError:
return False
expected = hmac.new(
secret.encode(),
timestamp.encode() + b"." + raw_body,
hashlib.sha256,
).hexdigest()
# constant-time compare
return hmac.compare_digest(expected, signature)<?php
// $rawBody: file_get_contents('php://input'), exactly as received, never re-encoded JSON.
// $timestamp / $signature: the X-Webhook-Timestamp and X-Webhook-Signature header values.
function isValid(string $secret, string $timestamp, string $rawBody, string $signature): bool
{
if (!ctype_digit($timestamp) || abs(time() - (int) $timestamp) > 300) {
return false; // replay guard
}
$expected = hash_hmac('sha256', $timestamp . '.' . $rawBody, $secret);
return hash_equals($expected, $signature); // constant-time compare
}import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
// rawBody: the request body exactly as received (bytes), never re-serialised JSON.
// timestamp / signature: the X-Webhook-Timestamp and X-Webhook-Signature header values.
static boolean isValid(String secret, String timestamp, byte[] rawBody, String signature) throws Exception {
long ts;
try {
ts = Long.parseLong(timestamp);
} catch (NumberFormatException e) {
return false;
}
if (Math.abs(System.currentTimeMillis() / 1000 - ts) > 300) return false; // replay guard
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256"));
mac.update((timestamp + ".").getBytes(StandardCharsets.UTF_8));
StringBuilder expected = new StringBuilder();
for (byte b : mac.doFinal(rawBody)) expected.append(String.format("%02x", b));
// constant-time compare
return MessageDigest.isEqual(
expected.toString().getBytes(StandardCharsets.UTF_8),
signature.getBytes(StandardCharsets.UTF_8));
}import (
"crypto/hmac"
"crypto/sha256"
"crypto/subtle"
"encoding/hex"
"strconv"
"time"
)
// rawBody: the request body exactly as received (io.ReadAll), never re-encoded JSON.
// timestamp / signature: the X-Webhook-Timestamp and X-Webhook-Signature header values.
func isValid(secret, timestamp string, rawBody []byte, signature string) bool {
ts, err := strconv.ParseInt(timestamp, 10, 64)
if err != nil {
return false
}
if age := time.Now().Unix() - ts; age > 300 || age < -300 { // replay guard
return false
}
mac := hmac.New(sha256.New, []byte(secret))
mac.Write([]byte(timestamp + "."))
mac.Write(rawBody)
expected := hex.EncodeToString(mac.Sum(nil))
// constant-time compare
return subtle.ConstantTimeCompare([]byte(expected), []byte(signature)) == 1
}using System.Linq;
using System.Security.Cryptography;
using System.Text;
// rawBody: the request body exactly as received (bytes), never re-serialised JSON.
// timestamp / signature: the X-Webhook-Timestamp and X-Webhook-Signature header values.
static bool IsValid(string secret, string timestamp, byte[] rawBody, string signature)
{
if (!long.TryParse(timestamp, out var ts)) return false;
if (Math.Abs(DateTimeOffset.UtcNow.ToUnixTimeSeconds() - ts) > 300) return false; // replay guard
using var hmac = new HMACSHA256(Encoding.UTF8.GetBytes(secret));
var signed = Encoding.UTF8.GetBytes(timestamp + ".").Concat(rawBody).ToArray();
var expected = Convert.ToHexString(hmac.ComputeHash(signed)).ToLowerInvariant();
// constant-time compare
return CryptographicOperations.FixedTimeEquals(
Encoding.UTF8.GetBytes(expected), Encoding.UTF8.GetBytes(signature));
}require 'openssl'
# raw_body: the request body exactly as received (String), never re-serialised JSON.
# timestamp / signature: the X-Webhook-Timestamp and X-Webhook-Signature header values.
def valid?(secret, timestamp, raw_body, signature)
return false unless timestamp.match?(/\A\d+\z/)
return false if (Time.now.to_i - timestamp.to_i).abs > 300 # replay guard
expected = OpenSSL::HMAC.hexdigest('SHA256', secret, "#{timestamp}.#{raw_body}")
return false unless expected.bytesize == signature.bytesize
OpenSSL.fixed_length_secure_compare(expected, signature) # constant-time compare
endPrefer a ready-made helper? The official SDKs verify the signature and parse the event for you: Node.js, Python, PHP, Java, Go, .NET and Ruby.
Event types
Every delivery carries one of these in its payload's coreEventType-derived name.
| Event | Meaning |
|---|---|
order.created | An order was created. |
order.payment_confirmed | Payment for an order was confirmed. |
order.fulfilment_started | Fulfilment of an order has started. |
order.fulfilment_completed | An order finished fulfilling successfully. |
order.failed | An order failed. |
order.cancelled | An order was cancelled. |
order.refund_completed | A refund for an order completed. |
order.document_ready | A generated document (e.g. an e-Stamp certificate) is ready to download. |
Example
order.fulfilment_completed
{
"coreOrderId": "core_order_9f3a1c2b8e4d4a5f",
"coreEventType": "FULFILMENT_COMPLETED",
"occurredAt": "2026-09-25T09:05:00.000Z",
"orderId": "ord_4f5a6b7c8d9e0f1a",
"externalOrderId": "ord_ext_123",
"status": "FULFILMENT_COMPLETED"
}A partner-facing API to self-serve register, list and test your own webhook endpoints (create, rotate secret, delete). Today, webhook endpoints for an organization are configured internally by StampMitra. There is no confirmed public POST /v1/webhooks-style route in the backend yet.