Tài liệu API & Tích hợp
1 Tổng quan
VNGateway.net cung cấp cổng thanh toán tiền điện tử (USDT, USDC) tự động trên các mạng EVM. Hệ thống sử dụng mô hình API đơn giản và chữ ký bảo mật SHA-256.
Base API URL
http://vngateway.net/api
2 Tạo đơn hàng (Create Order)
POST
/create-order
| Trường | Yêu cầu | Mô tả |
|---|---|---|
| api_key | Yes | Mã định danh API của bạn. |
| signature | Yes | hash('sha256', api_key + secret_key + memo) |
| memo | Yes | Nội dung thanh toán. Duy nhất cho mỗi API Key. |
| amount | Yes | Số tiền. Min 1 USDT (giá trị quy đổi). |
| coin | Yes | USDT hoặc USDC. |
| network | Yes | BSC, POL, OP, ARB. |
| callback_url | Yes | URL nhận thông báo kết quả. |
checkout.php
PHP Example
<?php
$apiUrl = "http://vngateway.net/api/create-order";
$apiKey = "YOUR_API_KEY";
$secretKey = "YOUR_SECRET_KEY";
$memo = "ORDER_ID_123";
$amount = 10.0;
$coin = "USDT";
$network = "BSC";
$callback = "https://domain.com/callback.php";
$return = "https://domain.com/success.php";
// Chữ ký bảo mật
$signature = hash('sha256', $apiKey . $secretKey . $memo);
$data = [
'api_key' => $apiKey,
'signature' => $signature,
'memo' => $memo,
'amount' => $amount,
'coin' => $coin,
'network' => $network,
'callback_url' => $callback,
'return_url' => $return
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
$result = json_decode($response, true);
if ($result['success']) {
header("Location: " . $result['data']['paymentUrl']);
}
Thông báo Callback (Webhook)
POST JSON
Khi trạng thái đơn hàng thay đổi (completed hoặc canceled), hệ thống sẽ gửi một POST request dạng JSON tới callback_url. Bạn PHẢI kiểm tra signature để xác thực nguồn gốc.
Payload JSON mẫu
{
"order_id": 123,
"token": "9TxkWI...",
"amount": "10.0",
"coin": "USDT",
"network": "BSC",
"status": "completed",
"memo": "ORDER_ID_123",
"signature": "a1b2c3d4..."
}
Công thức chữ ký
Dùng chung công thức cho tất cả API:
hash('sha256', api_key + secret_key + memo)
callback.php
PHP Example
<?php
$json = file_get_contents('php://input');
$data = json_decode($json, true);
if ($data) {
$apiKey = "YOUR_API_KEY";
$secretKey = "YOUR_SECRET_KEY";
// Kiểm tra chữ ký bảo mật
$expectedSignature = hash('sha256', $apiKey . $secretKey . $data['memo']);
if (hash_equals($expectedSignature, $data['signature'])) {
if ($data['status'] === 'completed') {
// Thanh toán thành công -> Xử lý đơn hàng của bạn
}
// Luôn trả về success cho hệ thống dừng gửi lại callback
header('Content-Type: application/json');
echo json_encode(['success' => true]);
} else {
http_response_code(401);
}
}
3 Rút tiền (Withdraw)
POST
/withdraw
| Trường | Yêu cầu | Mô tả |
|---|---|---|
| api_key | Yes | Mã định danh API của bạn. |
| signature | Yes | hash('sha256', api_key + secret_key + memo) |
| memo | Yes | Nội dung rút tiền. Duy nhất cho mỗi API Key. |
| amount | Yes | Số tiền rút. Min 1 USDT. |
| coin | Yes | USDT hoặc USDC. |
| network | Yes | BSC, POL, OP, ARB. |
| address | Yes | Địa chỉ ví nhận tiền. |
withdraw.php
PHP Example
<?php
$apiUrl = "http://vngateway.net/api/withdraw";
$apiKey = "YOUR_API_KEY";
$secretKey = "YOUR_SECRET_KEY";
$memo = "WITHDRAW_" . time();
$amount = 50.0;
$coin = "USDT";
$network = "BSC";
$address = "0x...";
$signature = hash('sha256', $apiKey . $secretKey . $memo);
$data = [
'api_key' => $apiKey,
'signature' => $signature,
'memo' => $memo,
'amount' => $amount,
'coin' => $coin,
'network' => $network,
'address' => $address
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
echo $response;
4 Trạng thái rút tiền (Withdraw Status)
POST
/withdraw-status
| Trường | Yêu cầu | Mô tả |
|---|---|---|
| api_key | Yes | Mã API của bạn. |
| signature | Yes | hash('sha256', api_key + secret_key + memo) |
| memo | Opt | Dùng để tra cứu theo memo. |
| id | Opt | Dùng để tra cứu theo ID đơn rút. |
status.php
PHP Example
<?php
$apiUrl = "http://vngateway.net/api/withdraw-status";
$apiKey = "YOUR_API_KEY";
$secretKey = "YOUR_SECRET_KEY";
$memo = "WITHDRAW_123456";
$signature = hash('sha256', $apiKey . $secretKey . $memo);
$data = [
'api_key' => $apiKey,
'signature' => $signature,
'memo' => $memo
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
echo $response;