SDK chính thức
Repo bankgateway-sdk trên GitHub có SDK cho JavaScript (Node.js 18+), Python 3.8+ và PHP 7.4+, không phụ thuộc thư viện ngoài. SDK bao gồm cả 3 API (tra cứu tài khoản, lịch sử giao dịch, cổng thanh toán VietQR), tự ký HMAC, tự gom lỗi thành một kiểu chung và có hàm xác minh chữ ký webhook.
git clone https://github.com/bankgatewayvietnam/bankgateway-sdk.gitimport { BankGateway } from "./bankgateway-sdk/js/src/index.js";
const bg = new BankGateway({ apiKey: process.env.BANKGATEWAY_API_KEY });
const { accountName } = await bg.lookup({ bankCode: "MB", accountNumber: "0783825888" });Code mẫu không cần SDK
Nếu không muốn thêm SDK, các ví dụ dưới đây chỉ dùng thư viện có sẵn của ngôn ngữ, có thể chép thẳng vào dự án:
# Gọi trực tiếp từ máy chủ backend (Server-to-Server).
# Bảo mật: Không bao giờ nhúng API Key vào client/web frontend.
curl -X POST 'https://api.bankgateway.vn/api/v1/lookup' \
-H 'Content-Type: application/json' \
-H 'X-API-Key: YOUR_API_KEY' \
-H 'Idempotency-Key: op_$(date +%s)_$RANDOM' \
-d '{
"bankCode": "MB",
"accountNumber": "0783825888"
}'Tải về
bankgateway-sdk (GitHub)
SDK JavaScript, Python, PHP.
OpenAPI 3 (openapi.json)Import vào Swagger, Insomnia hoặc trình sinh client.
Postman collectionBộ request mẫu, chỉ cần điền biến apiKey.
Danh sách ngân hàng (banks.json)Mã, BIN và tên ngân hàng.
lookup.mjsVí dụ Node.js hoàn chỉnh có retry.
lookup.pyVí dụ Python.
lookup.goVí dụ Go.
Kiểu dữ liệu TypeScript
export interface LookupRequest {
bankCode: string;
accountNumber: string; // luôn là chuỗi
}
export interface QuotaRemaining {
subscriptionQuota: number;
vaultQuota: number;
walletBalanceVnd: number;
}
export interface LookupSuccess {
success: true;
data: {
requestId: string;
bankCode: string;
accountNumber: string;
accountName: string;
cached: boolean;
verifiedAt: string;
feeChargedVnd: number;
chargeMethod: "PAY_AS_YOU_GO" | "MONTHLY_PASS_30_DAYS" | "LIFETIME_VAULT";
quotaRemaining: QuotaRemaining;
latencyMs: number;
message?: string;
};
}
export interface LookupError {
success: false;
error: {
code: string;
message?: string;
requestId?: string;
category?: string;
retryable?: boolean;
action?: string;
feeChargedVnd?: number;
autoReopenAt?: string | null;
};
}
export type LookupResponse = LookupSuccess | LookupError;
export interface BankTransaction {
transactionID: string;
amount: number;
currency: "VND";
balanceAfter: number;
description: string;
transactionDate: string; // dd/MM/yyyy
bookingDateTime: string; // ISO 8601 +07:00
type: "IN" | "OUT";
creditDebitIndicator: "CRDT" | "DBIT";
bankCode: string;
counterPartyAccount: string | null;
counterPartyName: string | null;
}