Skip to main content

Khan Bank payment gateway SDK for Python

Project description

mongolian-payment-khanbank

Khan Bank payment gateway SDK for Python. Supports both synchronous and asynchronous usage.

Installation

pip install mongolian-payment-khanbank

Usage

Synchronous

from mongolian_payment_khanbank import KhanBankClient, KhanBankConfig, OrderRegisterInput

client = KhanBankClient(KhanBankConfig(
    endpoint="https://ecommerce.khanbank.com/payment/rest",
    username="your_username",
    password="your_password",
))

# Register a new order
result = client.register_order(OrderRegisterInput(
    order_number="ORD-001",
    amount=50000,
    success_callback="https://example.com/success",
    fail_callback="https://example.com/fail",
))

print(result.order_id)  # Bank-assigned order ID
print(result.form_url)  # Redirect user to this URL

# Check order status
status = client.check_order(result.order_id)
print(status.success)       # True if payment succeeded
print(status.error_code)
print(status.error_message)

Asynchronous

import asyncio
from mongolian_payment_khanbank import AsyncKhanBankClient, KhanBankConfig, OrderRegisterInput

async def main():
    async with AsyncKhanBankClient(KhanBankConfig(
        endpoint="https://ecommerce.khanbank.com/payment/rest",
        username="your_username",
        password="your_password",
    )) as client:
        result = await client.register_order(OrderRegisterInput(
            order_number="ORD-001",
            amount=50000,
            success_callback="https://example.com/success",
            fail_callback="https://example.com/fail",
        ))

        status = await client.check_order(result.order_id)
        print(status.success)

asyncio.run(main())

Configuration from Environment Variables

from mongolian_payment_khanbank import KhanBankClient, load_config_from_env

client = KhanBankClient(load_config_from_env())

Required environment variables:

Variable Description
KHANBANK_ENDPOINT Khan Bank API base URL
KHANBANK_USERNAME API username
KHANBANK_PASSWORD API password

Optional environment variables:

Variable Description Default
KHANBANK_LANGUAGE Language code (mn or en) mn

License

MIT

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

mongolian_payment_khanbank-1.0.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mongolian_payment_khanbank-1.0.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file mongolian_payment_khanbank-1.0.0.tar.gz.

File metadata

File hashes

Hashes for mongolian_payment_khanbank-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2275efe5fa4791150f07109ad43a51d7f0b24e70f9659dc1b750b3770a0ad45f
MD5 f9a2f8862fe92b1496b5f094f235ebcf
BLAKE2b-256 438722e1e63c95a150059e3ed1e41650a0a650cfed1bff9ec0f9c2db6c5137a3

See more details on using hashes here.

File details

Details for the file mongolian_payment_khanbank-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mongolian_payment_khanbank-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce58d2be474d0b8150438208980deb2d43d829f47966c7911824b2c0ae1abf1b
MD5 3cc49e800ae7848797169b72adb09435
BLAKE2b-256 8bf8f4d0bd4d1a21f7b701b04acffdeca082e43bbb7b31de54f513b3bde6c5d1

See more details on using hashes here.

Supported by

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