Skip to main content
TON Pay uses webhooks to notify applications in real-time about transfer events.

How webhooks work

  1. A transfer is completed on-chain and indexed by TON Pay.
  2. TON Pay generates a webhook payload and signs it using HMAC-SHA256 and the optional API key when it is configured.
  3. TON Pay sends a POST request to the webhook URL with the signed payload. The request includes the X-TonPay-Signature header for verification.
  4. Verify the signature and process the event payload. Return a 2xx status code to acknowledge receipt.

Configure the webhook URL

Configure the endpoint in TON Pay Merchant Dashboard.
  1. Open the TON Pay Merchant Dashboard and sign in to the merchant account.
  2. Navigate to the Developer section, then select Webhooks.
  3. Enter the webhook URL. In production, the endpoint must use HTTPS. For example, https://thedomain.com/webhooks/tonpay.
  4. Save the configuration and use the test feature to verify delivery.

Webhook payload

Event types

transfer.completed

Example payloads

Successful transfer:
Failed transfer:
Placeholders:
  • <SENDER_ADDR> - sender wallet address.
  • <RECIPIENT_ADDR> - recipient wallet address.
  • <REFERENCE> - transfer reference returned by createTonPayTransfer.
  • <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.
string
required
ISO 8601 timestamp indicating when the event occurred.
object
required
Transfer details such as amount, addresses, and the transaction hash.

Verify webhook signatures

Every webhook request includes an X-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.
  1. Verify the X-TonPay-Signature header and reject invalid requests.
  2. Verify the event type.
  3. Check that the reference matches a transaction created earlier.
  4. Verify the amount matches the expected payment amount.
  5. Verify the payment currency or token.
  6. Check status and process only successful transfers.
  7. 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 2xx only after successful validation, then process the webhook to avoid timeouts.
  • Implement idempotency. Webhooks may be delivered more than once. Use the reference field 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 txHash to support on-chain verification for disputes.

Troubleshooting

  1. Verify the webhook URL configured in the Merchant Dashboard.
  2. Ensure the endpoint is publicly reachable and not blocked by a firewall.
  3. Use the dashboard test feature to send a sample webhook.
  4. Review webhook attempt logs in the Merchant Dashboard.
  5. Ensure the endpoint returns a 2xx status code for valid requests.
  6. Ensure the endpoint responds within 10 seconds to avoid timeouts.
  1. Use the optional API key from the Merchant Dashboard at DeveloperAPI when webhook signing is configured.
  2. Compute the HMAC over the raw JSON string.
  3. Do not modify the request body before verification.
  4. Verify the header name is x-tonpay-signature in lowercase.
  5. Use the HMAC-SHA256 algorithm.
  6. Ensure the signature value starts with sha256=.
  1. Wrong order lookup or reference mapping.
  2. Price changed after order creation.
  3. Currency mismatch between order and transfer.
  4. Potential attack or spoofed request.
  1. Implement idempotency using the reference field.
  2. Use database transactions to prevent race conditions.
  3. Check order status before processing.
  1. Respond within 10 seconds.
  2. Process webhooks asynchronously after quick validation.
  3. Return 2xx after validation passes.

Next steps

Build a transfer

Create a TON Pay transfer message.

Check status and retrieve info

Query transfer status and details.