Skip to content

🔍 Kiểm tra OneQR - Xem chi tiết QR

📱 Tổng quan

Để kiểm tra chi tiết một mã QR đã tạo, bạn gọi API Retrieve QR Transaction của OneQR. API này trả về đầy đủ thông tin giao dịch và trạng thái thanh toán.


🔌 Endpoint

GET http://api.pay2s.vn/api/{bank_code}/v1/qr/transactions/{transactionId}
Tham sốVí dụMô tả
{bank_code}vcbMã ngân hàng (vcb = Vietcombank, acb = ACB Bank, ...)
{transactionId}0e907bd2-74d0-4c49-96ba-e64660736a2aMã truy vấn (từ response tạo QR)

📤 Request

Headers

json
{
  "Authorization": "Bearer <token>"
}

Lưu ý: <token> là Bearer token được cấp từ Pay2S

✅ Ví dụ Request (cURL)

bash
curl --location 'http://api.pay2s.vn/api/vcb/v1/qr/transactions/0e907bd2-74d0-4c49-96ba-e64660736a2a' \
  --header 'Authorization: Bearer YOUR_BEARER_TOKEN'

📥 Response

✅ Thành công (200 OK)

json
{
  "success": true,
  "message": "QR transaction retrieved successfully",
  "data": {
    "transactionId": "0e907bd2-74d0-4c49-96ba-e64660736a2a",
    "merchantId": "091000000900000",
    "terminalId": "60199886",
    "orderId": "123456",
    "amount": 10000,
    "description": "THANH TOAN DON HANG",
    "exoDate": null,
    "qrData": "00020101021238630010A000000727013300069704360119QRPP2S26159194HHKZE0208QRIBFTTA5204732153037045405100005802VN5920CT CP TM DAU TU GAJA6011HO CHI MINH62350708591998060819THANH TOAN DON HANG63047130",
    "status": "processing",
    "traceNumber": "QRPP2S26159194HHKZE",
    "bankCode": "978485",
    "responseCode": "00",
    "requestId": "P2S-1780908087998-3hlh5c4og",
    "vcbResponse": {
      "code": "00",
      "nodeIn": "0.0.0.0",
      "message": "Succeed",
      "nodeOut": "10.1.60.185",
      "subCode": "00",
      "checksum": "8DB582799A700B17FA56C2558CC8CCB1",
      "operation": "InitInvoice",
      "ccPayLoad": "00020101021238630010A000000727013300069704360119QRPP2S26159194HHKZE0208QRIBFTTA5204732153037045405100005802VN5920CT CP TM DAU TU GAJA6011HO CHI MINH62350708591998060819THANH TOAN DON HANG63047130",
      "requestId": "P2S-1780908087999-3hlh5c4og",
      "paymentRef": "QRPP2S26159194HHKZE",
      "serverTime": "15:42:07 09/06/2026",
      "subMessage": "Succeed",
      "paymentName": "CT CP TM DAU TU GAJA"
    },
    "auditData": {
      "channel": "P2S",
      "channelId": "0.0.0.0",
      "channelTime": "2825600815142",
      "channelUser": "adi-payment",
      "channelUserBranch": "01"
    },
    "createdAt": "2025-06-08T09:41:28.000Z"
  }
}

Giải thích Response

TrườngMô tả
successTrạng thái: true = Lấy thông tin thành công
transactionIdMã giao dịch duy nhất
orderIdID đơn hàng
amountSố tiền (VND)
statusTrạng thái: processing (chờ), paid (thanh toán), cancelled (hủy)
qrDataChuỗi QR mã (EMV-QR format)
traceNumberMã định danh QR
vcbResponseChi tiết response từ ngân hàng
createdAtThời gian tạo QR
paymentRefMã tham chiếu thanh toán

💻 Code mẫu - Kiểm tra QR

php
<?php
$bearerToken = "YOUR_BEARER_TOKEN";
$transactionId = "0e907bd2-74d0-4c49-96ba-e64660736a2a";
$url = "http://api.pay2s.vn/api/vcb/v1/qr/transactions/" . $transactionId;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Authorization: Bearer " . $bearerToken
]);

$response = curl_exec($ch);
$result = json_decode($response, true);

if ($result['success'] === true) {
    $txn = $result['data'];
    
    echo "Order ID: " . $txn['orderId'] . "\n";
    echo "Amount: " . $txn['amount'] . " VND\n";
    echo "Status: " . $txn['status'] . "\n";
    echo "Description: " . $txn['description'] . "\n";
    echo "Created: " . $txn['createdAt'] . "\n";
    
    // Kiểm tra thanh toán
    if ($txn['status'] === 'paid') {
        echo "✅ Thanh toán thành công!\n";
        echo "Payment Ref: " . $txn['paymentRef'] . "\n";
    } else if ($txn['status'] === 'processing') {
        echo "⏳ Chờ thanh toán...\n";
    } else if ($txn['status'] === 'cancelled') {
        echo "❌ QR đã bị hủy\n";
    }
} else {
    echo "Error: " . $result['message'];
}

curl_close($ch);
?>
javascript
const axios = require('axios');

const bearerToken = "YOUR_BEARER_TOKEN";
const transactionId = "0e907bd2-74d0-4c49-96ba-e64660736a2a";

const url = `http://api.pay2s.vn/api/vcb/v1/qr/transactions/${transactionId}`;

axios.get(url, {
  headers: {
    "Authorization": `Bearer ${bearerToken}`
  }
})
  .then(response => {
    if (response.data.success === true) {
      const txn = response.data.data;
      
      console.log(`Order ID: ${txn.orderId}`);
      console.log(`Amount: ${txn.amount} VND`);
      console.log(`Status: ${txn.status}`);
      console.log(`Description: ${txn.description}`);
      console.log(`Created: ${txn.createdAt}`);
      
      // Check payment status
      if (txn.status === 'paid') {
        console.log("✅ Payment successful!");
        console.log(`Payment Ref: ${txn.paymentRef}`);
      } else if (txn.status === 'processing') {
        console.log("⏳ Waiting for payment...");
      } else if (txn.status === 'cancelled') {
        console.log("❌ QR was cancelled");
      }
    } else {
      console.error("Error:", response.data.message);
    }
  })
  .catch(err => console.error(err));
python
import requests

bearer_token = "YOUR_BEARER_TOKEN"
transaction_id = "0e907bd2-74d0-4c49-96ba-e64660736a2a"

url = f"http://api.pay2s.vn/api/vcb/v1/qr/transactions/{transaction_id}"

headers = {
    "Authorization": f"Bearer {bearer_token}"
}

response = requests.get(url, headers=headers)
result = response.json()

if result['success'] == True:
    txn = result['data']
    
    print(f"Order ID: {txn['orderId']}")
    print(f"Amount: {txn['amount']} VND")
    print(f"Status: {txn['status']}")
    print(f"Description: {txn['description']}")
    print(f"Created: {txn['createdAt']}")
    
    # Check payment status
    if txn['status'] == 'paid':
        print("✅ Payment successful!")
        print(f"Payment Ref: {txn['paymentRef']}")
    elif txn['status'] == 'processing':
        print("⏳ Waiting for payment...")
    elif txn['status'] == 'cancelled':
        print("❌ QR was cancelled")
else:
    print("Error:", result['message'])
java
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class RetrieveQRClient {
    
    public static void main(String[] args) throws Exception {
        String bearerToken = "YOUR_BEARER_TOKEN";
        String transactionId = "0e907bd2-74d0-4c49-96ba-e64660736a2a";
        
        String url = "http://api.pay2s.vn/api/vcb/v1/qr/transactions/" + transactionId;
        
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        conn.setRequestMethod("GET");
        conn.setRequestProperty("Authorization", "Bearer " + bearerToken);
        
        int responseCode = conn.getResponseCode();
        System.out.println("Response Code: " + responseCode);
        
        if (responseCode == 200) {
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String inputLine;
            StringBuilder response = new StringBuilder();
            
            while ((inputLine = in.readLine()) != null) {
                response.append(inputLine);
            }
            in.close();
            
            // Parse and display JSON response
            System.out.println("Response: " + response.toString());
            
            // Note: For production, use a JSON library like Gson or Jackson
        }
    }
}

⚡ Best Practices

  1. Cache transaction ID: Lưu transactionId từ khi tạo QR để kiểm tra sau
  2. Poll status: Gọi API này định kỳ để kiểm tra trạng thái thanh toán
  3. Error handling: Kiểm tra success trước xử lý data
  4. Timeout: Đặt timeout hợp lý (30-60 giây)
  5. Retry logic: Nếu request fail, retry sau 2-3 giây
  6. Check payment status: Luôn kiểm tra status trước cập nhật database
  7. Store response: Lưu toàn bộ response để audit trail
  8. VCB Response: Kiểm tra vcbResponse.code để xác nhận ngân hàng
  9. Avoid repeated calls: Đừng gọi quá nhiều lần trong một vài giây
  10. Logging: Log transactionId và status để debug

🔄 Luồng kiểm tra QR

javascript
// 1. Tạo QR → nhận transactionId
// 2. Hiển thị QR cho khách hàng
// 3. Poll API kiểm tra status
const interval = setInterval(() => {
  getQRStatus(transactionId).then(status => {
    if (status === 'completed') {
      clearInterval(interval);
      console.log("✅ Payment completed");
      updateOrderStatus('paid');
    } else if (status === 'cancelled') {
      clearInterval(interval);
      console.log("❌ QR cancelled");
    }
  });
}, 2000); // Kiểm tra mỗi 2 giây

📊 Trạng thái QR

StatusMô tảHành động
processingChờ thanh toánTiếp tục kiểm tra
paidĐã thanh toánCập nhật order, gửi email
cancelledQR bị hủyHiển thị lỗi, yêu cầu tạo QR mới
expiredQR hết hạnYêu cầu tạo QR mới

Tiếp theo: Xem Danh sách OneQR để xem tất cả QR hoặc Webhook để nhận thông báo tự động