API Overview

Welcome to TG Wallet API documentation. This API allows you to create payment links and process internal payouts.

Features

  • 🔗 Payment Link Creation: Create secure payment links for your customers
  • 💰 Internal Payouts: Send payments to other users within the system
  • 🔐 Secure Authentication: API key based authentication
  • 📊 Real-time Rates: Live cryptocurrency exchange rates
  • 🔔 Webhook Support: Receive payment notifications via callbacks

Authentication

All API requests require authentication using an API key in the request headers.

API Key Authentication

Include your API key in the request headers:

Header Value Description
api-key your_api_key_here Your unique API key for authentication
// Example: Adding API key to headers
const headers = {
    'api-key': 'your_api_key_here',
    'Content-Type': 'application/json'
};

fetch('https://your-domain.com/api/create-payment-link/', {
    method: 'POST',
    headers: headers,
    body: JSON.stringify({
        amount: '10.00',
        callback_url: 'https://your-site.com/webhook'
    })
});
// Example: Adding API key to headers
$headers = [
    'api-key: your_api_key_here',
    'Content-Type: application/json'
];

$data = [
    'amount' => '10.00',
    'callback_url' => 'https://your-site.com/webhook'
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://your-domain.com/api/create-payment-link/');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);
curl_close($ch);
# Example: Adding API key to headers
import requests

headers = {
    'api-key': 'your_api_key_here',
    'Content-Type': 'application/json'
}

data = {
    'amount': '10.00',
    'callback_url': 'https://your-site.com/webhook'
}

response = requests.post(
    'https://your-domain.com/api/create-payment-link/',
    headers=headers,
    json=data
)

Internal Payout

Send payments to other users within the TG Wallet system.

POST /api/payout/
Send internal payouts to any specified currency with fee deduction.

Request Headers

Header Type Required Description
api-key string Yes Your API key for authentication
Content-Type string Yes application/json

Request Parameters

Parameter Type Required Description
amount string Yes Amount to send (e.g., "1.5")
address string Yes Recipient's UID (user identifier)
currency_code string Yes Currency code (e.g., "USDT", "BTC", "ETH")

Code Examples

const sendPayout = async () => {
    const response = await fetch('https://your-domain.com/api/payout/', {
        method: 'POST',
        headers: {
            'api-key': 'your_api_key_here',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            amount: '10.0',
            address: 'recipient_uid_123',
            currency_code: 'USDT'
        })
    });
    
    const data = await response.json();
    console.log(data);
};

sendPayout();
$url = 'https://your-domain.com/api/payout/';
$data = [
    'amount' => '10.0',
    'address' => 'recipient_uid_123',
    'currency_code' => 'USDT'
];

$options = [
    'http' => [
        'header' => [
            'api-key: your_api_key_here',
            'Content-Type: application/json'
        ],
        'method' => 'POST',
        'content' => json_encode($data)
    ]
];

$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result, true);

print_r($response);
import requests
import json

def send_payout():
    url = 'https://your-domain.com/api/payout/'
    headers = {
        'api-key': 'your_api_key_here',
        'Content-Type': 'application/json'
    }
    data = {
        'amount': '10.0',
        'address': 'recipient_uid_123',
        'currency_code': 'USDT'
    }
    
    response = requests.post(url, headers=headers, json=data)
    return response.json()

result = send_payout()
print(result)

Response Examples

200 OK
{ "status": "success", "message": "10.0 USDT (TRC20) successfully sent to recipient_username. Fee: 0.1 USDT", "transaction_id": 12345 }
401 Unauthorized
{ "error": "API key is required in headers." }
400 Bad Request
{ "error": "Amount, address (recipient UID), and currency_code are required." }
400 Bad Request
{ "error": "Insufficient total USDT balance to cover amount and fee." }

HTTP Status Codes

Understanding the different response codes returned by the API.

Status Code Reference

Code Status Description
200 OK Request successful
201 Created Resource created successfully
400 Bad Request Invalid request parameters
401 Unauthorized Invalid or missing API key
404 Not Found Resource not found
500 Internal Server Error Server error occurred

Webhook Notifications

When a payment is successfully processed, a webhook notification will be sent to your callback URL (if provided).

Webhook Payload

POST to callback_url
{ "status": "success", "token": "12345678-1234-1234-1234-123456789abc", "amount_usd": "25.50", "amount_crypto": "25.50", "fee_crypto": "0.25", "net_crypto": "25.25", "currency": "USDT", "network": "TRC20", "payer_id": 123456789, "payee_id": 987654321 }

Webhook Headers

Header Value Description
User-Agent MyWallet-Webhook/1.0 Identifies the webhook sender
Content-Type application/json Payload format