What is VietQR?
VietQR is the bank payment QR code standard in Vietnam, issued by Napas and the State Bank of Vietnam. A VietQR code carries everything needed to make a bank transfer: account number, bank name, amount (optional), and transfer note.
What sets it apart: VietQR works cross-bank. A customer using any bank app can scan it, with no need to share the same bank as the merchant.
Static QR vs dynamic QR
| Static QR | Dynamic QR | |
|---|---|---|
| Amount | Not fixed, customer types it in | Fixed inside the QR |
| Note | Fixed | Can carry an order code |
| Use when | Simple payment counter, donations | E-commerce checkout, kiosk |
| Reconciliation | Hard to automate | Easy to automate via order_id |
For most B2B and e-commerce systems, dynamic QR is the right choice: you attach order_id to the QR and receive an IPN callback when the payment succeeds.
Integration architecture
[Ứng dụng của bạn]
│
▼
POST /openapi/v1/transaction/qr/generate ──► [TConnect API] ──► [Ngân hàng / Napas]
│ │
│◄─── qr_content / image_png_base64 ────────────┘
│
▼
[Render QR cho khách hàng]
│
│ Khách quét & thanh toán
▼
[TConnect IPN Callback] ──► [Backend của bạn] ──► Cập nhật đơn hàngStep 1: Get the service_code
Before creating a QR, call the Get Services API to get the service_code matching the bank you use.
curl -X GET "https://sme-open-api-sandbox.tconnect.vn/openapi/v1/services?payment_method=qr&limit=10&page=1" \
-H "Partner-Code: YOUR_PARTNER_CODE" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"The response returns a list of services, for example "code": "bidv-qr". This is the value you pass into the x-service-code header.
Step 2: Create a Virtual Account
A VA (Virtual Account) is an identifying account number for the merchant. Create it once, use it forever.
// Tạo Virtual Account một lần, dùng mãi
payload = {
bank_code: "970454", // BIDV
account_name: "CONG TY THUONG MAI ABC"
}
encrypt payload then POST to /openapi/v1/va/va-account/create
// Response: { "va_number": "VA100023312", "status": "active" }Step 3: Create a QR for the order
// Khởi tạo client và đăng nhập
client = new TConnectClient(base_url, partner_code, aes_key)
client.login(username, password, client_id, client_secret)
// Tạo QR cho đơn hàng
qr_response = client.create_qr(
order_id: "ORDER_20260510_001",
va: "VA100023312",
bincode: "970454",
service_code: "bidv-qr",
amount: 250000 // 250,000 VND — truyền 0 cho QR tĩnh
)
// qr_response.image_png_base64 → dùng trong <img src="data:image/png;base64,...">
// qr_response.qr_content → dùng render bằng thư viện QR codeRendering in React
// Component hiển thị ảnh QR từ base64 data
function PaymentQR(qrData):
render image:
src = "data:image/png;base64," + qrData.image_png_base64
alt = "QR thanh toán"
size = 192 x 192 pxStep 4: Receive the IPN when the payment succeeds
// IPN endpoint: POST /webhook/tconnect/ipn
function ipn_handler(request):
body = parse_json(request)
txn = decrypt_aes(body.data, AES_KEY)
// Idempotency check
if is_processed(txn.request_id):
return { status: "ok" }
mark_order_paid(txn.order_id, txn.amount)
return { status: "ok" } // Bắt buộc trả 200Important: TConnect retries the IPN if it does not receive an HTTP 200. Always implement idempotency using
request_id.
Handling edge cases
Expired QR: VietQR codes have no hard TTL, but you should set a timeout on your backend (for example, 15 minutes) and cancel the order if it passes.
Duplicate IPN: This happens on network retries. Use request_id as the unique key to avoid charging twice.
Amount mismatch: Check txn["amount"] in the IPN against the order's expected_amount before marking it paid.
Conclusion
VietQR is simpler than card payment and far more common in Vietnam (especially among SMEs). The integration flow:
- Login → get token
- Get Services → get
service_code - Create VA → get
va_number - Create QR → show it to the customer
- IPN Callback → update the order
The whole flow can be implemented in under 4 hours with the TConnect Sandbox.