Skip to main content

High-performance, Rust-powered, security-focused Bangladesh payment gateway library for Python

Project description

bd-payment-gateway (Python)

bd-payment-gateway is a high-performance, Rust-powered, security-focused Bangladesh payment gateway library for Python. It is built for production checkout flows with typed request models, actionable error codes, and safe defaults.

This SDK family is available in multiple languages:

Supported Providers (Python)

  • SSLCOMMERZ: ✅ Supported and stable
  • PortWallet: ❌ Not supported yet (WIP)
  • shurjoPay: ❌ Not supported yet (WIP)
  • aamarPay: ❌ Not supported yet (WIP)

Only SSLCOMMERZ is supported right now in Python.

Install

Use the copy button on each command block when your docs viewer supports it.

pip install bd-payment-gateway
uv add bd-payment-gateway
uv pip install bd-payment-gateway

Provider Docs (Python)

SSLCOMMERZ (default)

Configuration

Set these environment variables in your shell or .env file.

Environment variable Meaning Example
BDPG_SSLCOMMERZ_STORE_ID Your SSLCOMMERZ store ID testbox
BDPG_SSLCOMMERZ_STORE_PASSWD Your SSLCOMMERZ store password qwerty
BDPG_SSLCOMMERZ_ENVIRONMENT sandbox, production, or custom sandbox
BDPG_SSLCOMMERZ_CUSTOM_BASE_URL Required only when environment is custom https://sandbox.sslcommerz.com

Example:

BDPG_SSLCOMMERZ_STORE_ID=your_store_id
BDPG_SSLCOMMERZ_STORE_PASSWD=your_store_password
BDPG_SSLCOMMERZ_ENVIRONMENT=sandbox
# BDPG_SSLCOMMERZ_CUSTOM_BASE_URL=https://sandbox.sslcommerz.com

Quickstart (FastAPI)

This example shows the full payment flow:

  1. Create payment session
  2. Send user to redirect URL
  3. Handle callback endpoints (success, fail, cancel, ipn)
  4. Verify payment status
from decimal import Decimal

from fastapi import FastAPI, Request

from bd_payment_gateway.errors import PaymentGatewayError
from bd_payment_gateway.sslcommerz import SslcommerzClient
from bd_payment_gateway.sslcommerz.models import (
    Customer,
    InitiatePaymentRequest,
    Product,
    Settings,
    Urls,
    VerifyPaymentRequest,
)

app = FastAPI()
settings = Settings()  # Reads BDPG_SSLCOMMERZ_* from env/.env
client = SslcommerzClient.from_settings(settings)


@app.post("/pay")
def pay() -> dict:
    try:
        initiated = client.initiate_payment(
            InitiatePaymentRequest(
                total_amount=Decimal("500.00"),
                tran_id="TXN-10001",
                urls=Urls(
                    success_url="https://merchant.example/payment/success",
                    fail_url="https://merchant.example/payment/fail",
                    cancel_url="https://merchant.example/payment/cancel",
                    ipn_url="https://merchant.example/payment/ipn",
                ),
                customer=Customer(
                    name="Demo User",
                    email="demo@example.com",
                    address_line_1="Dhaka",
                    city="Dhaka",
                    country="Bangladesh",
                    phone="01700000000",
                ),
                product=Product(
                    name="Python Course",
                    category="Education",
                    profile="general",
                ),
            )
        )
    except PaymentGatewayError as err:
        return {"error": err.message, "code": err.code, "hint": err.hint}

    # Frontend should redirect the customer to this URL.
    return {"redirect_url": str(initiated.redirect_url)}


@app.get("/payment/success")
def payment_success(request: Request) -> dict:
    # SSLCOMMERZ sends sessionkey in callback query params.
    session_key = request.query_params.get("sessionkey", "")
    if not session_key:
        return {"error": "Missing sessionkey in callback"}

    try:
        verified = client.verify_payment(
            VerifyPaymentRequest(session_key=session_key)
        )
    except PaymentGatewayError as err:
        return {"error": err.message, "code": err.code, "hint": err.hint}

    return {
        "status": verified.status,
        "provider_reference": verified.provider_reference,
        "amount": str(verified.amount) if verified.amount else None,
    }


@app.get("/payment/fail")
def payment_fail() -> dict:
    return {"status": "failed"}


@app.get("/payment/cancel")
def payment_cancel() -> dict:
    return {"status": "cancelled"}


@app.post("/payment/ipn")
def payment_ipn() -> dict:
    # IPN = Instant Payment Notification from SSLCOMMERZ server.
    return {"received": True}

Alternative without environment variables

You can configure the client directly without setting BDPG_SSLCOMMERZ_* vars:

from bd_payment_gateway.sslcommerz import SslcommerzClient
from bd_payment_gateway.sslcommerz.models import Settings

settings = Settings(
    store_id="your_store_id",
    store_passwd="your_store_password",
    environment="sandbox",
)
client = SslcommerzClient.from_settings(settings)
PortWallet (Python: coming soon)

Python bindings are not published yet.

shurjoPay (Python: coming soon)

Python bindings are not published yet.

aamarPay (Python: coming soon)

Python bindings are not published yet.

Common Errors and Troubleshooting (SSLCOMMERZ)

  • ValidationError when loading Settings:
    • Cause: missing BDPG_SSLCOMMERZ_* values.
    • Fix: set required environment variables exactly as shown above.
  • PaymentGatewayError with provider error code:
    • Cause: wrong credentials, invalid callback URLs, or invalid transaction data.
    • Fix: check err.code, err.message, and err.hint in your except block.
  • Payment stays pending:
    • Cause: customer has not completed payment yet.
    • Fix: verify again after callback/IPN or poll with your own retry logic.

Links

Have a suggestion, integration request, or bug report? Please open an issue: https://github.com/Barrzen/bd-payment-gateway/issues/new/choose

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

bd_payment_gateway-0.1.5.tar.gz (98.2 kB view details)

Uploaded Source

Built Distributions

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

bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl (2.5 MB view details)

Uploaded CPython 3.9+Windows x86-64

bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.28+ ARM64

bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.2 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl (3.0 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl (3.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file bd_payment_gateway-0.1.5.tar.gz.

File metadata

  • Download URL: bd_payment_gateway-0.1.5.tar.gz
  • Upload date:
  • Size: 98.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bd_payment_gateway-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d70a74e68f729a8a7c4dd615bd13e3fdf8c3c2b77a8428b74baff4066814825e
MD5 caa74ba1c8bd2a9376cbd51ba5532a59
BLAKE2b-256 1613af245ea2ea8ca19f9ce1d39e803caa906a66d7feaafee152a21d15dbd713

See more details on using hashes here.

Provenance

The following attestation bundles were made for bd_payment_gateway-0.1.5.tar.gz:

Publisher: publish-python.yml on Barrzen/bd-payment-gateway

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 331c05fbbf9f91e08e6fcdd341395de57315383e97f74b449b901c7762d5db08
MD5 434d72d7e084b9e189d2b5155eb09983
BLAKE2b-256 43297dd88fb15631f3679a96ad809115cccd9b3308953da83e38d46a419bf51b

See more details on using hashes here.

Provenance

The following attestation bundles were made for bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl:

Publisher: publish-python.yml on Barrzen/bd-payment-gateway

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 f7582fcb10dafcbf04a7c4c991f252e27b0fd8becb264cb1b6ffc24cff763b9e
MD5 485803ef45ac8094979e2c1cf9a0ad45
BLAKE2b-256 2c9059b54a898dd9cf374be4b8e1433801df1f37f2bf2ae524773b0ff031020c

See more details on using hashes here.

Provenance

The following attestation bundles were made for bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl:

Publisher: publish-python.yml on Barrzen/bd-payment-gateway

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8d2af5683abb85b3c64c364be8e35e5a6b4e618d2cace4093c2f42f6a53af614
MD5 e16da1727c989dfe79b1084bff6a2dc7
BLAKE2b-256 3122bfa7daa37f7a7c4b290d1c9e179d804e2a7090ea030b773480731600ca53

See more details on using hashes here.

Provenance

The following attestation bundles were made for bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish-python.yml on Barrzen/bd-payment-gateway

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5b82ef859ecc744eddd24e31821a9defa4b50843d64692c8a99d1397f66f11b5
MD5 1807c2de621d811e3a48d84e39fe63ea
BLAKE2b-256 4b7f5fecaab8df10f66aaa881b2787153d6a4f51b14261f70b2dfa7bd587d027

See more details on using hashes here.

Provenance

The following attestation bundles were made for bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: publish-python.yml on Barrzen/bd-payment-gateway

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 a2123953d56b02b7240deb0bb33ffc3f11d7e6820132ce683c2d2b927bf19d21
MD5 0fb93c2919bc7b9d1334347b7beff6ce
BLAKE2b-256 d8dbf20a0bf0528ab9281dd79d165d7c3bb91f1f8ff2d0686dc7baf82c77475d

See more details on using hashes here.

Provenance

The following attestation bundles were made for bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: publish-python.yml on Barrzen/bd-payment-gateway

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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