Skip to main content

A Python package for generating payment transactions compliant with the Bakong KHQR standard. (Unofficial NBC Library)

Project description

bakong-khqr (Unofficial)

A Python package for generating payment transactions compliant with the Bakong KHQR standard.

Requirement

Installation

pip3 install bakong-khqr

or Update Last Version

pip3 install --upgrade bakong-khqr

Usage

The bakong-khqr package provides the KHQR class for generating QR code, Deeplink, Check Payment transaction for Bakong KHQR.

Video Toturials

Importing the Library

You can import the KHQR class from the package as follows:

from bakong_khqr import KHQR

Creating Payment Transaction

To generate QR code data for a transaction, create an instance of the KHQR() class with Bakong Token and call the:

  • create_qr() method with the required parameters.
  • generate_deeplink() method with the required parameters.
  • generate_md5() method with the required parameters.
  • check_payment() method with the required parameters.
  • check_bulk_payments() method with the required parameters.

Example:

from bakong_khqr import KHQR

# Create an instance of KHQR with Bakong Developer Token
khqr = KHQR("eyJhbGciOiJIUzI1NiIsI...nMhgG87BWeDg9Lu-_CKe1SMqC0")

# Generate QR code data for a transaction
qr = khqr.create_qr(
    bank_account='your_name@wing', # Check your address under Bakong profile (Mobile App)
    merchant_name='Your Name',
    merchant_city='Phnom Penh',
    amount=9800, #9800 Riel
    currency='KHR', # USD or KHR
    store_label='MShop',
    phone_number='85512345678',
    bill_number='TRX019283775',
    terminal_label='Cashier-01',
    static=False # Static or Dynamic QR code (default: False)
)
print(qr)
# String Result: 00020101021229180014your_name@wing520459995802KH5909Your Name6010Phnom Penh991700131724927295157541100000009800530311662610112TRX0192837750211855123456780305MShop0717Buy 1A_Level_Book63041087

# Generate Deeplink
deeplink = khqr.generate_deeplink(
    qr,
    callback="https://your_website.com/shop/details?q=ABC", # Or your app's custom scheme (e.g., mshop://purchase/39482)
    appIconUrl="https://your_website.com/images/logo.png", # Your logo image .png or .svg
    appName="MyAppName" # (e.g., MSHOP)
)
print(deeplink)
# String Result: https://bakong.page.link/CgXb....ks6az9a38

# Get Hash MD5
md5 = khqr.generate_md5(qr)
print(md5)
# String Result: dfcabf4598d1c405a75540a3d4ca099d

# Check Transaction paid or unpaid
payment_status = khqr.check_payment(md5)
print(payment_status)
# String Result: "UNPAID"
# Indicates that this transaction has not yet been paid.

# Check Bulk Transactions
md5_list = [
    "dfcabf4598d1c405a75540a3d4ca099d", 
    "5154e4f795634ff1a0ae4b48e53a6d9c",
    "a57d9bb85f52f12a20cf7beecb03d11d",
    "495fdaec0be5d94c89bc1283c7283d3d",
    "31bca02094ad576588e42b60db57bc98"
]

bulk_payments_status = khqr.check_bulk_payments(md5_list)
print(bulk_payments_status)
# List Result: ["5154e4f795634ff1a0ae4b48e53a6d9c", "495fdaec0be5d94c89bc1283c7283d3d"]
# Returns a list containing only the MD5 hashes that correspond to successful (paid) transactions.

Parameters for create_qr() Method

  • bank_account: The bank account associated with the transaction.
  • merchant_name: Name of the merchant.
  • merchant_city: City where the merchant is located.
  • amount: Amount to be transacted.
  • currency: Currency of the transaction (e.g., 'USD', 'KHR').
  • store_label: Label or name of the store.
  • phone_number: Contact phone number.
  • bill_number: Reference number for the bill.
  • terminal_label: Label for the terminal.
  • static: Static or Dynamic QR code (default: static = False).

Parameters for generate_deeplink() Method

  • qr: Valid QR Code data as string that generate from create_qr() method.
  • callback: Deeplink URL for opening your app after payment is completed.
  • appIconUrl: Your App Icon URL.
  • appName: Your App Name.

Parameters for generate_md5() Method

  • qr: Valid QR Code data as string that generate from create_qr() method.

Parameters for check_payment() Method

  • md5: Valid hash md5 from generate_md5() method of the correct transaction.

Parameters for check_bulk_payments() Method

  • md5_list: md5 list of all transacrions generate from generate_md5() method.

Bakong Official

KHQR SDK Documentation: https://bakong.nbc.gov.kh/download/KHQR/integration/KHQR%20SDK%20Document.pdf

Development API: https://sit-api-bakong.nbc.gov.kh/

Production API: https://api-bakong.nbc.gov.kh/

License

This project is licensed under the MIT License. See the LICENSE file for details.

Contributing

If you would like to contribute to this project, please fork the repository and submit a pull request.

Contact

For any questions or feedback, you can contact ME or Buy Me A Coffee ☕️ ABA: 000510062

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bakong_khqr-0.2.7.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

bakong_khqr-0.2.7-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file bakong_khqr-0.2.7.tar.gz.

File metadata

  • Download URL: bakong_khqr-0.2.7.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for bakong_khqr-0.2.7.tar.gz
Algorithm Hash digest
SHA256 7965fe60a2de4f069b519c8bb205444a9c4fe80bb61f0523392686bb84bd901e
MD5 6ee72a713ad9590691e6c7cb39473c15
BLAKE2b-256 febaebdaeb711e1e7a0d73526e44628f3642a338fbc44868da219f731ea05bd8

See more details on using hashes here.

File details

Details for the file bakong_khqr-0.2.7-py3-none-any.whl.

File metadata

  • Download URL: bakong_khqr-0.2.7-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for bakong_khqr-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e60ad25e09a0866a58a57abbb054f81a5e43dc3f160055519c5e6418c62c2fcd
MD5 84cc928dea0cb657d098483287b48ae2
BLAKE2b-256 59dcd03f9cda048cf00e78d229cf0330b3fcd824da886b21e2e0feef6028b3c9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page