Blog
bin-lookuppayment-apicard-validationux

Tra cứu BIN/IIN: Xác thực và nhận diện thẻ thanh toán trong ứng dụng

BIN/IIN lookup giúp nhận diện loại thẻ, ngân hàng phát hành và quốc gia chỉ từ 6-9 số đầu. Tìm hiểu cách dùng API tra cứu BIN để cải thiện UX và giảm gian lận.

TConnect Team 20 tháng 1, 2026 6 min read

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_level

2. 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 false

4. 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 địa1.3 – 1.8%
Visa/Master debit quốc tế1.5 – 2.2%
Visa/Master credit quốc tế2.0 – 3.0%
Amex2.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 result

Vớ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 result

Tí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.

Bắt đầu tích hợp ngay

Sandbox miễn phí · Tài liệu API đầy đủ · Hỗ trợ kỹ thuật