{"id":34519702,"url":"https://github.com/bsthen/bakong-khqr","last_synced_at":"2026-05-09T06:02:15.175Z","repository":{"id":252179709,"uuid":"839641803","full_name":"bsthen/bakong-khqr","owner":"bsthen","description":"A Python package for generating payment transactions compliant with the Bakong KHQR standard.","archived":false,"fork":false,"pushed_at":"2026-04-10T10:09:34.000Z","size":395,"stargazers_count":21,"open_issues_count":0,"forks_count":10,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-10T12:17:19.821Z","etag":null,"topics":["bakong","khqr","khr","payments","pypi","python","python3","qr","qrcode","riel","usd"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/bakong-khqr/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bsthen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"bsthen","buy_me_a_coffee":"bsthen"}},"created_at":"2024-08-08T03:20:32.000Z","updated_at":"2026-04-10T10:08:52.000Z","dependencies_parsed_at":"2025-12-24T05:05:13.991Z","dependency_job_id":null,"html_url":"https://github.com/bsthen/bakong-khqr","commit_stats":null,"previous_names":["bsthen/bakong-khqr"],"tags_count":26,"template":false,"template_full_name":null,"purl":"pkg:github/bsthen/bakong-khqr","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsthen%2Fbakong-khqr","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsthen%2Fbakong-khqr/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsthen%2Fbakong-khqr/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsthen%2Fbakong-khqr/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bsthen","download_url":"https://codeload.github.com/bsthen/bakong-khqr/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bsthen%2Fbakong-khqr/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32809147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bakong","khqr","khr","payments","pypi","python","python3","qr","qrcode","riel","usd"],"created_at":"2025-12-24T04:37:47.506Z","updated_at":"2026-05-09T06:02:15.169Z","avatar_url":"https://github.com/bsthen.png","language":"Python","funding_links":["https://github.com/sponsors/bsthen","https://buymeacoffee.com/bsthen"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e Bakong-KHQR (Unofficial NBC) \u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://youtu.be/24bClwP3Tzo\" target=\"_blank\" \u003e\n        \u003cimg src=\"https://cdn.jsdelivr.net/gh/bsthen/bsthen/dev_qr.png\" width=\"500px\" heigh=\"492px\" alt=\"YouTube\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\nA Python package for generating payment transactions compliant with the Bakong KHQR standard.\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://opensource.org/licenses/MIT\" target=\"_blank\" \u003e\n        \u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\" alt=\"License\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/bakong-khqr/\" target=\"_blank\" \u003e\n        \u003cimg src=\"https://img.shields.io/pypi/pyversions/bakong-khqr.svg\" alt=\"Python Version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/bakong-khqr/\" target=\"_blank\" \u003e\n        \u003cimg src=\"https://img.shields.io/pypi/v/bakong-khqr?color=%2334D058\u0026label=pypi%20package\" alt=\"PyPI version\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://socket.dev/pypi/package/bakong-khqr/\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://badge.socket.dev/pypi/package/bakong-khqr/0.5.8?artifact_id=tar-gz\"\n             alt=\"Socket Security\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pepy.tech/projects/bakong-khqr\" target=\"_blank\" \u003e\n        \u003cimg src=\"https://static.pepy.tech/badge/bakong-khqr\" alt=\"Downloads\"\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n## 📱 Download Mobile App\n\n- \u003cimg src=\"https://cdn.jsdelivr.net/gh/bsthen/bsthen/bakong_app.png\"\n       alt=\"Bakong App\"\n       width=\"28\"\n       style=\"vertical-align: middle;\" /\u003e\n  \u003cstrong style=\"margin: 0 6px;\"\u003eBakong App\u003c/strong\u003e\n  \u003ca href=\"https://apps.apple.com/kh/app/bakong/id1440829141\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/App_Store-0D96F6?style=flat\u0026logo=app-store\u0026logoColor=white\"\n           style=\"vertical-align: middle;\" /\u003e\n  \u003c/a\u003e | \n  \u003ca href=\"https://play.google.com/store/apps/details?id=jp.co.soramitsu.bakong\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/Google_Play-414141?style=flat\u0026logo=google-play\u0026logoColor=white\"\n           style=\"vertical-align: middle;\" /\u003e\n  \u003c/a\u003e\n\n- \u003cimg src=\"https://cdn.jsdelivr.net/gh/bsthen/bsthen/bakong_tourists.png\"\n       alt=\"Bakong Tourists\"\n       width=\"28\"\n       style=\"vertical-align: middle;\" /\u003e\n  \u003cstrong style=\"margin: 0 6px;\"\u003eBakong Tourists\u003c/strong\u003e\n  \u003ca href=\"https://apps.apple.com/kh/app/bakong-tourists/id6471774666\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/App_Store-0D96F6?style=flat\u0026logo=app-store\u0026logoColor=white\"\n           style=\"vertical-align: middle;\" /\u003e\n  \u003c/a\u003e | \n  \u003ca href=\"https://play.google.com/store/apps/details?id=kh.gov.nbc.bakong.tourist\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/badge/Google_Play-414141?style=flat\u0026logo=google-play\u0026logoColor=white\"\n           style=\"vertical-align: middle;\" /\u003e\n  \u003c/a\u003e\n\n\n\n## 📋 Requirement\n\n- Python3\n- A Bakong account with full KYC verification\n- A Bakong developer token (register here: [https://api-bakong.nbc.gov.kh/register/](https://api-bakong.nbc.gov.kh/register/) or RBK Token: [https://bakongrelay.com/](https://bakongrelay.com/))\n- A VPS or hosting service located in Cambodia or use RBK Token.\n\n## 📦 Installation\n\n```bash\npip3 install bakong-khqr\n```\n\nor Update Last Version\n\n```bash\npip3 install --upgrade bakong-khqr\n```\n\n## 🚀 Usage\n\nThe bakong-khqr package provides the KHQR class for generating QR code, Deeplink, Check Payment, Get Payment transaction for Bakong KHQR.\n\n### Importing the package\n\nYou can import the KHQR class from the package as follows:\n\n```bash\nfrom bakong_khqr import KHQR\n```\n\n### Creating Payment Transaction\n\nTo generate QR code data for a transaction, create an instance of the KHQR() class with Bakong Token and call the:\n\n- create_qr() method with the required parameters.\n- generate_deeplink() method with the required parameters.\n- generate_md5() method with the required parameters.\n- check_payment() method with the required parameters.\n- get_payment() method with the required parameters.\n- check_bulk_payments() method with the required parameters.\n\nExample:\n\n```bash\nfrom bakong_khqr import KHQR\n\n# Create an instance of KHQR with Bakong Developer Token:\nkhqr = KHQR(\"eyJhbGciOiJIUzI1NiIsI...nMhgG87BWeDg9Lu-_CKe1SMqC0\")\n\n# Generate QR code data for a transaction:\nqr_string = khqr.create_qr(\n    bank_account='user_name@bank', # Check your user_name@bank under Bakong profile (Mobile App)\n    merchant_name='Your Name',\n    merchant_city='Phnom Penh',\n    amount=9800, #9800 Riel\n    currency='KHR', # USD or KHR\n    store_label='Phsar Thmei',\n    phone_number='012345678',\n    bill_number='TRX012345',\n    terminal_label='POS-01',\n    static=False, # Static or Dynamic QR code (default: False)\n    expiration=1 # Expiration time in 1 day for the QR code (default: 1 day). This is used to calculate the expiration time for the QR code.\n)\nprint(qr_string)\n# String Result: 00020101021229180014your_name@bank520459995303116540498005802KH5909Your Name6010Phnom Penh62510109TRX01234502090123456780311Phsar Thmei0706POS-01993400131773894603019011317738947758196304A5A3\n\n# Generate Deeplink:\ndeeplink = khqr.generate_deeplink(\n    qr=qr_string,\n    appDeepLinkCallback=\"https://your_website.com/shop/details?q=ABC\", # Or your app's custom scheme (e.g., mshop://purchase/39482)\n    appIconUrl=\"https://your_website.com/images/logo.png\", # Your logo image .png or .svg\n    appName=\"MyAppName\" # (e.g., MSHOP)\n)\nprint(deeplink)\n# String Result: https://bakong.page.link/CgXb....ks6az9a38\n\n# Get Hash MD5\nmd5 = khqr.generate_md5(qr_string)\nprint(md5)\n# String Result: dfcabf4598d1c405a75540a3d4ca099d\n\n# Check Transaction paid or unpaid:\npayment_status = khqr.check_payment(md5)\nprint(payment_status)\n# String Result: \"UNPAID\"\n# Indicates that this transaction has not yet been paid.\n\n# Retrieve the payment information:\n#e.g. In case static QR code (static=True) is used for payment, and the amount is not known from the user's input.\npayment_info = khqr.get_payment(md5)\nprint(payment_info)\n# Object Result:\n# {\n#     \"hash\": \"a7121ca103c.....eb3671b9601a6\",\n#     \"fromAccountId\": \"bankkhppxxx@bank\",\n#     \"toAccountId\": \"your_name@bank\",\n#     \"currency\": \"KHR\",\n#     \"amount\": 9800,\n#     \"description\": \"Cashier-01\",\n#     \"createdDateMs\": 1739###953000,\n#     \"acknowledgedDateMs\": 1739###954000,\n#     \"trackingStatus\": null,\n#     \"receiverBank\": null,\n#     \"receiverBankAccount\": null,\n#     \"instructionRef\": null,\n#     \"externalRef\": \"100FT3###6550298\"\n# }\n# You can retrieve information such as the amount to integrate into your system.\n\n# Check Bulk Transactions:\nmd5_list = [\n    \"dfcabf4598d1c405a75540a3d4ca099d\", \n    \"5154e4f795634ff1a0ae4b48e53a6d9c\",\n    \"a57d9bb85f52f12a20cf7beecb03d11d\",\n    \"495fdaec0be5d94c89bc1283c7283d3d\",\n    \"31bca02094ad576588e42b60db57bc98\"\n]\n\nbulk_payments_status = khqr.check_bulk_payments(md5_list)\nprint(bulk_payments_status)\n# List Result: [\"5154e4f795634ff1a0ae4b48e53a6d9c\", \"495fdaec0be5d94c89bc1283c7283d3d\"]\n# Returns a list containing only the MD5 hashes that correspond to successful (paid) transactions.\n\n\n# ⚠️ Bulk Transaction Check Limit\n# The Bakong API allows a maximum of 50 MD5 hashes per request when using the check_bulk_payments() method.\n#If you pass more than 50 hashes, the function will raise a ValueError to prevent unexpected API errors.\n\nmd5_list = [md5_1, md5_2, ..., md5_51]  # 51 hashes\n\n# This will raise:\n# ValueError: The md5_list exceeds the allowed limit of 50 hashes per request.\nresult = khqr.check_bulk_payments(md5_list)\n\n# ✅ If you need to check more than 50 transactions, you must handle chunking manually:\ndef chunked(iterable, size=50):\n    for i in range(0, len(iterable), size):\n        yield iterable[i:i + size]\n\nall_md5 = [...]  # more than 50 md5 hashes\npaid_md5 = []\n\nfor batch in chunked(all_md5):\n    paid_md5.extend(khqr.check_bulk_payments(batch))\n\nprint(paid_md5)\n# List Result: [\"5154e4f795634ff1a0ae4b48e53a6d9c\", \"495fdaec0be5d94c89bc1283c7283d3d\"]\n# Returns a list containing only the MD5 hashes that correspond to successful (paid) transactions.\n```\n\n### Generate QR Image\n\nThe `qr_image()` method generates a QR code image from a QR string.\nMake sure you install the optional [image] extras to get dependencies like Pillow and qrcode:\n\n```bash\npip3 install \"bakong-khqr[image]\"\n```\n\nExample:\n\n```bash\nfrom bakong_khqr import KHQR\n\nkhqr = KHQR(\"your_bakong_token\")\n\nqr = khqr.create_qr(\n    bank_account='user_name@bank',\n    merchant_name='Your Name',\n    merchant_city='Phnom Penh',\n    amount=100.00,\n    currency='USD',\n    store_label='MShop',\n    phone_number='85512345678',\n    bill_number='TRX123456',\n    terminal_label='Cashier-01',\n    static=False,\n    expiration=1\n)\n\n# Generate QR image as PNG file path\npng_path = khqr.qr_image(qr)\nprint(\"QR image saved at:\", png_path)\n\n```\n\n#### Parameters for `create_qr()` Method\n\n- `bank_account`: The bank account associated with the transaction.\n- `merchant_name`: Name of the merchant.\n- `merchant_city`: City where the merchant is located.\n- `amount`: Amount to be transacted.\n- `currency`: Currency of the transaction (e.g., 'USD', 'KHR').\n- `store_label` (optional): Label or name of the store.\n- `phone_number` (optional): Contact phone number.\n- `bill_number` (optional): Reference number for the bill.\n- `terminal_label` (optional): Label for the terminal.\n- `static` (optional): Static or Dynamic QR code (default: static = False).\n- `expiration` (optional): Expiration time in days for the QR code (default: 1 day).\n\n`Note`: Using static mode will create a Static QR Code for payment, allowing unlimited transactions, usage, and a zero amount included.\n\n#### Parameters for `generate_deeplink()` Method\n\n- `qr`: Valid QR Code data as string that generate from create_qr() method.\n- `appDeepLinkCallback`: Deeplink URL for opening your app after payment is completed.\n- `appIconUrl`: Your App Icon URL.\n- `appName`: Your App Name.\n\n    ***Deprecation Note***: The parameter `callback` has been renamed to `appDeepLinkCallback` to align with the Bakong standard. While `callback` still works in the current version for backward compatibility, it will be removed in future releases. Please update your implementation.\n\n\n#### Parameters for `generate_md5()` Method\n\n- `qr`: Valid QR Code data as string that generate from create_qr() method.\n\n#### Parameters for `check_payment()` Method\n\n- `md5`: Valid hash md5 from generate_md5() method of the correct transaction.\n\n#### Parameters for `check_bulk_payments()` Method\n\n- `md5_list`: md5 list of all transacrions generate from generate_md5() method.\n\n#### Parameters for `get_payment()` Method\n\n- `md5`: Valid hash md5 from generate_md5() method of the correct transaction.\n\n#### Parameters for `qr_image()` Method\n\n- `qr`: QR string to convert into an image from create_qr().\n- `output_path`: Optional path to save the image. If not provided, returns a temp file path.\n- `format`: Image format to export ('png', 'jpeg','webp', 'bytes', 'base64' or 'base64_uri'). Default: 'png'.\n\n## ✨ Bakong Relay API Support (New in v0.5.*)\n### Why Use Bakong Relay? (Optional)\n\nMany developers face **HTTP 403 errors** when accessing Bakong APIs from servers outside Cambodia.\n\nThis service allows you to use **RBK tokens** directly in `bakong-khqr` (Python SDK), so your application can reliably check transactions, accounts, and references without restrictions.\n\n**Important**: Only `bakong-khqr` (Python SDK) supports RBK tokens.\n\nUsing Bakong Relay is **optional**.  \nIf your server is in Cambodia or you have no access issues, you can continue using official Bakong tokens — no changes are needed.\n\nFor more information, token creation, pricing, and full documentation, visit:  \n👉 **[bakongrelay.com](https://bakongrelay.com)** or **[Telegram Bot](https://t.me/bakong_relay_bot/)**\n\n## 📄 Bakong Official\n\nKHQR SDK Documentation:\n\n- [https://api-bakong.nbc.gov.kh/document](https://api-bakong.nbc.gov.kh/document)\n- [KHQR Content Guideline v1.4.pdf](https://bakong.nbc.gov.kh/download/KHQR/integration/KHQR%20Content%20Guideline%20v.1.3.pdf)\n- [QR Payment Integration.pdf](https://bakong.nbc.gov.kh/download/KHQR/integration/QR%20Payment%20Integration.pdf)\n- [KHQR SDK Document.pdf](https://bakong.nbc.gov.kh/download/KHQR/integration/KHQR%20SDK%20Document.pdf)\n\nDevelopment API: [https://sit-api-bakong.nbc.gov.kh/](https://sit-api-bakong.nbc.gov.kh/)\n\nProduction API: [https://api-bakong.nbc.gov.kh/](https://api-bakong.nbc.gov.kh/)\n\n## 📜 License\n\nThis project is licensed under the MIT License. See the [LICENSE](https://github.com/bsthen/bakong-khqr/blob/main/LICENSE) file for details.\n\n## 🤝 Contributing\n\nIf you would like to contribute to this project, please fork the repository and submit a pull request.\n\n## 📬 Contact\n\nFor any questions or feedback, you can contact me via [Mail](mailto:bansokthen@gmail.com), [Telegram](https://t.me/bakongRelaySupport/) or [Buy Me A Coffee ☕️](https://buymeacoffee.com/bsthen)\n\n\u003cp align=\"center\"\u003e\n        \u003cimg src=\"https://cdn.jsdelivr.net/gh/bsthen/bsthen@main/khqr_riel.png\" alt=\"KHQR Donation\" width=\"auto\" height=\"250\" style=\"display: inline-block; margin-right: 10px;\"\u003e\n        \u003cimg src=\"https://cdn.jsdelivr.net/gh/bsthen/bsthen@main/khqr_dollar.png\" alt=\"KHQR Donation\" width=\"auto\" height=\"250\" style=\"display: inline-block;\"\u003e\n\u003c/p\u003e\n\n## ❤️ Sponsors\n\nThis project is supported by the community.  \n👉 [List Sponsors \u0026 Donors](https://github.com/bsthen/bakong-khqr/blob/main/SPONSORS.md)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsthen%2Fbakong-khqr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbsthen%2Fbakong-khqr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbsthen%2Fbakong-khqr/lists"}