Tylt: API Documentation
  • Introduction
    • Introduction
    • Getting Started
    • Generating API Keys
    • Signing API Payloads
    • Important Concepts
    • Merchant Verification
    • Tylt Prime (UPI to Crypto Solution)
      • API Reference
        • Create a Pay-in Instance
        • Create a Pay-out Instance
        • Webhook for Tylt Prime
        • Get Instance Information
        • Get Pay-In Transaction Information
        • Get Pay-Out Transaction Information
    • Tylt Prime (UPI to Crypto Solution - H2H)
      • API Reference ( Pay-In)
        • Create a Pay-in Instance
        • Buyer Confirms Payment
        • Webhook for Tylt Prime
        • Get Instance Details
        • Get Pay-In Transaction Information
        • Get List of Fiat Currency and Supported Payment Methods
        • Get List of Supported Crypto Currency for Settlement
        • Get Conversion Rates
  • Tylt CPG (Crypto Payment Gateway)
    • API Reference
      • Accept Crypto Payments
        • Creating a Pay-in Request
        • Get Pay-In Transaction History
        • Get Pay-In Transaction Information
      • Make Crypto Payouts
        • Creating a Payout Request
        • Get Pay-Out Transaction History
        • Get Pay-Out Transaction Information
      • Supporting API's
        • Get Supported Crypto Currencies List
        • Get Supported Fiat Currencies
        • Get Account Balance / Holdings
        • Get Supported Crypto Networks
        • Supported Base Currency List
      • Webhook
    • Use Cases
      • E-commerce Flow
      • Withdrawal Flow
Powered by GitBook
On this page
  1. Tylt CPG (Crypto Payment Gateway)
  2. API Reference

Webhook

Overview

Tylt provides a webhook mechanism for merchants to receive real-time updates on the status of their transactions, whether for pay-ins. Merchants can specify a callBackUrl in their API requests, and Tylt will send notifications to this URL whenever there is a status change in the transaction.

Setting Up the Webhook

  1. Implement a Callback Endpoint: Merchants must set up an HTTP POST endpoint that can receive JSON payloads. This endpoint should be capable of processing the incoming webhook data and verifying its authenticity using HMAC-SHA256 signature validation.

  2. Insert the Callback URL: During a pay-in request, insert your endpoint URL in the callBackUrl field. Tylt will send updates to this URL whenever the transaction status changes.

  3. Status Updates: When a transaction status changes to Waiting, Confirming, Paid, Failed, or Expired, Tylt will send a JSON payload with the updated status.

  4. Callback Validation: To ensure the integrity and authenticity of the callback, Tylt signs each callback payload using HMAC-SHA256 with the merchant’s API secret key. This signature is sent in the HTTP header X-TLP-SIGNATURE.

  5. Acknowledge the Callback: Upon receiving the callback, merchants must respond with an HTTP 200 status code and the text "ok" in the response body. This acknowledges the successful receipt of the callback. If the acknowledgment is not received, the webhook will not be retried automatically. Merchants can manually resend webhooks from their Tylt dashboard.

Validating Callbacks

Merchants should validate the HMAC signature included in the X-TLP-SIGNATURE header to ensure the callback is from Tylt and has not been tampered with. The HMAC signature is generated using the raw POST data and the MERCHANT_API_SECRET as the shared key.

Example Web-hook Handling Code

const express = require('express');
const crypto = require('crypto');

const app = express();
const PORT = 3000;
const apiSecretKey = 'YOUR_TLP_API_SECRET_KEY'; // Replace with your actual API secret key

// Middleware to parse incoming JSON requests
app.use(express.json());

// Callback endpoint
app.post('/callback', (req, res) => {
    const data = req.body;

    // Calculate HMAC signature
    const tlpSignature = req.headers['x-tlp-signature'];
    const calculatedHmac = crypto
        .createHmac('sha256', apiSecretKey)
        .update(JSON.stringify(data)) // Use raw body string for HMAC calculation
        .digest('hex');

    if (calculatedHmac === tlpSignature) {
        // Signature is valid
        if (data.type === 'pay-in') {
            console.log('Received pay-in callback:', data);
            // Process pay-in data here
        } 
        // Return HTTP Response 200 with content "ok"
        res.status(200).send('ok');
    } else {
        // Invalid HMAC signature
        res.status(400).send('Invalid HMAC signature');
    }
});

// Start the server
app.listen(PORT, () => {
    console.log(`Server listening on port ${PORT}`);
});
from flask import Flask, request, jsonify
import hmac
import hashlib
import json

app = Flask(__name__)

# Your TL Pay API Secret Key
TLP_API_SECRET_KEY = 'YOUR_TLP_API_SECRET_KEY'  # Replace with your actual API secret key

@app.route('/callback', methods=['POST'])
def callback():
    # Get the raw request data for HMAC calculation
    raw_data = json.dumps(request.get_json(), separators=(',', ':'), ensure_ascii=False)

    # Parse JSON data from the request
    data = request.get_json()
    
    # Retrieve the signature from the request headers
    tlp_signature = request.headers.get('X-TLP-SIGNATURE')

    # Calculate the HMAC SHA-256 signature
    calculated_hmac = hmac.new(
        key=TLP_API_SECRET_KEY.encode(),
        msg=raw_data,
        digestmod=hashlib.sha256
    ).hexdigest()

    # Compare the calculated HMAC signature with the one in the request header
    if hmac.compare_digest(calculated_hmac, tlp_signature):
        # Signature is valid
        if data['type'] == 'pay-in':
            print('Received pay-in callback:', data)
            # Process pay-in data here
            
        # Return HTTP Response 200 with content "ok"
        return jsonify({"message": "ok"}), 200
    else:
        # Invalid HMAC signature
        return jsonify({"error": "Invalid HMAC signature"}), 400

if __name__ == '__main__':
    app.run(port=3000, debug=True)

Again, please note that these code snippets serve as examples and may require modifications based on your specific implementation and framework.

Example of Web-hook Responses

{
  "data": {
    "orderId": "sample-id-1", // an id like ajdng-adgh-1433-adad
    "merchantOrderId": "sample-id-2", // an id like ajdng-adgh-1433-adad
    "baseAmount": 10,
    "baseCurrency": "USDT",
    "settledCurrency": "USDT",
    "settledAmountRequested": 10,
    "settledAmountReceived": 10,
    "settledAmountCredited": 9.9,
    "commission": 0.1,
    "network": "BSC",
    "depositAddress": "address", // a crypto wallet address
    "status": "Completed",
    "paymentURL": "https://app.tylt.money/pscreen/sample-id-1", // sample-id-1 is the orderId above
    "callBackURL": "https://www.domain.com/your_callback_url", // your url where this callback data is sent
    "transactions": [
      {
        "fromAddress": "address", // a crypto wallet address
        "transactionHash": "txn_hash", // a crypto transaction hash
        "amount": 10,
        "confirmationStatus": 1,
        "createdAt": "2024-11-06T19:00:29Z",
        "updatedAt": "2024-11-06T19:01:21Z"
      }
    ],
    "createdAt": "2024-11-06T18:54:44Z",
    "expiresAt": "2024-11-06T19:54:44Z",
    "updatedAt": "2024-11-06T19:01:21Z",
    "isFinal": 1,
    "isCredited": 1,
    "customerName": "",
    "comments": "",
    "accounts" = {
    rate: 90, // for transaction where a fiat equivalent crypto is required
    cryptoReceived: 10,
    equivalentFiat: 900,// for transaction where a fiat equivalent crypto is required
    }
}
  },
  "type": "pay-in"
}

Again, please note that these response snippets serve as examples and may require modifications based on your specific implementation and framework.

{
  "data": {
    "orderId": "sample-id-1", // an id like ajdng-adgh-1433-adad
    "merchantOrderId": "sample-id-2", // an id like ajdng-adgh-1433-adad
    "settledCurrency": "USDT",
    "settledAmountRequested": 10,
    "settledAmountDebited": 10,
    "settledAmountSent": 9.9,
    "commission": 0.1,
    "network": "BSC",
    "toAddress": "address", // a crypto wallet address
    "status": "Completed",
    "insufficientBalance": 0,
    "paymentURL": "", // sample-id-1 is the orderId above
    "callBackURL": "", // your url where this callback data is sent
    "transactions": [
      {
        "fromAddress": "address", // a crypto wallet address
        "transactionHash": "txn_hash", // a crypto transaction hash
        "amount": 10,
        "confirmationStatus": 1,
        "createdAt": "2024-11-06T19:00:29Z",
        "updatedAt": "2024-11-06T19:01:21Z"
      }
    ],
    "createdAt": "2024-11-06T18:54:44Z",
    "expiresAt": "2024-11-06T19:54:44Z",
    "updatedAt": "2024-11-06T19:01:21Z",
    "isFinal": 1,
    "isDebited": 1,
    "customerName": "",
    "comments": ""
  },
  "type": "pay-out"
}

Again, please note that these response snippets serve as examples and may require modifications based on your specific implementation and framework.

Important Considerations

  • Security: Always verify the X-TLP-SIGNATURE header to ensure the callback originates from Tylt.

  • Response: Always return an HTTP 200 response with "ok" in the body to acknowledge successful receipt of the webhook.

  • Manual Retry: In case of missed callbacks, use the tylt.monry dashboard to manually resend the webhook.

PreviousSupported Base Currency ListNextUse Cases

Last updated 1 month ago