Python SDK for the Fastaar payment gateway — accept bKash & Nagad payments in Bangladesh.
Project description
Fastaar Python SDK
Accept bKash & Nagad payments on any Python website or application via Fastaar.
This is a zero-dependency SDK utilizing Python's standard library.
Install
Install the package via pip (or configure it in your requirements.txt / pyproject.toml):
pip install fastaar-python
Create a payment & redirect to checkout
Here is an example using a generic Python web application:
import os
from fastaar import FastaarClient
fastaar = FastaarClient(api_key=os.getenv('FASTAAR_API_KEY')) # fk_live_... or fk_test_...
# The key must have the `payments:write` ability (and not be expired) or this
# call returns a 403 `ability_denied` / 401 `authentication_error` error.
payment = fastaar.create_payment({
'amount': 1250,
'invoice_number': 'ORDER-42', # required — your order reference
'customer_id': customer['id'] if customer else None, # optional — attach an existing customer
'success_url': 'https://shop.example.com/thanks', # optional, customer returns here
'cancel_url': 'https://shop.example.com/cart', # optional
})
# Redirect the customer to checkout
checkout_url = payment['checkout_url']
print(f"Redirecting customer to: {checkout_url}")
invoice_number is idempotent: if a payment already exists for it and hasn't reached failed
or expired, creating another one raises a FastaarException with error type
duplicate_invoice_number (HTTP 409) instead of creating a duplicate — so a dropped connection
never double-charges. Use find_by_invoice_number() to look the existing payment up rather than
retrying blindly.
Confirm the order from a webhook
Verify the signature header to ensure webhook security:
import os
from fastaar import WebhookSignature, FastaarException
# Get raw request body as bytes/string and signature header from request
raw_body = request.body # must be the raw string or bytes of the request body
signature = request.headers.get('X-Fastaar-Signature', '')
secret = os.getenv('FASTAAR_WEBHOOK_SECRET')
if not WebhookSignature.verify(secret, raw_body, signature):
# Signature verification failed
return "Invalid signature", 400
# Parse the event
event = request.json()
if event['event'] == 'payment.completed':
order_id = event['data']['invoice_number']
payment_id = event['data']['id']
# Mark the order as paid idempotently using the payment_id as key
print(f"Payment completed: {payment_id} for invoice {order_id}")
return "OK", 200
Other payment calls
# Retrieve one payment by its ID (e.g. "01jxyz...")
payment = fastaar.get_payment('01jxyz...')
# Look up most recent payment by your reference
payment = fastaar.find_by_invoice_number('ORDER-42')
# List payments
payments = fastaar.list_payments(params={'status': 'completed'})
# Refund a completed (or partially refunded) payment
payment = fastaar.refund_payment('01jxyz...') # refund the full remaining balance
payment = fastaar.refund_payment('01jxyz...', 200) # or refund only part of it
refunds = fastaar.list_refunds('01jxyz...') # full refund history, newest first
Customers
Store customer records to attach them to payments collected via payment links.
# Create a customer — name and phone are required
customer = fastaar.create_customer({
'name': 'Rahim Uddin',
'phone': '01712345678',
'email': 'rahim@example.com', # optional
'address': 'Dhaka, Bangladesh', # optional
'notes': 'VIP customer', # optional
})
# Retrieve, update, list
customer = fastaar.get_customer(customer['id'])
customer = fastaar.update_customer(customer['id'], {'name': 'Rahim Ahmed'})
customers = fastaar.list_customers({'email': 'rahim@example.com'})
Error Handling
Errors raise fastaar.FastaarException with error_type (e.g. authentication_error, subscription_required, transaction_limit_reached, connection_error) and status_code.
from fastaar import FastaarException
try:
payment = fastaar.create_payment({'amount': 100, 'invoice_number': 'ORDER-42'})
except FastaarException as e:
print(f"API Error: {e}")
print(f"Type: {e.error_type}")
print(f"Status Code: {e.status_code}")
Test mode
Use an fk_test_ key: payments auto-complete on the checkout page without real money, and webhooks fire exactly like production with "livemode": false.
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 Distribution
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 fastaar_python-1.0.3.tar.gz.
File metadata
- Download URL: fastaar_python-1.0.3.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43b4bd64cb253b66d10736080dc5e0b6f10b48e85c694c75931e218a4f862546
|
|
| MD5 |
b5f477df1b7cb08cea48fac04a6c0309
|
|
| BLAKE2b-256 |
e3d1ed522443a40a35289e01521ac5ac60d0977c12b101767fec016626bbb203
|
Provenance
The following attestation bundles were made for fastaar_python-1.0.3.tar.gz:
Publisher:
ci.yml on fastaar/fastaar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastaar_python-1.0.3.tar.gz -
Subject digest:
43b4bd64cb253b66d10736080dc5e0b6f10b48e85c694c75931e218a4f862546 - Sigstore transparency entry: 2169098922
- Sigstore integration time:
-
Permalink:
fastaar/fastaar-python@19e6ce2cd9de5d8d5d4d00335173005a063797d9 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/fastaar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@19e6ce2cd9de5d8d5d4d00335173005a063797d9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastaar_python-1.0.3-py3-none-any.whl.
File metadata
- Download URL: fastaar_python-1.0.3-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e895c13bb56bcacb3d201cb94a7ec2f19f2a06a4f5d0d850d8ba7d6b0f4ced35
|
|
| MD5 |
86ab06664aeadd5d3685aa26f8c0b6ad
|
|
| BLAKE2b-256 |
2c06c56e7490c45267ac69e1a933cf699759b62f1d5eee6bb87dde2d634570a1
|
Provenance
The following attestation bundles were made for fastaar_python-1.0.3-py3-none-any.whl:
Publisher:
ci.yml on fastaar/fastaar-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastaar_python-1.0.3-py3-none-any.whl -
Subject digest:
e895c13bb56bcacb3d201cb94a7ec2f19f2a06a4f5d0d850d8ba7d6b0f4ced35 - Sigstore transparency entry: 2169098950
- Sigstore integration time:
-
Permalink:
fastaar/fastaar-python@19e6ce2cd9de5d8d5d4d00335173005a063797d9 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/fastaar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@19e6ce2cd9de5d8d5d4d00335173005a063797d9 -
Trigger Event:
push
-
Statement type: