Skip to main content
The Bill class wraps the official Iranian bill verification algorithm. Given a billId + paymentId (or a combined 26-digit barcode), it can validate both check digits, classify the bill type (water, electricity, …), and compute the amount in toman or rial.

Construction

All parameters are optional, but most methods require either billId + paymentId or barcode to do real work.

Public methods

getResult() shape

Bill type encoding

The penultimate digit of the bill ID encodes the service: The full BillTypes union and the billTypes lookup map are exported.

Amount calculation

The last 5 digits of paymentId are control + scaling; the rest are the amount in 100s of toman or 1000s of rial. Picking the wrong currency is a 10× error — match it to your downstream domain.

Type exports

Pitfalls

  • Result field is type, not billType. Older docs use billType — those accesses return undefined.
  • All constructor params are optional, but calling getResult() on an empty Bill returns garbage (NaN amount, “unknown” type, etc.). Guard upstream.
  • unknown bill type forces verificationBillId() to return false even if math checks out — intentional.
  • No Persian/Arabic digit normalization on the barcode — convert first if input may contain them.

Source

src/modules/bill/index.ts · Tests: test/bill.spec.ts