Skip to main content

Unified Python SDK for Bangladeshi payment gateways

Project description

bpay

Unified Python SDK for Bangladeshi payment gateways.

bpay provides a clean, typed, async-first developer experience for integrating Bangladeshi payment providers like bKash, Nagad, and SSLCommerz.


Features

  • Async-first architecture
  • Typed request & response models
  • Sandbox & production environment support
  • Hosted checkout workflows
  • Agreement/tokenized checkout support
  • Payment callback parsing
  • Payment verification support
  • Provider abstraction layer
  • Modern Python packaging with uv

Supported Providers

Provider Status
bKash In Progress
Nagad Planned
SSLCommerz Planned

Installation

pip install bpay

Quick Start

Create a One-Time Payment

import asyncio

from bpay import BPay
from bpay.config.environments import (
    Environment,
)
from bpay.schemas.payment import (
    CreatePaymentRequest,
)


async def main() -> None:
    client = BPay(
        provider="bkash",
        environment=Environment.SANDBOX,
        username="YOUR_USERNAME",
        password="YOUR_PASSWORD",
        app_key="YOUR_APP_KEY",
        app_secret="YOUR_APP_SECRET",
    )

    payment = await client.create_payment(
        CreatePaymentRequest(
            amount=100,
            merchant_invoice_number="INV-1001",
            callback_url=(
                "https://yourdomain.com/callback"
            ),
        )
    )

    print(payment.checkout_url)


if __name__ == "__main__":
    asyncio.run(main())

Agreement / Tokenized Checkout

Agreements allow merchants to create reusable customer payment authorizations for recurring or saved payments.

Create Agreement

import asyncio

from bpay import BPay
from bpay.config.environments import (
    Environment,
)
from bpay.schemas.agreement import (
    CreateAgreementRequest,
)


async def main() -> None:
    client = BPay(
        provider="bkash",
        environment=Environment.SANDBOX,
        username="YOUR_USERNAME",
        password="YOUR_PASSWORD",
        app_key="YOUR_APP_KEY",
        app_secret="YOUR_APP_SECRET",
    )

    agreement = await (
        client.create_agreement(
            CreateAgreementRequest(
                customer_phone="017XXXXXXXX",
                callback_url=(
                    "https://yourdomain.com/callback"
                ),
            )
        )
    )

    print(agreement.checkout_url)


if __name__ == "__main__":
    asyncio.run(main())

Callback Parsing

Payment Callback

from bpay import BPay

client = BPay(...)

callback = client.parse_payment_callback(
    {
        "paymentID": "PAY123",
        "status": "success",
        "signature": "abc123",
    }
)

print(callback.status)

Agreement Callback

from bpay import BPay

client = BPay(...)

callback = (
    client.parse_agreement_callback(
        {
            "paymentID": "PAY123",
            "agreementID": "AGR123",
            "status": "success",
            "signature": "abc123",
        }
    )
)

print(callback.status)

Payment Verification

verification = await client.verify_payment(
    payment_id="PAY123"
)

print(verification.status)

Environments

bpay supports both sandbox and production environments.

Sandbox

from bpay.config.environments import (
    Environment,
)

Environment.SANDBOX

Production

from bpay.config.environments import (
    Environment,
)

Environment.PRODUCTION

Development

Setup

uv sync

Run Checks

make check

Run Tests

uv run pytest

Project Structure

src/bpay/
├── client.py
├── exceptions.py
├── config/
├── providers/
├── schemas/
├── transports/
└── types.py

Roadmap

  • Full bKash recurring payment workflow
  • Nagad integration
  • SSLCommerz integration
  • Refund support
  • Webhook signature verification
  • Automatic retry handling
  • Sync client support
  • Logging middleware

License

MIT License

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

bpay-0.1.0.tar.gz (54.1 kB view details)

Uploaded Source

Built Distribution

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

bpay-0.1.0-py3-none-any.whl (15.4 kB view details)

Uploaded Python 3

File details

Details for the file bpay-0.1.0.tar.gz.

File metadata

  • Download URL: bpay-0.1.0.tar.gz
  • Upload date:
  • Size: 54.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for bpay-0.1.0.tar.gz
Algorithm Hash digest
SHA256 66e01e52b9fe35b1afb97657deaa299bb34f337add65e55ed6de236b4b83c935
MD5 3a95cf5251dbf4925fcd14880d59c925
BLAKE2b-256 8feefb8d3812481466dc6c84030b8b8c8a387d837c3511919e754fea59a573c3

See more details on using hashes here.

File details

Details for the file bpay-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: bpay-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for bpay-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9994dd3e9fca802faf351d9549c94381ec479467ed8ca5ca6a8218e3153a4998
MD5 f5728fffbd3d05a8760c5b769b015737
BLAKE2b-256 42c0af7e7e3b9a45c262ef211556cd4993ed4276aed7e71808121e6c80819d6e

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