Apinganhang API v1

REST API xác thực giao dịch ngân hàng, quản lý tài khoản, kết nối OTP, và tích hợp cổng thanh toán tự động.

Thuộc tínhGiá trị
Base URLhttps://client.apinganhang.net/api/v1
Content-Typeapplication/json
AuthAuthorization: Bearer <token>
EncodingUTF-8
Health check: GET /api/v1/ping.php — không cần token, trả {"ok":true}

Xác thực

Tất cả endpoint (trừ ping.php) yêu cầu header Authorization: Bearer <token>.

Token nhận được từ endpoint POST /auth/login.php. Token không có thời hạn hết hạn — cookie được duy trì lâu dài trừ khi user đăng xuất hoặc admin reset token.

401 Unauthorized: Khi token sai hoặc không tồn tại, API trả HTTP 401. Client nên redirect về trang login.

Mã lỗi & Response format

Mọi response đều là JSON với field success (boolean).

HTTPÝ nghĩaVí dụ
200Thành công{"success":true,"data":{...}}
400Bad request / login bank thất bại{"success":false,"message":"..."}
401Chưa đăng nhập / token không hợp lệ
403Gói API hết hạn
404Không tìm thấy
405Method không hỗ trợ
422Thiếu / sai field
500Lỗi server

Rate Limit

Chưa áp dụng rate limiting cứng. Khuyến nghị polling giao dịch tối đa mỗi 10–30 giây. Bank cron cập nhật mỗi 1 phút.

POST Login

POST /api/v1/auth/login.php

Đăng nhập lấy token.

Request Body

FieldTypeRequiredMô tả
usernamestringrequiredTên đăng nhập
passwordstringrequiredMật khẩu

Response 200

FieldTypeMô tả
successbooleantrue
tokenstringBearer token
userobject{ id, username, email, level, money, time_momo, id_telegram }

GET Profile

GET /api/v1/auth/profile.php

Lấy thông tin user hiện tại. Có thể dùng để kiểm tra token còn hợp lệ.

Response 200

FieldTypeMô tả
successbooleantrue
data.idintegerUser ID
data.usernamestringTên đăng nhập
data.emailstringEmail
data.moneyintegerSố dư tài khoản (VNĐ)
data.time_momointegerTimestamp hết hạn gói API
data.tokenstringAPI Token hiện tại
data.id_telegramintegerTelegram chat ID nhận thông báo

POST Logout

POST /api/v1/auth/logout.php

Hủy token hiện tại.

GET List accounts

GET /api/v1/accounts/index.php

Lấy danh sách tài khoản ngân hàng đã liên kết của user.

Query Parameters

ParamTypeMô tả
bankstringoptional Lọc: MBBANK, BIDV, VIETCOMBANK, ACB, VIETTINBANK, SEABANK, VIETTEL

Response 200

FieldTypeMô tả
data[].idintegerAccount ID
data[].bank_codestringMã ngân hàng
data[].account_numberstringSố tài khoản
data[].holder_namestringTên chủ TK
data[].balancenumberSố dư (nếu lấy được)
data[].activeinteger1=đang hoạt động, 0=tạm dừng

POST Add account

POST /api/v1/accounts/store.php

Thêm tài khoản ngân hàng mới.

Request Body

FieldTypeRequiredMô tả
bank_codestringrequiredBIDV, MBBANK, ACB, VIETCOMBANK, VIETTINBANK, SEABANK, VIETTEL
account_numberstringrequiredSố tài khoản (4-64 ký tự)
holder_namestringoptionalTên chủ TK
login_idstringoptionalUsername đăng nhập bank
passwordstringoptionalMật khẩu bank (mã hóa khi lưu)

POST Connect account with OTP

POST /api/v1/accounts/connect.php

Đăng nhập bank thực tế + xác thực OTP — không cần mở trang gốc ngân hàng.

Ngân hàng hỗ trợ OTP: BIDV (loginType 3). ACB/MBBANK/VCB tự bypass captcha, không cần OTP từ user.

Bước 1 — Request OTP

FieldTypeRequiredMô tả
actionstringrequired"request_otp"
bank_codestringrequiredVD: "BIDV"
login_idstringrequiredUsername SmartBanking
passwordstringrequiredMật khẩu SmartBanking
account_numberstringrequiredSố tài khoản

Response — Cần OTP

{"success":true, "step":"otp_required", "message":"Mã OTP đã được gửi..."}

Bước 2 — Verify OTP

FieldTypeRequiredMô tả
actionstringrequired"verify_otp"
bank_codestringrequiredGiống bước 1
login_idstringrequiredGiống bước 1
passwordstringrequiredGiống bước 1
account_numberstringrequiredGiống bước 1
otpstringrequiredMã OTP 6 số nhận qua SMS

Response thành công

{"success":true, "step":"done", "data":{"id":68, "bank_code":"BIDV"}}

Lỗi thường gặp: OTP sai, phiên OTP hết hạn (>5 phút), sai mật khẩu bank.

GET List transactions

GET /api/v1/transactions/index.php

Lấy danh sách giao dịch ngân hàng. Hỗ trợ phân trang, lọc, tìm kiếm.

Query Parameters

ParamTypeDefaultMô tả
pageinteger1Trang hiện tại
limitinteger20Số bản ghi/trang (max 100)
bankstringLọc: MBBANK, BIDV, VIETCOMBANK, ACB, VIETTINBANK, SEABANK
typestringINCOME (tiền vào) | EXPENSE (tiền ra)
date_fromstringTừ ngày: 2026-04-01
date_tostringĐến ngày: 2026-04-16
searchstringTìm nội dung / mã GD
account_idintegerLọc theo account ID

Response 200

FieldTypeMô tả
data[]arrayDanh sách giao dịch
data[].idintegerID giao dịch
data[].amountnumberSố tiền (dương = vào, âm = ra)
data[].bankstringNgân hàng
data[].ref_nostringMã giao dịch ngân hàng
data[].descriptionstringNội dung chuyển khoản
data[].typestringin | out
data[].accountstringSố tài khoản
data[].balance_afternumberSố dư sau giao dịch
data[].transaction_timestringThời gian GD
paginationobject{ page, limit, total, total_pages }
totalsobject{ total_in, total_out, net }

GET Get transaction by ID

GET /api/v1/transactions/index.php?id={id}

Lấy chi tiết 1 giao dịch.

GET Export CSV

GET /api/v1/transactions/export.php

Xuất file CSV giao dịch. Chấp nhận cùng query params như list.

GET Dashboard Summary

GET /api/v1/dashboard/summary.php

Tổng thu chi hôm nay, tuần, tháng, quý + 5 giao dịch mới nhất.

GET Dashboard Charts

GET /api/v1/dashboard/charts.php

Dữ liệu biểu đồ thu chi theo ngày (30 ngày gần nhất) + phân bổ danh mục.

GET Extension Info

GET /api/v1/services/extension.php

Trạng thái gói API: ngày hết hạn, giá/tháng, còn bao nhiêu ngày.

POST Gia hạn gói

POST /api/v1/services/extension.php
FieldTypeMô tả
monthsintegerSố tháng gia hạn (1-12)

GET Deposit info

GET /api/v1/services/deposit.php

Thông tin nạp tiền: số dư, lịch sử nạp, min nạp.

GET Site Settings (logo, title)

GET /api/v1/services/site-settings.php

Lấy cấu hình công khai: logo, title, description, hotline, link_facebook, link_zalo.

Response 200

FieldTypeMô tả
data.titlestringTên website
data.descriptionstringMô tả
data.logostringURL logo
data.hotlinestringHotline
data.link_facebookstringLink Facebook
data.link_zalostringLink Zalo

GET Bank Packages

GET /api/v1/services/packages.php

Danh sách gói ngân hàng admin đã cấu hình.

Response 200

FieldTypeMô tả
data[].idintegerID gói
data[].bank_codestringNgân hàng: MBBANK, BIDV, ...
data[].namestringTên gói
data[].priceintegerGiá (VNĐ/tháng)
data[].featuresstringMô tả tính năng
data[].activeinteger1 = hiển thị, 0 = ẩn

GET Notifications

GET /api/v1/notifications/index.php

Lấy 100 thông báo gần nhất.

Use Case: Xác minh thanh toán tự động

Luồng xác minh giao dịch cho website bán hàng / SaaS / game topup.

  1. Tạo đơn hàng trên website với order_code duy nhất + số tiền.
  2. Hiển thị QR / thông tin CK — yêu cầu khách ghi order_code vào nội dung.
  3. Polling API mỗi 10-30s: GET /transactions/index.php?search={order_code}&type=INCOME&limit=5
  4. Khớp giao dịch: so amount + description chứa order_code + type=in
  5. Cập nhật đơn paid khi tìm thấy.

Use Case: Webhook Callback

Nhận push notification thay vì polling. Server gửi callback khi có giao dịch mới.

Payload mẫu

FieldTypeMô tả
eventstring"transaction.confirmed"
order_codestringMã đơn hàng
amountintegerSố tiền
bankstringNgân hàng
trans_idstringMã GD ngân hàng
signstringHMAC-SHA256 chữ ký
Bảo mật: Luôn verify sign = hmac_sha256(secret, order_code|amount|trans_id|paid_at) trước khi xử lý.

Use Case: OTP Flow — Kết nối BIDV trong app

  1. User nhập login_id + password + account_number BIDV SmartBanking.
  2. Gọi Step 1: POST /accounts/connect.php với action: "request_otp".
  3. Hệ thống login BIDV, BIDV gửi SMS OTP đến SĐT user.
  4. User nhập OTP vào ô trên app.
  5. Gọi Step 2: POST /accounts/connect.php với action: "verify_otp" + otp: "123456".
  6. Nếu đúng, tài khoản được lưu với session đã xác thực, cron tự động đồng bộ giao dịch.

Demo trực tiếp

Test API ngay từ trình duyệt.

Lấy thông tin tài khoản + token hiện tại.

* Giữ nguyên login_id/password/account từ Step 1

Lấy cấu hình site (logo, title, contact).

// Kết quả sẽ hiện ở đây...

Base URL

https://client.apinganhang.net/api/v1

Auth Header

Authorization: Bearer eyJhbGci...

Login

curl -X POST https://client.apinganhang.net/api/v1/auth/login.php \
  -H "Content-Type: application/json" \
  -d '{"username":"demo","password":"123456"}'

200 Response:

{
  "success": true,
  "token": "eyJhbGci...",
  "user": {
    "id": 5,
    "username": "demo",
    "email": "[email protected]",
    "money": 150000,
    "time_momo": 1788998400
  }
}

Profile

curl https://client.apinganhang.net/api/v1/auth/profile.php \
  -H "Authorization: Bearer <token>"

200 Response:

{
  "success": true,
  "data": {
    "id": 5,
    "username": "demo",
    "email": "[email protected]",
    "money": 150000,
    "time_momo": 1788998400,
    "token": "eyJhbGci...",
    "id_telegram": 123456789
  }
}

List Accounts

curl "https://client.apinganhang.net/api/v1/accounts/index.php?bank=MBBANK" \
  -H "Authorization: Bearer <token>"

200 Response:

{
  "success": true,
  "data": [
    {
      "id": 268,
      "bank_code": "MBBANK",
      "account_number": "0368492618",
      "holder_name": "NGUYEN VAN A",
      "balance": 19437345,
      "active": 1
    }
  ]
}

Connect OTP — Step 1

curl -X POST https://client.apinganhang.net/api/v1/accounts/connect.php \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "request_otp",
    "bank_code": "BIDV",
    "login_id": "bidv_user",
    "password": "bidv_pass",
    "account_number": "8877172056"
  }'

200

{
  "success": true,
  "step": "otp_required",
  "message": "Mã OTP đã được gửi đến SĐT"
}

Connect OTP — Step 2

curl -X POST https://client.apinganhang.net/api/v1/accounts/connect.php \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "action": "verify_otp",
    "bank_code": "BIDV",
    "login_id": "bidv_user",
    "password": "bidv_pass",
    "account_number": "8877172056",
    "otp": "123456"
  }'

200

{
  "success": true,
  "step": "done",
  "message": "Xác thực OTP thành công",
  "data": { "id": 68, "bank_code": "BIDV" }
}

Transactions

# 20 giao dịch mới nhất
curl "https://client.apinganhang.net/api/v1/transactions/index.php?limit=20" \
  -H "Authorization: Bearer <token>"

# Lọc theo bank + ngày
curl "https://client.apinganhang.net/api/v1/transactions/index.php?\
bank=MBBANK&date_from=2026-04-01&date_to=2026-04-16" \
  -H "Authorization: Bearer <token>"

# Tìm kiếm
curl "https://client.apinganhang.net/api/v1/transactions/index.php?\
search=INV2026001&type=INCOME" \
  -H "Authorization: Bearer <token>"

200

{
  "success": true,
  "data": [
    {
      "id": 25533,
      "amount": 1000000,
      "bank": "MBBANK",
      "ref_no": "FT26105370000088",
      "description": "NGUYEN VAN A CK",
      "type": "in",
      "account": "0368492618",
      "balance_after": 19437345,
      "transaction_time": "15/04/2026 09:30:00",
      "created_at": 1776395400
    }
  ],
  "pagination": {
    "page": 1, "limit": 20,
    "total": 150, "total_pages": 8
  },
  "totals": {
    "total_in": 5000000,
    "total_out": 2000000,
    "net": 3000000
  }
}

Xác minh thanh toán (PHP)

<?php
$token = 'YOUR_TOKEN';
$base  = 'https://client.apinganhang.net/api/v1';
$order = 'INV20260416001';
$expect = 500000;

$url = "$base/transactions/index.php?" .
  http_build_query([
    'search' => $order,
    'type'   => 'INCOME',
    'limit'  => 10,
  ]);

$ch = curl_init($url);
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer $token",
  ],
  CURLOPT_TIMEOUT => 15,
]);
$res = json_decode(curl_exec($ch), true);
curl_close($ch);

foreach ($res['data'] ?? [] as $txn) {
  if (
    abs($txn['amount']) === $expect &&
    stripos($txn['description'], $order) !== false
  ) {
    echo "Paid! ref={$txn['ref_no']}\n";
    break;
  }
}
?>

Xác minh thanh toán (Node.js)

const axios = require('axios');
const TOKEN = 'YOUR_TOKEN';
const BASE = 'https://client.apinganhang.net/api/v1';

async function verify(order, amount, bank) {
  const { data } = await axios.get(
    `${BASE}/transactions/index.php`,
    {
      params: { search: order, type: 'INCOME', limit: 10, bank },
      headers: { Authorization: `Bearer ${TOKEN}` },
    }
  );
  return (data.data || []).find(t =>
    Math.abs(t.amount) === amount &&
    (t.description || '').toLowerCase()
      .includes(order.toLowerCase())
  );
}

verify('INV20260416001', 500000, 'MBBANK')
  .then(m => console.log(m ? 'Paid' : 'Pending'));

Webhook Callback Payload

POST https://your-site.com/payment/callback
Content-Type: application/json

{
  "event": "transaction.confirmed",
  "order_code": "INV20260416001",
  "amount": 500000,
  "bank": "MBBANK",
  "trans_id": "FT26105370000088",
  "account": "0368492618",
  "paid_at": 1776395400,
  "sign": "hmac_sha256(secret, ...)"
}

Verify Webhook Signature (PHP)

<?php
$secret = 'YOUR_SECRET';
$body = json_decode(
  file_get_contents('php://input'), true
);
$expected = hash_hmac('sha256',
  implode('|', [
    $body['order_code'],
    $body['amount'],
    $body['trans_id'],
    $body['paid_at'],
  ]),
  $secret
);
if (!hash_equals($expected, $body['sign'])) {
  http_response_code(403);
  die('Invalid signature');
}
echo json_encode(['received' => true]);
?>

Site Settings

curl https://client.apinganhang.net/api/v1/services/site-settings.php \
  -H "Authorization: Bearer <token>"

200

{
  "success": true,
  "data": {
    "title": "API Ngân hàng",
    "description": "Hệ thống API ngân hàng...",
    "logo": "https://client.apinganhang.net/public/assets/img/logo.png",
    "hotline": "0123456789",
    "link_facebook": "https://...",
    "link_zalo": ""
  }
}

Bank Packages

curl https://client.apinganhang.net/api/v1/services/packages.php \
  -H "Authorization: Bearer <token>"

200

{
  "success": true,
  "data": [
    {
      "id": 1,
      "bank_code": "MBBANK",
      "name": "MB Bank API",
      "price": 50000,
      "features": "Thông báo GD, lấy số dư",
      "active": 1
    }
  ]
}