account-pay
v0.2.0
Published
Unofficial Khan Bank (e.khanbank.com) client: login, account transactions, IBAN generation and account holder lookup
Maintainers
Readme
account-pay
Unofficial Node.js client for Khan Bank e-banking (e.khanbank.com).
Log in with your e-banking credentials, list account transactions, build Mongolian IBANs offline, and look up account holders at any Mongolian bank.
This library talks to the same private API the e-banking web app uses. It is not endorsed by Khan Bank and may break whenever the bank changes its API. Use it only with your own account.
Install
npm install account-payRequires Node.js 16 or newer. TypeScript types are included.
Quick start
import AccountPay from "account-pay";
await AccountPay.Auth({
DEVICE_ID: "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", // "device-id" header from browser dev tools
ACCOUNT: 5400012345, // your Khan Bank account number
USER: "login.name", // e-banking login
PASSWORD: "********", // e-banking password
USERNAME: "OWNER NAME", // account owner as shown in e-banking
});
// Transactions for the last 2 days
const rows = await AccountPay.listTransaction(2);
// Account holder at another bank (Golomt, bankRefNo "203")
const holder = await AccountPay.transaction.retrieve("1605157029", "203");
// { fullName: "...", iban: "MN070015001605157029", account: "1605157029", name: "...", msgId: "..." }Keep credentials in environment variables or a secrets store. Never commit them.
API
Auth(options): Promise<string>
Stores the credentials and fetches an access token. Resolves to "Success Login khaanbank" or "Failed Login khaanbank"; it does not throw on a bad login, so check the returned string.
| Option | Type | Description |
| --- | --- | --- |
| DEVICE_ID | string | Value of the device-id request header. Log in once at e.khanbank.com in a browser and copy it from the network tab. |
| ACCOUNT | number | Account number whose transactions you want to read. |
| USER | string | E-banking login name. |
| PASSWORD | string | E-banking password (sent base64-encoded, as the web app does). |
| USERNAME | string | Account owner name. |
The token expires after about 5 minutes. Every other call refreshes it automatically on a 401.
listTransaction(days): Promise<Transaction[]>
Raw transactions for ACCOUNT from days days ago until today. See Transaction in dist/types.d.ts for the shape.
listNewTransaction(days): Promise<PushData[]>
Same data flattened into a simpler row:
{
date: "2024-08-09 04:18:00",
accountNumber: "5400012345",
transactionType: "Credit" | "Debit",
expenseBalance: 0,
incomeBalance: 990,
beginBalance: 0,
endBalance: 990,
description: "SETTLEMENT - SELLER PANDA",
txnBranchId: "5008",
id: "17231932800990" // timestamp + endBalance
}transaction.retrieve(accountId, bankCode): Promise<AccountInquiry>
Look up an account holder. bankCode can be any of:
- a
bankRefNofromBankOfList()(for example"203"for Golomt) - a 6-digit clearing code (
"150000") - a 4-digit IBAN bank code (
"0015")
The IBAN is built locally and sent to the bank's inquiry endpoint. Rejects with the bank's { code, message } (for example CA0008 for a malformed IBAN) or with Unknown bank code if the code is not in the list.
transaction.retrieveByIban(iban): Promise<AccountInquiry>
Same lookup when you already have the IBAN.
interface AccountInquiry {
fullName: string;
iban: string;
account: string;
msgId: string;
name: string;
}transaction.generateIban(bankClearingCode, account): string
Builds a Mongolian IBAN offline: MN + 2 check digits + 4-digit bank code + account zero-padded to 12 digits. Accepts a 6-digit clearing code or a 4-digit bank code. This only computes the checksum and does not verify that the account exists.
AccountPay.transaction.generateIban("150000", "1605157029"); // "MN070015001605157029"
AccountPay.transaction.generateIban("040000", 5400038909); // "MN720004005400038909"transaction.resolveBankClearingCode(bankCode): Promise<string>
Resolves a bankRefNo, clearing code, or IBAN bank code to the 6-digit clearing code.
transaction.BankOfList(): Promise<Bank[]>
Static list of banks known to Khan Bank's transfer form, with bankName, bankClearingCode, bankRefNo, and network type (RTG, ACH, SWI).
Development
npm install
npm run build-ts # compile to dist/
npm test # runs test/index.ts with ts-node; set KHAN_* env vars firstnpm publish runs the build automatically via prepublishOnly.
License
ISC
