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:
- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d70a74e68f729a8a7c4dd615bd13e3fdf8c3c2b77a8428b74baff4066814825e
|
|
| MD5 |
caa74ba1c8bd2a9376cbd51ba5532a59
|
|
| BLAKE2b-256 |
1613af245ea2ea8ca19f9ce1d39e803caa906a66d7feaafee152a21d15dbd713
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_payment_gateway-0.1.5.tar.gz -
Subject digest:
d70a74e68f729a8a7c4dd615bd13e3fdf8c3c2b77a8428b74baff4066814825e - Sigstore transparency entry: 991685489
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Barrzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
331c05fbbf9f91e08e6fcdd341395de57315383e97f74b449b901c7762d5db08
|
|
| MD5 |
434d72d7e084b9e189d2b5155eb09983
|
|
| BLAKE2b-256 |
43297dd88fb15631f3679a96ad809115cccd9b3308953da83e38d46a419bf51b
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_payment_gateway-0.1.5-cp39-abi3-win_amd64.whl -
Subject digest:
331c05fbbf9f91e08e6fcdd341395de57315383e97f74b449b901c7762d5db08 - Sigstore transparency entry: 991685515
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Barrzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.9+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7582fcb10dafcbf04a7c4c991f252e27b0fd8becb264cb1b6ffc24cff763b9e
|
|
| MD5 |
485803ef45ac8094979e2c1cf9a0ad45
|
|
| BLAKE2b-256 |
2c9059b54a898dd9cf374be4b8e1433801df1f37f2bf2ae524773b0ff031020c
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
f7582fcb10dafcbf04a7c4c991f252e27b0fd8becb264cb1b6ffc24cff763b9e - Sigstore transparency entry: 991685492
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Barrzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Trigger Event:
workflow_dispatch
-
Statement type:
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
- Download URL: bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.2 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d2af5683abb85b3c64c364be8e35e5a6b4e618d2cace4093c2f42f6a53af614
|
|
| MD5 |
e16da1727c989dfe79b1084bff6a2dc7
|
|
| BLAKE2b-256 |
3122bfa7daa37f7a7c4b290d1c9e179d804e2a7090ea030b773480731600ca53
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_payment_gateway-0.1.5-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
8d2af5683abb85b3c64c364be8e35e5a6b4e618d2cace4093c2f42f6a53af614 - Sigstore transparency entry: 991685501
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Barrzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b82ef859ecc744eddd24e31821a9defa4b50843d64692c8a99d1397f66f11b5
|
|
| MD5 |
1807c2de621d811e3a48d84e39fe63ea
|
|
| BLAKE2b-256 |
4b7f5fecaab8df10f66aaa881b2787153d6a4f51b14261f70b2dfa7bd587d027
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_payment_gateway-0.1.5-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
5b82ef859ecc744eddd24e31821a9defa4b50843d64692c8a99d1397f66f11b5 - Sigstore transparency entry: 991685496
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Barrzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.9+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2123953d56b02b7240deb0bb33ffc3f11d7e6820132ce683c2d2b927bf19d21
|
|
| MD5 |
0fb93c2919bc7b9d1334347b7beff6ce
|
|
| BLAKE2b-256 |
d8dbf20a0bf0528ab9281dd79d165d7c3bb91f1f8ff2d0686dc7baf82c77475d
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bd_payment_gateway-0.1.5-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
a2123953d56b02b7240deb0bb33ffc3f11d7e6820132ce683c2d2b927bf19d21 - Sigstore transparency entry: 991685507
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Barrzen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@46a5979fad7e0e7c787151ee10f7be9176e98669 -
Trigger Event:
workflow_dispatch
-
Statement type: