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:
- Python:
bd-payment-gateway(this package) - JavaScript/TypeScript:
bd-payment-gateway-js - Rust:
bd-payment-gateway
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:
- Create payment session
- Send user to redirect URL
- Handle callback endpoints (
success,fail,cancel,ipn) - 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.
- Rust crate docs: https://github.com/Barrzen/bd-payment-gateway/tree/main/bd-payment-gateway-portwallet
- JavaScript package docs: https://github.com/Barrzen/bd-payment-gateway/tree/main/bd-payment-gateway-js
shurjoPay (Python: coming soon)
Python bindings are not published yet.
- Rust crate docs: https://github.com/Barrzen/bd-payment-gateway/tree/main/bd-payment-gateway-shurjopay
- JavaScript package docs: https://github.com/Barrzen/bd-payment-gateway/tree/main/bd-payment-gateway-js
aamarPay (Python: coming soon)
Python bindings are not published yet.
- Rust crate docs: https://github.com/Barrzen/bd-payment-gateway/tree/main/bd-payment-gateway-aamarpay
- JavaScript package docs: https://github.com/Barrzen/bd-payment-gateway/tree/main/bd-payment-gateway-js
Common Errors and Troubleshooting (SSLCOMMERZ)
ValidationErrorwhen loadingSettings:- Cause: missing
BDPG_SSLCOMMERZ_*values. - Fix: set required environment variables exactly as shown above.
- Cause: missing
PaymentGatewayErrorwith provider error code:- Cause: wrong credentials, invalid callback URLs, or invalid transaction data.
- Fix: check
err.code,err.message, anderr.hintin yourexceptblock.
- Payment stays pending:
- Cause: customer has not completed payment yet.
- Fix: verify again after callback/IPN or poll with your own retry logic.
Links
- GitHub repository: https://github.com/Barrzen/bd-payment-gateway
- Project home page: https://github.com/Barrzen/bd-payment-gateway#readme
- Documentation index: https://github.com/Barrzen/bd-payment-gateway/tree/main/docs
- SSLCOMMERZ quickstart doc: https://github.com/Barrzen/bd-payment-gateway/blob/main/docs/QUICKSTART_SSLCOMMERZ.md
- Python API spec: https://github.com/Barrzen/bd-payment-gateway/blob/main/docs/PYTHON_API_SPEC.md
- Issue tracker: https://github.com/Barrzen/bd-payment-gateway/issues
Have a suggestion, integration request, or bug report? Please open an issue: https://github.com/Barrzen/bd-payment-gateway/issues/new/choose
Metadata
Release files for bd-payment-gateway 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| bd_payment_gateway-0.1.5.tar.gz | 98.2 kB | With provenance | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ ARM64 | Details |
| bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
| bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details |
Total release size: 15.0 MB
Release files / bd_payment_gateway-0.1.5.tar.gz
| Download URL | bd_payment_gateway-0.1.5.tar.gz |
|---|---|
| Size | 98.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d70a74e68f729a8a7c4dd615bd13e3fdf8c3c2b77a8428b74baff4066814825e
|
|
BLAKE2b-256 checksum How to use checksums |
1613af245ea2ea8ca19f9ce1d39e803caa906a66d7feaafee152a21d15dbd713
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logRelease files / bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl
| Download URL | bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 2.5 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
331c05fbbf9f91e08e6fcdd341395de57315383e97f74b449b901c7762d5db08
|
|
BLAKE2b-256 checksum How to use checksums |
43297dd88fb15631f3679a96ad809115cccd9b3308953da83e38d46a419bf51b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logRelease files / bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
f7582fcb10dafcbf04a7c4c991f252e27b0fd8becb264cb1b6ffc24cff763b9e
|
|
BLAKE2b-256 checksum How to use checksums |
2c9059b54a898dd9cf374be4b8e1433801df1f37f2bf2ae524773b0ff031020c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logRelease files / bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 3.2 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
8d2af5683abb85b3c64c364be8e35e5a6b4e618d2cace4093c2f42f6a53af614
|
|
BLAKE2b-256 checksum How to use checksums |
3122bfa7daa37f7a7c4b290d1c9e179d804e2a7090ea030b773480731600ca53
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logRelease files / bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 3.0 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
5b82ef859ecc744eddd24e31821a9defa4b50843d64692c8a99d1397f66f11b5
|
|
BLAKE2b-256 checksum How to use checksums |
4b7f5fecaab8df10f66aaa881b2787153d6a4f51b14261f70b2dfa7bd587d027
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logRelease files / bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 3.1 MB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
a2123953d56b02b7240deb0bb33ffc3f11d7e6820132ce683c2d2b927bf19d21
|
|
BLAKE2b-256 checksum How to use checksums |
d8dbf20a0bf0528ab9281dd79d165d7c3bb91f1f8ff2d0686dc7baf82c77475d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logSecurity for bd-payment-gateway 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 6 files in this release have been uploaded with provenance metadata.
Attestation for bd_payment_gateway-0.1.5.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 25, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.