Skip to content

Webhook Technical Documentation

Method

Method: POST
json
{
'Content-Type: application/json',
'secret-key: secret-key'
}

POST Parameters

json
{
  "payload": [
    {
      "transactionId": "de3148d3-22fe-4d97-8f10-d98b008c5e4a",
      "walletId": "06a9044c-86b3-4bb4-acee-33cc4f1683c3",
      "address": "0x4035bb59573acf9ff6c428667f3b1f4af7d68a80",
      "merchantId": "75ff4eff-164c-4b13-adde-1118f8277a54",
      "paymentMethodId": "b2f26627-adbe-4233-99bd-bd547f754af6",
      "orderId": "ORD121212",
      "txHash": "0x56074abb9a7fdf298176d553b2c4119a786c6da5017a35749a076bd55220e8e1",
      "transactionDate": "2025-02-21T04:12:04.564Z",
      "amount": 30.5
    }
  ]
}

Sample Code

js
import { Controller, ForbiddenException, Post, Req } from '@nestjs/common';
import { DepositService } from './deposit.service';
import { ConfigService } from '@nestjs/config';

@Controller('webhook')
export class DepositController {
    constructor(private readonly depositService: DepositService,
        private readonly configService: ConfigService,
    ) { }
  // Define POST endpoint at /webhook
  @Post()
  async handleDeposit(@Req() req: any): Promise<boolean> {
    // Get raw data from request body
    const rawData = req.body;

    // Create payload containing transaction information from raw data
    const payload = {
      transactionId: rawData.transactionId,                // Transaction ID
      walletId: rawData.walletId,                    // Wallet ID
      address: rawData.address, // Receiving address
      merchantId: rawData.merchantId, // Merchant ID
      paymentMethodId: rawData.paymentMethodId,              // Payment method ID
      orderId: rawData.orderId,                // Order ID
      txHash: rawData.txHash,                  // Blockchain transaction hash
      transactionDate: rawData.transactionDate,              // Transaction date
      amount: rawData.amount,              // Transaction amount
    };

    // Get secret key from request header
    const secretKey = req.headers['secret-key'];
    // Get correct secret key value from config file
    const expectedKey = this.configService.get<string>('WEBHOOK_SECRET_KEY');

    // Check if request secret key matches configured secret key
    if (secretKey !== expectedKey) {
      // If not matching, throw ForbiddenException
      throw new ForbiddenException('Invalid secret key');
    }

    // Use payload to process according to your system
    console.log(payload)

    // Return true if processing is successful
    return true;
  }
}