BIN/IIN là gì?
BIN (Bank Identification Number) — còn gọi là IIN (Issuer Identification Number) — là 6 đến 9 số đầu tiên của một thẻ thanh toán. Những con số này xác định:
- Tổ chức phát hành: Ngân hàng nào phát hành thẻ (Vietcombank, BIDV, Techcombank, v.v.)
- Loại thẻ: Visa, Mastercard, Napas, JCB, Amex
- Hạng thẻ: Debit, Credit, Prepaid
- Quốc gia phát hành: VN, US, SG, v.v.
Ví dụ: Thẻ bắt đầu bằng 970436 là thẻ Vietcombank, còn 970415 là Vietinbank.
Ứng dụng thực tế của BIN Lookup
1. Cải thiện UX khi nhập thẻ
Khi người dùng nhập số thẻ, gọi BIN lookup sau 6 chữ số đầu để:
- Hiển thị logo ngân hàng phát hành
- Tự động chọn đúng payment processor
- Validate format số thẻ theo từng loại (Visa: 16 số, Amex: 15 số)
// Component nhập số thẻ: tự động nhận diện loại thẻ khi người dùng nhập
function CardInput():
state cardInfo = null
function handleCardChange(value):
digits = strip_non_digits(value)
// Gọi BIN lookup sau 6 số
if digits.length >= 6 and cardInfo is null:
bin = first 9 digits of digits
info = fetch_bin_info(bin)
set cardInfo = info
if digits.length < 6:
set cardInfo = null
render:
text input (placeholder="Số thẻ", maxLength=19,
onChange → handleCardChange)
if cardInfo is not null:
display bank logo from cardInfo.bank_logo_url
display cardInfo.card_type + " · " + cardInfo.card_level2. Routing thông minh
Với merchant có nhiều cổng thanh toán, dùng BIN để route đến processor tối ưu:
function get_optimal_processor(bin_code):
bin_info = lookup_bin(bin_code)
// Thẻ nội địa Napas → cổng nội địa (phí thấp hơn)
if bin_info.network == "NAPAS":
return "domestic_processor"
// Thẻ quốc tế → cổng quốc tế
if bin_info.issuer_country != "VN":
return "international_processor"
// Thẻ tín dụng nội địa → có thể trả góp
if bin_info.card_type == "CREDIT":
return "installment_enabled_processor"
return "default_processor"3. Phát hiện gian lận sơ bộ
function preliminary_fraud_check(bin_code, user_country):
bin_info = lookup_bin(bin_code)
// Thẻ phát hành tại quốc gia khác với quốc gia người dùng
if bin_info.issuer_country != user_country:
flag_for_review("country_mismatch", bin_code, user_country)
return true
// Thẻ prepaid có rủi ro cao hơn
if bin_info.card_level == "PREPAID":
flag_for_review("prepaid_card", bin_code)
return false4. Hiển thị phí xử lý đúng
Phí xử lý thẻ khác nhau theo loại:
| Loại thẻ | Phí điển hình |
|---|---|
| Debit nội địa (Napas) | 0.5 – 1.1% |
| Credit nội địa | 1.3 – 1.8% |
| Visa/Master debit quốc tế | 1.5 – 2.2% |
| Visa/Master credit quốc tế | 2.0 – 3.0% |
| Amex | 2.5 – 3.5% |
function get_processing_fee(bin_code, amount):
bin_info = lookup_bin(bin_code)
fee_rate = FEE_RATES[bin_info.network][bin_info.card_type]
fee = round(amount * fee_rate)
return {
amount: amount,
fee: fee,
fee_rate: fee_rate,
total: amount + fee,
card_type: bin_info.card_type,
network: bin_info.network
}Gọi TConnect BIN Lookup API
// Tra cứu thông tin BIN/IIN từ 6-9 số đầu của thẻ
function lookup_bin(bin_code, partner_code, access_token):
payload = { bin: bin_code }
encrypted = encrypt_payload(payload, AES_KEY)
POST https://sme-open-api-sandbox.tconnect.vn/openapi/v1/bin/lookup
body: { data: encrypted }
headers:
Authorization: "Bearer {access_token}"
Partner-Code: partner_code
return decrypt_response(response.data, AES_KEY)Kết quả trả về:
{
"bin": "970436",
"bank_name": "Ngân hàng TMCP Ngoại thương Việt Nam",
"bank_short_name": "Vietcombank",
"bank_code": "970436",
"card_type": "DEBIT",
"card_level": "STANDARD",
"network": "NAPAS",
"issuer_country": "VN",
"bank_logo_url": "https://..."
}Cache BIN lookup để tối ưu hiệu năng
BIN data thay đổi rất ít (chỉ khi ngân hàng phát hành BIN mới). Cache tích cực:
function lookup_bin_cached(bin_code):
cache_key = "bin:{bin_code}"
// Check cache
cached = cache.get(cache_key)
if cached exists:
return parse_json(cached)
// Gọi API
result = lookup_bin_api(bin_code)
// Cache 30 ngày — BIN data rất stable
cache.set(cache_key, result, ttl = 30 days)
return resultVới traffic cao, thêm in-memory LRU cache:
// In-memory LRU cache: tối đa 10.000 entries, TTL 1 giờ
memory_cache = new LRUCache(max_size=10000, ttl=1 hour)
function lookup_bin_fast(bin_code):
if bin_code in memory_cache:
return memory_cache[bin_code]
result = lookup_bin_cached(bin_code)
memory_cache[bin_code] = result
return resultTích hợp với checkout flow
Pattern đầy đủ tại checkout:
// Hook quản lý trạng thái BIN lookup tại checkout
function useCardLookup():
state binInfo = null
state loading = false
debouncedLookup = debounce(lookupBin, delay=300ms)
function onCardNumberChange(value):
digits = strip_non_digits(value)
if digits.length < 6:
set binInfo = null
return
set loading = true
info = debouncedLookup(first 9 digits of digits)
set binInfo = info
set loading = false
return { binInfo, loading, onCardNumberChange }Kết luận
BIN lookup là tính năng nhỏ nhưng tạo ra sự khác biệt lớn trong trải nghiệm thanh toán: người dùng thấy logo ngân hàng ngay khi nhập thẻ, hệ thống tự chọn đúng processor, và fraud detection có thêm tín hiệu đầu vào. Chi phí implement thấp, lợi ích rõ ràng — đây là một trong những API nên tích hợp đầu tiên.