Python bindings for Bangladesh payment gateway SDK
Project description
bd-payment-gateway (Python)
bd-payment-gateway helps you collect online payments in Bangladesh using a Python API.
It gives you a typed SSLCOMMERZ client for create-session, redirect, callback handling, and payment verification.
You can start from environment variables and call strongly typed request models.
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
pip install bd-payment-gateway
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 (SSLCOMMERZ)
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 flask import Flask, jsonify, 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 = Flask(__name__)
settings = Settings() # Reads BDPG_SSLCOMMERZ_* from env/.env
client = SslcommerzClient.from_settings(settings)
@app.post("/pay")
def pay() -> tuple[dict, int]:
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}, 400
# Frontend should redirect the customer to this URL.
return {"redirect_url": str(initiated.redirect_url)}, 200
@app.get("/payment/success")
def payment_success() -> tuple[dict, int]:
# SSLCOMMERZ sends sessionkey in callback query params.
session_key = request.args.get("sessionkey", "")
if not session_key:
return {"error": "Missing sessionkey in callback"}, 400
try:
verified = client.verify_payment(
VerifyPaymentRequest(session_key=session_key)
)
except PaymentGatewayError as err:
return {"error": err.message, "code": err.code, "hint": err.hint}, 400
return {
"status": verified.status,
"provider_reference": verified.provider_reference,
"amount": str(verified.amount) if verified.amount else None,
}, 200
@app.get("/payment/fail")
def payment_fail() -> tuple[dict, int]:
return {"status": "failed"}, 200
@app.get("/payment/cancel")
def payment_cancel() -> tuple[dict, int]:
return {"status": "cancelled"}, 200
@app.post("/payment/ipn")
def payment_ipn() -> tuple[dict, int]:
# IPN = Instant Payment Notification from SSLCOMMERZ server.
return jsonify({"received": True}), 200
Common Errors and Troubleshooting
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
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.4.tar.gz.
File metadata
- Download URL: bd_payment_gateway-0.1.4.tar.gz
- Upload date:
- Size: 96.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dbc59998c3f92e96f67a06b7c94fae583b8dcc496f38e8e82fd7165f5005d0e
|
|
| MD5 |
f6b6ac33343df6e57cc1a6efe8511968
|
|
| BLAKE2b-256 |
bd3ca3248b076a5aa193651bc035cb6d1397370092cd8a15918a107b8bd9b2bd
|
Provenance
The following attestation bundles were made for bd_payment_gateway-0.1.4.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.4.tar.gz -
Subject digest:
5dbc59998c3f92e96f67a06b7c94fae583b8dcc496f38e8e82fd7165f5005d0e - Sigstore transparency entry: 991601758
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
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@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.4-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.4-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 |
224d49abf54007fcfe2165a2b1104dd4592e190453728e069162ad74d3b9b663
|
|
| MD5 |
6ad8e9cfa0492418b17e486d02acab1b
|
|
| BLAKE2b-256 |
9c76d4e4b097c8a2535792047b4dbe3c9e7f5200186d1fbf6040a319d93914be
|
Provenance
The following attestation bundles were made for bd_payment_gateway-0.1.4-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.4-cp39-abi3-win_amd64.whl -
Subject digest:
224d49abf54007fcfe2165a2b1104dd4592e190453728e069162ad74d3b9b663 - Sigstore transparency entry: 991601760
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
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@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.4-cp39-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.4-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 |
a54d670b940abad13e49847549d7eac752d43ffea1b82b8ab09f0cfd94ae7685
|
|
| MD5 |
75b7fc11c503a63d739617dcb47cde7f
|
|
| BLAKE2b-256 |
24d21e34beb99745d55f78d18427a7a5df3acd241518ed5555ec3954baa39ce4
|
Provenance
The following attestation bundles were made for bd_payment_gateway-0.1.4-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.4-cp39-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
a54d670b940abad13e49847549d7eac752d43ffea1b82b8ab09f0cfd94ae7685 - Sigstore transparency entry: 991601765
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
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@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.4-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 |
f781117d7ddda78bb91dd79ea8353eda075dc03bbb8228d370649eb1da50a494
|
|
| MD5 |
0d2cf63a751b76a3ae9c87c61a6d94c6
|
|
| BLAKE2b-256 |
5ccc7c09ce03bd4afa245f71667b1045db880603b12d41ed7cf4a7cdccfbc4ed
|
Provenance
The following attestation bundles were made for bd_payment_gateway-0.1.4-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.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
f781117d7ddda78bb91dd79ea8353eda075dc03bbb8228d370649eb1da50a494 - Sigstore transparency entry: 991601769
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
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@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.4-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.4-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 |
ed53de97fceb1ed6ac030baa1ed87ff39a1632025c502fb4c54eb5240ea12b86
|
|
| MD5 |
b253cb395f0fecdd01bf33e62a7cf786
|
|
| BLAKE2b-256 |
731e8084936f9c422f4614f8eca6e9d81e59b80529d55512d81ca94b8befdb40
|
Provenance
The following attestation bundles were made for bd_payment_gateway-0.1.4-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.4-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
ed53de97fceb1ed6ac030baa1ed87ff39a1632025c502fb4c54eb5240ea12b86 - Sigstore transparency entry: 991601768
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
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@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bd_payment_gateway-0.1.4-cp39-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: bd_payment_gateway-0.1.4-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 |
d8c81ecc99589195ec90dfc1a3c1cdbe5801c47f8d8a278e2c155516787825ec
|
|
| MD5 |
42e365287ff72661b98f96647f0379ca
|
|
| BLAKE2b-256 |
a9baa32992add819050fed7cd101186e938c9210546944977132c2de118f5e80
|
Provenance
The following attestation bundles were made for bd_payment_gateway-0.1.4-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.4-cp39-abi3-macosx_10_12_x86_64.whl -
Subject digest:
d8c81ecc99589195ec90dfc1a3c1cdbe5801c47f8d8a278e2c155516787825ec - Sigstore transparency entry: 991601761
- Sigstore integration time:
-
Permalink:
Barrzen/bd-payment-gateway@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
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@de4944a19a1cfd809bca5bcae5b7e79c922a3665 -
Trigger Event:
workflow_dispatch
-
Statement type: