Skip to content

Konthaina/khqr-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

English | ខ្មែរ

konthaina-khqr

KHQR / EMVCo merchant-presented QR payload generator for Bakong / Cambodia (NBC KHQR spec v2.7-style TLV) with CRC-16/CCITT-FALSE verification.

This package generates the payload string (the EMV tag-length-value text) that you can encode into a QR image.

Install

pip install konthaina-khqr

Optional: generate QR images (PNG) using qrcode:

pip install "konthaina-khqr[qrcode]"

Features

  • Static & Dynamic KHQR
  • Correct KHR (116) / USD (840)
  • Stable static QR (no timestamp)
  • CRC-16 verification
  • Decode / verify helpers
  • CLI + PNG QR support

Quick start

from konthaina_khqr import KHQRGenerator, MerchantType, Currency

result = (
    KHQRGenerator(MerchantType.INDIVIDUAL)
    .set_bakong_account_id("john_smith@devb")
    .set_merchant_name("John Smith")
    .set_currency(Currency.USD)
    .set_amount(100.50)
    .set_merchant_city("Phnom Penh")
    .generate()
)

print(result.qr)     # KHQR payload string
print(result.md5)    # md5 of payload

Verify / decode

from konthaina_khqr import verify, decode

ok = verify(result.qr)
data = decode(result.qr)   # simple TLV decode

CLI

khqr --type individual --bakong john_smith@devb --name "John Smith" --amount 1.25 --currency USD

Generate a PNG (requires extras):

khqr --type individual --bakong john_smith@devb --name "John Smith" --amount 1.25 --currency USD --png out.png

Development

python -m venv .venv
. .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install -e ".[dev]"
pytest
ruff check .
mypy src

Build & publish

Build:

python -m build
twine check dist/*

Publish to TestPyPI:

twine upload -r testpypi dist/*

Publish to PyPI:

twine upload dist/*

For GitHub Actions + Trusted Publishing, see .github/workflows/publish.yml.

Releases

Sponsor this project

Packages

Contributors

Languages