How webhooks work
- A transfer is completed on-chain and indexed by TON Pay.
- TON Pay generates a webhook payload and signs it using HMAC-SHA256 and the optional API key when it is configured.
- TON Pay sends a
POSTrequest to the webhook URL with the signed payload. The request includes theX-TonPay-Signatureheader for verification. - Verify the signature and process the event payload. Return a
2xxstatus code to acknowledge receipt.
Configure the webhook URL
Configure the endpoint in TON Pay Merchant Dashboard.- Open the TON Pay Merchant Dashboard and sign in to the merchant account.
- Navigate to the Developer section, then select Webhooks.
- Enter the webhook URL. In production, the endpoint must use HTTPS. For example,
https://thedomain.com/webhooks/tonpay. - Save the configuration and use the test feature to verify delivery.
Webhook payload
Event types
transfer.completed
Example payloads
Successful transfer:<SENDER_ADDR>- sender wallet address.<RECIPIENT_ADDR>- recipient wallet address.<REFERENCE>- transfer reference returned bycreateTonPayTransfer.<BODY_BASE64_HASH>- Base64 hash of the transfer body.<TX_HASH>- transaction hash.<TRACE_ID>- trace identifier.
Payload fields
string
required
Event type.
transfer.completed indicates that on-chain processing is finished. The transfer may be successful or failed; check data.status for the result.object
required
Transfer details such as amount, addresses, and the transaction hash.
Verify webhook signatures
Every webhook request includes anX-TonPay-Signature header containing an HMAC-SHA256 signature. Verify this signature to ensure the request comes from TON Pay.
Validate webhook requests
Validate fields against the expected transaction data before marking an order as paid.-
Verify the
X-TonPay-Signatureheader and reject invalid requests. -
Verify the event type.
-
Check that the reference matches a transaction created earlier.
-
Verify the amount matches the expected payment amount.
-
Verify the payment currency or token.
-
Check status and process only successful transfers.
-
Prevent duplicate processing using the reference.
Complete validation example
Retry behavior
TON Pay retries failed webhook deliveries.Retry attempts
Up to 3 automatic retries with exponential backoff.
Retry delays
1s, 5s, and 15s.
Delivery outcomes
- Success responses:
2xx. No retry; webhook marked as delivered. - All other responses:
4xx,5xx, or network errors. Automatic retry with exponential backoff.
Best practices
-
Validate the following fields before marking an order as paid:
- Signature: authentication;
- Reference: the transaction exists in the system;
- Amount: the expected payment is matched;
- Asset: correct currency or token;
- Wallet ID: correct receiving wallet;
- Status: the transaction succeeded.
-
Return
2xxonly after successful validation, then process the webhook to avoid timeouts. -
Implement idempotency. Webhooks may be delivered more than once. Use the
referencefield to prevent duplicate processing. -
Log all webhook attempts. Log each request for debugging and security auditing.
- To receive webhooks in production, ensure corresponding endpoints use HTTPS. Regular HTTP endpoints would be ignored by TON Pay.
- Monitor delivery failures. Set up alerts and review webhook delivery logs in the Merchant Dashboard
-
Store transaction hashes. Save
txHashto support on-chain verification for disputes.
Troubleshooting
If webhooks are not received
If webhooks are not received
- Verify the webhook URL configured in the Merchant Dashboard.
- Ensure the endpoint is publicly reachable and not blocked by a firewall.
- Use the dashboard test feature to send a sample webhook.
- Review webhook attempt logs in the Merchant Dashboard.
- Ensure the endpoint returns a
2xxstatus code for valid requests. - Ensure the endpoint responds within 10 seconds to avoid timeouts.
If signature verification fails
If signature verification fails
- Use the optional API key from the Merchant Dashboard at Developer → API when webhook signing is configured.
- Compute the HMAC over the raw JSON string.
- Do not modify the request body before verification.
- Verify the header name is
x-tonpay-signaturein lowercase. - Use the
HMAC-SHA256algorithm. - Ensure the signature value starts with
sha256=.
If amount or asset mismatch, possible causes include
If amount or asset mismatch, possible causes include
- Wrong order lookup or reference mapping.
- Price changed after order creation.
- Currency mismatch between order and transfer.
- Potential attack or spoofed request.
If duplicate webhook processing
If duplicate webhook processing
- Implement idempotency using the
referencefield. - Use database transactions to prevent race conditions.
- Check order status before processing.
If timeout errors occur
If timeout errors occur
- Respond within 10 seconds.
- Process webhooks asynchronously after quick validation.
- Return
2xxafter validation passes.
Next steps
Build a transfer
Create a TON Pay transfer message.
Check status and retrieve info
Query transfer status and details.