Sử dụng đoạn code sau để nhận dữ liệu từ hệ thống của chúng tôi. Hãy nhớ thay thế YOUR_SECRET_KEY bằng Secret Key của Webhook bạn vừa tạo.
<?php
$payload = file_get_contents('php://input');
$data = json_decode($payload, true);
$webhookSecret = $_SERVER['HTTP_X_WEBHOOK_SECRET'] ?? '';
$mySecret = "YOUR_SECRET_KEY_HERE"; #mã secret key của bạn
if ($webhookSecret !== $mySecret) {
http_response_code(401);
die(json_encode(['status' => 'error', 'message' => 'Xác thực không hợp lệ']));
}
if ($data && isset($data['transaction'])) {
$transaction = $data['transaction']; #data json full
$bankType = $data['bank_type']; #ngân hàng
$accountNo = $data['account_no']; #số tài khoản
$amount = $transaction['amount']; #số tiền
$content = $transaction['content']; #nội dung
$tradingCode = $transaction['trading']; #mã giao dịch
$type = $transaction['type']; #thể loại giao dịch IN và OUT
header('Content-Type: application/json');
echo json_encode([
'status' => 'success',
'message' => 'Nhận thành công giao dịch ' . $tradingCode
]);
} else {
http_response_code(400);
echo json_encode(['status' => 'error', 'message' => 'Dữ liệu không hợp lệ']);
}