Appearance
📋 Danh sách OneQR - Xem QR đã tạo
📱 Tổng quan
Để lấy danh sách các mã QR đã tạo, bạn gọi API List QR Code của OneQR. API này hỗ trợ phân trang để xem các QR được tạo trong quá khứ.
🔌 Endpoint
GET http://api.pay2s.vn/api/{bank_code}/v1/qr/list| Tham số | Ví dụ | Mô tả |
|---|---|---|
{bank_code} | vcb | Mã ngân hàng (vcb = Vietcombank, acb = ACB Bank, ...) |
📤 Request
Headers
json
{
"Authorization": "Bearer <token>"
}Lưu ý:
<token>là Bearer token được cấp từ Pay2S
Query Parameters
| Tham số | Loại | Bắt buộc | Mô tả |
|---|---|---|---|
limit | Number | - | Số lượng bản ghi trả về (default: 20, max: 100) |
offset | Number | - | Vị trí bắt đầu (dùng cho phân trang, default: 0) |
✅ Ví dụ Request (cURL)
bash
curl --location 'http://api.pay2s.vn/api/vcb/v1/qr/list?limit=20&offset=0' \
--header 'Authorization: Bearer YOUR_BEARER_TOKEN'📥 Response
✅ Thành công (200 OK)
json
{
"success": true,
"message": "QR list 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",
"requestId": "P2S-1780908087998-3hlh5c4og",
"bankCode": "978485",
"responseCode": "00",
"createdAt": "2025-06-08T10:58.000Z"
},
{
"transactionId": "72c00721-8ae2-4192-b7e3-7dfc0773d33f",
"merchantId": "091000000900000",
"terminalId": "60199886",
"orderId": "6844",
"amount": 2000,
"description": "HMD6085",
"exoDate": null,
"qrData": "00020101021238630010A000000727013300069704360119QRPP2S26159194HHKZE0208QRIBFTTA5204732153037045405100005802VN5920CT CP TM DAU TU GAJA6011HO CHI MINH62350708591998060819THANH TOAN DON HANG63047130",
"status": "cancelled",
"traceNumber": "QRPP2S26159194HHKZE",
"requestId": "P2S-1780994702237-vAzRiKxO",
"bankCode": "978485",
"responseCode": "00",
"createdAt": "2025-06-08T10:25.000Z"
}
],
"total": 8,
"limit": 20,
"offset": 0
}Giải thích Response
| Trường | Mô tả |
|---|---|
success | Trạng thái: true = Lấy danh sách thành công |
message | Mô tả: QR list retrieved successfully |
data | Mảng danh sách QR codes |
transactionId | Mã giao dịch duy nhất |
orderId | ID đơn hàng |
amount | Số tiền (VND) |
status | Trạng thái: processing, cancelled, completed |
traceNumber | Mã định danh QR |
createdAt | Thời gian tạo QR |
💻 Code mẫu - Lấy danh sách QR
php
<?php
$bearerToken = "YOUR_BEARER_TOKEN";
$limit = 20;
$offset = 0;
$url = "http://api.pay2s.vn/api/vcb/v1/qr/list?limit=" . $limit . "&offset=" . $offset;
$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) {
$qrList = $result['data'];
echo "Found " . count($qrList) . " QR codes\n";
foreach ($qrList as $qr) {
echo "Order: " . $qr['orderId'] .
" | Amount: " . $qr['amount'] .
" | Status: " . $qr['status'] . "\n";
}
$pagination = $result['pagination'];
echo "Total: " . $pagination['total'] . " QR codes\n";
} else {
echo "Error: " . $result['message'];
}
curl_close($ch);
?>javascript
const axios = require('axios');
const bearerToken = "YOUR_BEARER_TOKEN";
const limit = 20;
const offset = 0;
const url = `http://api.pay2s.vn/api/vcb/v1/qr/list?limit=${limit}&offset=${offset}`;
axios.get(url, {
headers: {
"Authorization": `Bearer ${bearerToken}`
}
})
.then(response => {
if (response.data.success === true) {
const qrList = response.data.data;
console.log(`Found ${qrList.length} QR codes`);
qrList.forEach(qr => {
console.log(`Order: ${qr.orderId} | Amount: ${qr.amount} | Status: ${qr.status}`);
});
const pagination = response.data.pagination;
console.log(`Total: ${pagination.total} QR codes`);
} else {
console.error("Error:", response.data.message);
}
})
.catch(err => console.error(err));python
import requests
bearer_token = "YOUR_BEARER_TOKEN"
limit = 20
offset = 0
url = f"http://api.pay2s.vn/api/vcb/v1/qr/list?limit={limit}&offset={offset}"
headers = {
"Authorization": f"Bearer {bearer_token}"
}
response = requests.get(url, headers=headers)
result = response.json()
if result['success'] == True:
qr_list = result['data']
print(f"Found {len(qr_list)} QR codes")
for qr in qr_list:
print(f"Order: {qr['orderId']} | Amount: {qr['amount']} | Status: {qr['status']}")
pagination = result['pagination']
print(f"Total: {pagination['total']} QR codes")
else:
print("Error:", result['message'])java
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.net.HttpURLConnection;
import java.net.URL;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ListQRClient {
public static void main(String[] args) throws Exception {
String bearerToken = "YOUR_BEARER_TOKEN";
int limit = 20;
int offset = 0;
String url = "http://api.pay2s.vn/api/vcb/v1/qr/list?limit=" + limit + "&offset=" + offset;
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 JSON response
System.out.println("Response: " + response.toString());
}
}
}⚡ Best Practices
- Pagination: Sử dụng
limitvàoffsetđể lấy dữ liệu từng trang - Limit cách hợp lý: Không nên lấy quá nhiều bản ghi (max: 100)
- Cache kết quả: Lưu danh sách QR vào cache để tránh request quá nhiều
- Filter by status: Lọc QR theo status (
processing,cancelled,paid) - Sort by date: Sắp xếp theo
createdAtđể xem QR mới nhất trước - Track total: Lưu
totaltừ pagination để biết có bao nhiêu QR - Error handling: Kiểm tra
successtrước xử lýdata - Timeout: Đặt timeout hợp lý (30-60 giây)
- Retry logic: Nếu request fail, retry sau 2-3 giây
- Logging: Log danh sách QR được lấy để audit
📌 Phân trang - Pagination
Để lấy dữ liệu theo trang, sử dụng limit và offset:
javascript
// Trang 1: offset = 0, limit = 20
const page1 = `/qr/list?limit=20&offset=0`;
// Trang 2: offset = 20, limit = 20
const page2 = `/qr/list?limit=20&offset=20`;
// Trang 3: offset = 40, limit = 20
const page3 = `/qr/list?limit=20&offset=40`;Công thức: offset = (page - 1) * limit
🔍 Filter QR theo Status
bash
# Lấy danh sách QR đang xử lý
curl 'http://api.pay2s.vn/api/vcb/v1/qr/list?limit=20&offset=0' \
-H 'Authorization: Bearer TOKEN'
# Sau đó filter trong code:
# status = 'processing' (chờ thanh toán)
# status = 'paid' (đã thanh toán)
# status = 'cancelled' (đã hủy)Tiếp theo: Xem Tạo OneQR để tạo QR mới hoặc Hủy OneQR để hủy QR hoặc Kiểm tra OneQR để xem chi tiết
