Webhooks
Cryptonly sends a webhook to your server on every status change of an invoice, deposit, or withdrawal, not only when it reaches a final status. Each webhook is signed with HMAC-SHA256 so you can verify it came from Cryptonly.
How webhooks are sent
Section titled “How webhooks are sent”HTTP contract
Section titled “HTTP contract”| Item | Value |
|---|---|
| Method | POST |
| Content type | application/json |
| Signature header | x-webhook-signature |
| Signature format | Lowercase hex string |
| Encoding | UTF-8 JSON body |
| Redirects | Not followed |
Request headers:
| Header | Value |
|---|---|
Content-Type | application/json |
User-Agent | Cryptonly-Webhooks/1 |
x-webhook-id | Delivery id (UUID). The same on every attempt of one delivery, including retries and manual resends |
x-webhook-timestamp | Unix time in seconds when this attempt was sent |
x-webhook-event | Event name, the same as event in the body |
x-webhook-signature | HMAC-SHA256 of the raw body. |
The timestamp field in the body is set when each attempt is sent, so a retry carries a newer timestamp and a different signature than the attempt before it.
Supported webhook events
Section titled “Supported webhook events”Cryptonly sends a signed webhook whenever a resource status changes.
| Event | When Cryptonly sends it |
|---|---|
invoice.statusChanged | On invoice create (initial created) and on every subsequent status transition |
deposit.statusChanged | On each status transition of a standalone deposit (not on initial create) |
withdrawal.statusChanged | On each post-commit status transition; the first webhook typically arrives when the withdrawal moves to processing |
Deposit webhooks are not sent when a deposit is linked to an invoice (invoiceId is set). For invoice checkout payments, listen for invoice.statusChanged instead.
Payload
Section titled “Payload”Every webhook body has the same envelope: the event name, the signed timestamp (ISO 8601), and data, the resource as the API returns it plus previousStatus. An invoice.statusChanged body looks like this:
{ "event": "invoice.statusChanged", "timestamp": "2026-01-01T12:00:00.000Z", "data": { "id": "8f0c2d4e-1b7a-4c1e-9d3f-2a6b5c7d8e90", "accountId": "3a1b2c3d-4e5f-4a6b-8c7d-9e0f1a2b3c4d", "orderId": "order_1001", "status": "paid", "previousStatus": "processing", "amount": 25, "fiatCurrencyCode": "USD", "cryptoCurrencyCode": "USDT_TRC20", "cryptoAmountExpected": 25.42, "cryptoAmountReceived": 25.42, "address": "TXYZ...", "txHash": "a1b2c3...", "settlement": { "amountPaid": 25.42, "commissionAmount": 0.25, "netAmount": 24.75, "completedAt": "2026-01-01T12:00:00.000Z" }, "paymentPageUrl": "https://...", "expiresAt": "2026-01-02T11:40:00.000Z", "createdAt": "2026-01-01T11:40:00.000Z" }}The example is shortened. See the OpenAPI reference for every field of invoice.statusChanged, deposit.statusChanged, and withdrawal.statusChanged.
Webhook URLs
Section titled “Webhook URLs”Each webhook goes to the webhookUrl from the create request (or, for withdrawals, the commit request). Without one, Cryptonly uses the organization default for that resource type, which you set under Settings → Integration. If neither is set, no webhook is sent.


Signing keys
Section titled “Signing keys”Getting your webhook signing key
Section titled “Getting your webhook signing key”Each account has its own webhook signing key. The Webhook signing key section on the account’s Security page shows a fingerprint of the current key. Members with the Owner, Admin or Developer role can rotate the key.


How to obtain the key
- Open the Cryptonly Merchant Dashboard.
- Go to Accounts and select the account.
- Open the Settings tab, then Security.
- Find the Webhook signing key section.
- Click Rotate key.
- Confirm the rotation.
- Copy the new signing key immediately.
- Store it in your server environment variables.
CRYPTONLY_WEBHOOK_SECRET=your_signing_key_hereVerifying webhooks
Section titled “Verifying webhooks”Signature format
Section titled “Signature format”The x-webhook-signature header is HMAC-SHA256(rawBody, webhookSigningKey) as a lowercase hex string, where rawBody is the exact raw UTF-8 bytes of the request body and webhookSigningKey is the signing key of the account the resource belongs to.
Compute the signature over the body exactly as received. Parsing and re-serializing the JSON first changes the bytes and breaks verification.
Recommended verification flow
Section titled “Recommended verification flow”Your webhook endpoint should follow this order:
- Receive the webhook request.
- Read the raw request body.
- Read the
x-webhook-signatureheader. - Calculate the expected signature using your webhook signing key.
- Compare signatures using a timing-safe comparison.
- Reject invalid signatures with
401 Unauthorized. - Parse the JSON body only after signature verification succeeds.
- Optionally validate timestamp and deduplicate the event.
- Process the webhook.
- Return a
2xxresponse.
Verify a webhook
Section titled “Verify a webhook”If you use the Cryptonly SDK, you can verify invoice, deposit, and withdrawal webhooks with helper functions.
import { verifyInvoiceWebhook, verifyWithdrawalWebhook, verifyDepositWebhook,} from '@cryptonly/sdk';
import type { Request, Response } from 'express';
export function cryptonlyWebhookHandler(req: Request, res: Response) { const rawBody = req.body as Buffer; const signature = req.headers['x-webhook-signature']; const secret = process.env.CRYPTONLY_WEBHOOK_SECRET;
if (!secret) { return res.status(500).json({ error: 'webhook secret is not configured', }); }
const signatureHeader = typeof signature === 'string' ? signature : undefined;
const invoiceResult = verifyInvoiceWebhook( rawBody, signatureHeader, secret, );
if (invoiceResult.ok) { const { event, data, timestamp } = invoiceResult.envelope;
// Handle invoice.statusChanged. // Optional: validate timestamp. // Optional: deduplicate event.
return res.status(200).json({ received: true }); }
const withdrawalResult = verifyWithdrawalWebhook( rawBody, signatureHeader, secret, );
if (withdrawalResult.ok) { const { event, data, timestamp } = withdrawalResult.envelope;
// Handle withdrawal.statusChanged. // Optional: validate timestamp. // Optional: deduplicate event.
return res.status(200).json({ received: true }); }
const depositResult = verifyDepositWebhook( rawBody, signatureHeader, secret, );
if (depositResult.ok) { const { event, data, timestamp } = depositResult.envelope;
// Handle deposit.statusChanged. // Optional: validate timestamp. // Optional: deduplicate event.
return res.status(200).json({ received: true }); }
return res.status(401).json({ error: 'webhook verification failed', });}Use express.raw() for the webhook route so you can verify the exact raw request body.
import { createHmac, timingSafeEqual } from 'node:crypto';import express from 'express';
const app = express();
function verifyCryptonlySignature( rawBody: Buffer, signatureHeader: string | undefined, secret: string,): boolean { if (!signatureHeader || signatureHeader.trim() === '') { return false; }
const expectedHex = createHmac('sha256', secret) .update(rawBody) .digest('hex');
const expected = expectedHex.toLowerCase(); const received = signatureHeader.trim().toLowerCase();
if (expected.length !== received.length || expected.length % 2 !== 0) { return false; }
try { return timingSafeEqual( Buffer.from(expected, 'hex'), Buffer.from(received, 'hex'), ); } catch { return false; }}
app.post( '/webhooks/cryptonly', express.raw({ type: 'application/json' }), (req, res) => { const rawBody = req.body as Buffer; const signature = req.headers['x-webhook-signature']; const secret = process.env.CRYPTONLY_WEBHOOK_SECRET;
if (!secret) { return res.status(500).send('webhook secret is not configured'); }
const isValid = verifyCryptonlySignature( rawBody, typeof signature === 'string' ? signature : undefined, secret, );
if (!isValid) { return res.status(401).send('invalid signature'); }
const webhook = JSON.parse(rawBody.toString('utf8')) as { event: string; data: unknown; timestamp: string; };
// Optional: validate webhook.timestamp for replay protection. // Optional: deduplicate by req.headers['x-webhook-id'].
switch (webhook.event) { case 'invoice.statusChanged': // Handle invoice status update. break;
case 'withdrawal.statusChanged': // Handle withdrawal status update. break;
case 'deposit.statusChanged': // Handle deposit status update. break;
default: // Unknown event type. break; }
return res.status(200).send('ok'); },);Read the raw request body before parsing JSON. In Flask, use request.get_data().
import hashlibimport hmacimport jsonimport os
from flask import Flask, request
app = Flask(__name__)
def verify_cryptonly_signature( raw_body: bytes, signature_header: str | None, secret: str,) -> bool: if signature_header is None or signature_header.strip() == "": return False
expected = hmac.new( secret.encode("utf-8"), raw_body, hashlib.sha256, ).hexdigest() received = signature_header.strip().lower()
if len(expected) != len(received): return False
return hmac.compare_digest(expected, received)
@app.post("/webhooks/cryptonly")def cryptonly_webhook(): raw_body = request.get_data() signature = request.headers.get("x-webhook-signature") secret = os.environ.get("CRYPTONLY_WEBHOOK_SECRET")
if not secret: return "webhook secret is not configured", 500
if not verify_cryptonly_signature(raw_body, signature, secret): return "invalid signature", 401
webhook = json.loads(raw_body.decode("utf-8"))
# Optional: validate webhook["timestamp"] for replay protection. # Optional: deduplicate by request.headers.get("x-webhook-id").
event = webhook.get("event")
if event == "invoice.statusChanged": # Handle invoice status update. pass elif event == "withdrawal.statusChanged": # Handle withdrawal status update. pass elif event == "deposit.statusChanged": # Handle deposit status update. pass
return "ok", 200Read r.Body before unmarshalling JSON so you verify the exact raw request body.
package main
import ( "crypto/hmac" "crypto/sha256" "encoding/hex" "encoding/json" "io" "net/http" "os" "strings")
func verifyCryptonlySignature(rawBody []byte, signatureHeader, secret string) bool { signatureHeader = strings.TrimSpace(signatureHeader) if signatureHeader == "" { return false }
mac := hmac.New(sha256.New, []byte(secret)) mac.Write(rawBody) expected := hex.EncodeToString(mac.Sum(nil)) received := strings.ToLower(signatureHeader)
if len(expected) != len(received) { return false }
return hmac.Equal([]byte(expected), []byte(received))}
func cryptonlyWebhook(w http.ResponseWriter, r *http.Request) { rawBody, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "invalid body", http.StatusBadRequest) return }
secret := os.Getenv("CRYPTONLY_WEBHOOK_SECRET") if secret == "" { http.Error(w, "webhook secret is not configured", http.StatusInternalServerError) return }
signature := r.Header.Get("X-Webhook-Signature") if !verifyCryptonlySignature(rawBody, signature, secret) { http.Error(w, "invalid signature", http.StatusUnauthorized) return }
var webhook struct { Event string `json:"event"` Data json.RawMessage `json:"data"` Timestamp string `json:"timestamp"` } if err := json.Unmarshal(rawBody, &webhook); err != nil { http.Error(w, "invalid json", http.StatusBadRequest) return }
// Optional: validate webhook.Timestamp for replay protection. // Optional: deduplicate by r.Header.Get("X-Webhook-Id").
switch webhook.Event { case "invoice.statusChanged": // Handle invoice status update. case "withdrawal.statusChanged": // Handle withdrawal status update. case "deposit.statusChanged": // Handle deposit status update. }
w.WriteHeader(http.StatusOK) _, _ = w.Write([]byte("ok"))}
func main() { http.HandleFunc("/webhooks/cryptonly", cryptonlyWebhook) http.ListenAndServe(":8080", nil)}Read php://input so you verify the exact raw request body.
<?php
function verify_cryptonly_signature(string $rawBody, ?string $signatureHeader, string $secret): bool{ if ($signatureHeader === null || trim($signatureHeader) === '') { return false; }
$expected = hash_hmac('sha256', $rawBody, $secret); $received = strtolower(trim($signatureHeader));
if (strlen($expected) !== strlen($received)) { return false; }
return hash_equals($expected, $received);}
$rawBody = file_get_contents('php://input');$signature = $_SERVER['HTTP_X_WEBHOOK_SIGNATURE'] ?? null;$secret = getenv('CRYPTONLY_WEBHOOK_SECRET');
if (!is_string($secret) || $secret === '') { http_response_code(500); echo 'webhook secret is not configured'; exit;}
if (!is_string($rawBody) || !verify_cryptonly_signature($rawBody, $signature, $secret)) { http_response_code(401); echo 'invalid signature'; exit;}
$webhook = json_decode($rawBody, true);
// Optional: validate $webhook['timestamp'] for replay protection.// Optional: deduplicate by $_SERVER['HTTP_X_WEBHOOK_ID'] ?? null.
switch ($webhook['event'] ?? '') { case 'invoice.statusChanged': // Handle invoice status update. break;
case 'withdrawal.statusChanged': // Handle withdrawal status update. break;
case 'deposit.statusChanged': // Handle deposit status update. break;}
http_response_code(200);echo 'ok';Read the request body bytes before parsing JSON. This example uses the JDK HTTP server and Jackson.
import com.fasterxml.jackson.databind.JsonNode;import com.fasterxml.jackson.databind.ObjectMapper;import com.sun.net.httpserver.HttpExchange;import com.sun.net.httpserver.HttpServer;
import javax.crypto.Mac;import javax.crypto.spec.SecretKeySpec;import java.io.IOException;import java.net.InetSocketAddress;import java.nio.charset.StandardCharsets;import java.security.GeneralSecurityException;import java.security.MessageDigest;import java.util.HexFormat;
public class CryptonlyWebhook { private static final ObjectMapper JSON = new ObjectMapper();
static boolean verifyCryptonlySignature(byte[] rawBody, String signatureHeader, String secret) { if (signatureHeader == null || signatureHeader.isBlank()) { return false; }
try { Mac mac = Mac.getInstance("HmacSHA256"); mac.init(new SecretKeySpec(secret.getBytes(StandardCharsets.UTF_8), "HmacSHA256")); byte[] expected = mac.doFinal(rawBody); byte[] received = HexFormat.of().parseHex(signatureHeader.trim()); return MessageDigest.isEqual(expected, received); } catch (GeneralSecurityException | IllegalArgumentException e) { return false; } }
static void handle(HttpExchange exchange) throws IOException { if (!"POST".equalsIgnoreCase(exchange.getRequestMethod())) { send(exchange, 405, "method not allowed"); return; }
byte[] rawBody = exchange.getRequestBody().readAllBytes(); String secret = System.getenv("CRYPTONLY_WEBHOOK_SECRET"); if (secret == null || secret.isEmpty()) { send(exchange, 500, "webhook secret is not configured"); return; }
String signature = exchange.getRequestHeaders().getFirst("X-Webhook-Signature"); if (!verifyCryptonlySignature(rawBody, signature, secret)) { send(exchange, 401, "invalid signature"); return; }
JsonNode webhook = JSON.readTree(rawBody); String event = webhook.path("event").asText();
// Optional: validate webhook.path("timestamp") for replay protection. // Optional: deduplicate by exchange.getRequestHeaders().getFirst("X-Webhook-Id").
switch (event) { case "invoice.statusChanged" -> { // Handle invoice status update. } case "withdrawal.statusChanged" -> { // Handle withdrawal status update. } case "deposit.statusChanged" -> { // Handle deposit status update. } default -> { } }
send(exchange, 200, "ok"); }
private static void send(HttpExchange exchange, int status, String body) throws IOException { byte[] bytes = body.getBytes(StandardCharsets.UTF_8); exchange.sendResponseHeaders(status, bytes.length); exchange.getResponseBody().write(bytes); exchange.close(); }
public static void main(String[] args) throws IOException { HttpServer server = HttpServer.create(new InetSocketAddress(8080), 0); server.createContext("/webhooks/cryptonly", CryptonlyWebhook::handle); server.start(); }}Delivery
Section titled “Delivery”Delivery behavior and retries
Section titled “Delivery behavior and retries”Cryptonly expects your server to respond with a successful 2xx status code.
| Behavior | Description |
|---|---|
| Success | Any 2xx response is treated as successful |
| Failure | Non-2xx responses, including 3xx redirects, are treated as failed |
| Timeout | Webhook delivery has a 10-second timeout |
| Invalid signature | Your server should return 401 Unauthorized |
| Retry policy | Cryptonly makes up to 15 delivery attempts in total |
| Retry delay | Retries use exponential backoff starting from 20 seconds |
| Not retried | An invalid URL, or a URL that resolves to a private or reserved address |
If your endpoint is temporarily unavailable, Cryptonly will retry delivery automatically.
The retry delay grows after each failed attempt. In practice, this means retries are spaced out approximately like this:
| Retry | Approximate delay after previous failed attempt |
|---|---|
| 1st retry | 20 seconds |
| 2nd retry | 40 seconds |
| 3rd retry | 80 seconds |
| 4th retry | about 2.7 minutes (160 seconds) |
| 5th retry | about 5.3 minutes (320 seconds) |
| 6th retry | about 10.7 minutes (640 seconds) |
| 7th retry | about 21 minutes (1,280 seconds) |
| 8th retry | about 43 minutes (2,560 seconds) |
| 9th retry | about 85 minutes (5,120 seconds) |
| 10th retry | about 2.8 hours (10,240 seconds) |
| 11th retry | about 5.7 hours (20,480 seconds) |
| 12th retry | about 11.4 hours (40,960 seconds) |
| 13th retry | about 22.8 hours (81,920 seconds) |
| 14th retry | about 45.5 hours (163,840 seconds) |
With 15 total attempts, that is 1 initial delivery plus up to 14 retries. The last retry happens about 3 days 19 hours after the first attempt. After that the delivery is marked failed, and a member with the Owner, Admin or Developer role can still resend it from the delivery log.
Your handler should avoid long-running processing before responding. If needed, store the event and process it asynchronously.
Webhook delivery log and manual resend
Section titled “Webhook delivery log and manual resend”Every webhook Cryptonly sends is listed in the Cryptonly Merchant Dashboard under Webhooks, Settings → Integration → Webhook delivery log, and View deliveries on a transaction.
Each entry shows the event, resource, endpoint URL, and status (pending, retrying, succeeded shown as Delivered, or failed), plus every attempt’s request and response. Filter by status, event, resource type, or date, and search by x-webhook-id, resource id, or orderId.
Members with the Owner, Admin or Developer role can Resend now a failed or succeeded delivery. The resend uses the recorded URL, the same x-webhook-id and data, the current signing key, and a new timestamp. A delivery that is still retrying cannot be resent until it finishes.




Duplicate events and replay protection
Section titled “Duplicate events and replay protection”See Idempotency.
Going live
Section titled “Going live”Security checklist
Section titled “Security checklist”Before going live, make sure that:
- your webhook URL uses HTTPS;
- your server verifies
x-webhook-signature; - invalid signatures are rejected with
401 Unauthorized; - verification uses the raw request body;
- signature comparison is timing-safe;
- the webhook signing key is stored securely;
- replay protection or event deduplication is implemented;
- webhook processing is idempotent;
- test webhooks from Settings → Integration → Test webhooks pass. See Testing your integration.