Skip to main content

QPay payment gateway SDK for Python

Project description

mongolian-payment-qpay

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

This is a Python port of the QPay JS SDK.

Installation

pip install mongolian-payment-qpay

Usage

Sync Client

from mongolian_payment_qpay import QPayClient, QPayConfig, CreateInvoiceInput

client = QPayClient(QPayConfig(
    username="MY_USERNAME",
    password="MY_PASSWORD",
    endpoint="https://merchant.qpay.mn/v2",
    callback="https://example.com/callback",
    invoice_code="MY_INVOICE_CODE",
    merchant_id="MY_MERCHANT_ID",
))

# Create an invoice
invoice = client.create_invoice(CreateInvoiceInput(
    sender_code="SENDER",
    sender_branch_code="BRANCH",
    receiver_code="RECEIVER",
    description="Test payment",
    amount=1000,
))

print(invoice.invoice_id)
print(invoice.qr_text)
print(invoice.qpay_short_url)

# Check payment status
from mongolian_payment_qpay import CheckPaymentOptions

result = client.check_payment(CheckPaymentOptions(invoice_id=invoice.invoice_id))
print(f"Paid: {result.paid_amount}, Count: {result.count}")
for row in result.rows:
    print(f"  {row.payment_id}: {row.payment_status}")

# Get invoice details
details = client.get_invoice(invoice.invoice_id)

# Cancel an invoice
client.cancel_invoice(invoice.invoice_id)

# Refund a payment
client.refund_payment("payment_id")

Async Client

import asyncio
from mongolian_payment_qpay import AsyncQPayClient, QPayConfig, CreateInvoiceInput

async def main():
    client = AsyncQPayClient(QPayConfig(
        username="MY_USERNAME",
        password="MY_PASSWORD",
        endpoint="https://merchant.qpay.mn/v2",
        callback="https://example.com/callback",
        invoice_code="MY_INVOICE_CODE",
        merchant_id="MY_MERCHANT_ID",
    ))

    invoice = await client.create_invoice(CreateInvoiceInput(
        sender_code="SENDER",
        sender_branch_code="BRANCH",
        receiver_code="RECEIVER",
        description="Test payment",
        amount=1000,
    ))

    print(invoice.invoice_id)

asyncio.run(main())

Loading Config from Environment Variables

Set the following environment variables:

Variable Description
QPAY_USERNAME QPay API username
QPAY_PASSWORD QPay API password
QPAY_ENDPOINT QPay API base URL (e.g. https://merchant.qpay.mn/v2)
QPAY_CALLBACK Callback URL for payment notifications
QPAY_INVOICE_CODE Invoice code assigned by QPay
QPAY_MERCHANT_ID Merchant ID assigned by QPay

Then load the config:

from mongolian_payment_qpay import QPayClient, load_config_from_env

config = load_config_from_env()
client = QPayClient(config)

API Reference

QPayClient / AsyncQPayClient

Both clients have identical method signatures. The async client uses async/await.

Method Description
create_invoice(input_) Create a new invoice
get_invoice(invoice_id) Get invoice details by ID
cancel_invoice(invoice_id) Cancel an invoice by ID
get_payment(payment_id) Get payment details by ID
check_payment(options) Check payment status for an invoice
cancel_payment(options) Cancel a payment
refund_payment(payment_id) Refund a payment by ID

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_qpay-1.0.0.tar.gz (9.8 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_qpay-1.0.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mongolian_payment_qpay-1.0.0.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.13

File hashes

Hashes for mongolian_payment_qpay-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4d5b552737409fb6c39bc8aad2cea9c907caed07b104a361c96caf456e9a0f71
MD5 0c73572d344964d4779b960b80a23f42
BLAKE2b-256 86bb52c9ad627c10f33e70b3d5009f84d51356a7d999bdf1d49845eac412b6e0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mongolian_payment_qpay-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed5374b9abac5115453ed9512bb6f9484d84eb64a4a121d0e3f5cfc231dd6c86
MD5 2122ab54b341d241bfe17a5e2be442f4
BLAKE2b-256 15687e37a3d05c778ebf888d840b3fbcdb844cb24737f7ab15415b8067f08f6b

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