Django integration for the Fastaar payment gateway — accept bKash & Nagad payments in Bangladesh.
Project description
Fastaar Django Plugin
Integrate bKash & Nagad payments seamlessly into your Django website/application via Fastaar.
This Django app wraps the fastaar-python SDK, exposes standard webhook views (CSRF-exempt and signature-verified), and dispatches Django signals when payments are completed or refunded.
Install
Install the package via pip (along with fastaar-python):
pip install fastaar-django
Configuration
- Add
fastaar_djangoto yourINSTALLED_APPSinsettings.py:
INSTALLED_APPS = [
# ...
'fastaar_django',
]
- Add your Fastaar credentials in
settings.py:
FASTAAR_API_KEY = 'fk_live_...' # fk_live_... or fk_test_...
FASTAAR_WEBHOOK_SECRET = 'whsec_...' # Your merchant webhook secret
FASTAAR_TIMEOUT = 15 # Optional (defaults to 15)
Keys are scoped to abilities (payments:read/write/refund, customers:read/write) and can have an
expiry date, set in the merchant panel. Calls outside the key's abilities return 403 ability_denied;
calls with an expired key return 401 authentication_error.
Setup Webhook Route
In your main urls.py, register the Fastaar webhook URL:
from django.urls import path, include
urlpatterns = [
# ...
path('fastaar/', include('fastaar_django.urls')),
]
This will expose the endpoint /fastaar/webhook/ (e.g. https://your-domain.com/fastaar/webhook/) which you should register in your Fastaar dashboard.
Handle Webhooks (Django Signals)
The plugin automatically verifies incoming webhook signatures and raises custom signals. You can listen to these signals in your Django apps:
from django.dispatch import receiver
from fastaar_django.signals import payment_completed, payment_refunded, webhook_received
@receiver(payment_completed)
def handle_payment_completed(sender, invoice_number, payment_id, data, **kwargs):
# invoice_number matches your internal ORDER-42 identifier
# payment_id matches the Fastaar payment ID (e.g., 01jxyz...)
print(f"Order {invoice_number} successfully paid. Fastaar payment ID: {payment_id}")
@receiver(payment_refunded)
def handle_payment_refunded(sender, invoice_number, payment_id, data, **kwargs):
print(f"Order {invoice_number} refunded. Fastaar payment ID: {payment_id}")
@receiver(webhook_received)
def handle_any_webhook(sender, event_name, data, **kwargs):
# Triggered on any incoming validated Fastaar webhook event
print(f"Received Fastaar event: {event_name}")
[!IMPORTANT] To ensure your signal receivers are loaded, make sure to import them in your Django app's
AppConfig.ready()method.
Making API Calls
The plugin provides a helper function to get an initialized FastaarClient preloaded with settings from your Django configuration:
from fastaar_django import get_fastaar_client
fastaar = get_fastaar_client()
# Create a payment intent
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',
'cancel_url': 'https://shop.example.com/cart',
})
# Redirect user to checkout url
checkout_url = payment['checkout_url']
# Refund a completed (or partially refunded) payment
payment = fastaar.refund_payment(payment_id)
# payment['status'] == 'refunded'
partial = fastaar.refund_payment(payment_id, 200) # refund only part of it
# partial['status'] == 'partially_refunded'
refunds = fastaar.list_refunds(payment_id) # full refund history, newest first
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.
Customers
The underlying FastaarClient exposes the full Customers API:
from fastaar_django import get_fastaar_client
fastaar = get_fastaar_client()
# Create a customer — name and phone are required
customer = fastaar.create_customer({
'name': 'Rahim Uddin',
'phone': '01712345678',
'email': 'rahim@example.com', # 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'})
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_django-1.0.3.tar.gz.
File metadata
- Download URL: fastaar_django-1.0.3.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1865d94fffd99a98cedf379ae9ac2ba71d9aa6272fe844ac353413e38bd5492
|
|
| MD5 |
07826b077d769c30727d0ca1c476b890
|
|
| BLAKE2b-256 |
7c0094545aa424aafbead656dd40f2b37349ce34c17a290ebecef22e74c1f071
|
Provenance
The following attestation bundles were made for fastaar_django-1.0.3.tar.gz:
Publisher:
ci.yml on fastaar/fastaar-django
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastaar_django-1.0.3.tar.gz -
Subject digest:
f1865d94fffd99a98cedf379ae9ac2ba71d9aa6272fe844ac353413e38bd5492 - Sigstore transparency entry: 2169259151
- Sigstore integration time:
-
Permalink:
fastaar/fastaar-django@97a9f669b94005841f2d69d0131798e873630a85 -
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@97a9f669b94005841f2d69d0131798e873630a85 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastaar_django-1.0.3-py3-none-any.whl.
File metadata
- Download URL: fastaar_django-1.0.3-py3-none-any.whl
- Upload date:
- Size: 5.4 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 |
e12c4855bf8392d9be930412d1d388cf8bc38108a7b844fd7e50d94045d2843c
|
|
| MD5 |
334877f54be111358eb2597580e6b462
|
|
| BLAKE2b-256 |
61313d79b7879980521e1fe72a41ab62c1f57f8a96aa1313cb208bbe79749bfa
|
Provenance
The following attestation bundles were made for fastaar_django-1.0.3-py3-none-any.whl:
Publisher:
ci.yml on fastaar/fastaar-django
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastaar_django-1.0.3-py3-none-any.whl -
Subject digest:
e12c4855bf8392d9be930412d1d388cf8bc38108a7b844fd7e50d94045d2843c - Sigstore transparency entry: 2169259166
- Sigstore integration time:
-
Permalink:
fastaar/fastaar-django@97a9f669b94005841f2d69d0131798e873630a85 -
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@97a9f669b94005841f2d69d0131798e873630a85 -
Trigger Event:
push
-
Statement type: