django-hesabpay
Beginner-friendly Django SDK for the HesabPay Payment Gateway.
Start a hosted checkout with hesabpay.checkout(...), then run your business logic in @on_payment_success. Redirects are for UX. Verified webhooks are the source of truth.
Install
pip install django-hesabpay
Requires Python 3.10+ and Django 4.2+.
Quickstart
1. Settings
# settings.py
INSTALLED_APPS = [
# ...
"hesabpay",
]
HESABPAY = {
"ENVIRONMENT": "sandbox", # or "production"
"SANDBOX_API_KEY": "your-sandbox-key",
# "PRODUCTION_API_KEY": "your-live-key", # when ENVIRONMENT=production
"HANDLERS": ["shop.payments"], # modules that register @on_payment_success
}
2. Migrate
python manage.py migrate
Webhook and status routes register automatically. The default webhook path is /hesabpay/webhook/. Copy that URL into the HesabPay dashboard.
3. Start checkout
import hesabpay
from django.shortcuts import redirect
def pay(request, order):
checkout = hesabpay.checkout(order, user=request.user)
return redirect(checkout.url)
Or from a template:
{% load hesabpay %}
{% hesabpay_checkout_button order user=request.user %}
JSON APIs can return checkout.as_dict() with payment_id, checkout_url, and status.
4. Fulfill after payment
# shop/payments.py
from hesabpay import on_payment_success
@on_payment_success
def fulfill(context):
# enroll, unlock, email, ship: your product decides
order = context.instance
user = context.user
if not context.is_first_success:
return
...
Amounts are AFN. Currency conversion is out of scope for v1.
Example shop
A runnable course shop lives in examples/basic_shop/:
cd examples/basic_shop
pip install -e ../..
python manage.py migrate
python manage.py seed_courses
python manage.py createsuperuser
python manage.py runserver
Multi-vendor (advanced)
After a payment succeeds, settle vendors with an encrypted PIN (documented HesabPay API):
from hesabpay import transfer_to_vendors
transfer_to_vendors(
payment=payment,
vendors=[{"account_number": "700000001", "amount": 50}],
pin="1234",
)
Auto-settle is off by default (AUTO_VENDOR_TRANSFER).
Commands
python manage.py hesabpay doctor
python manage.py hesabpay simulate-webhook <payment_reference>
Django admin includes payments, webhook events, vendor payouts, and activity logs. Use Replay fulfillment handlers on a webhook event if a handler failed after the payment was already acknowledged.
Official API docs
HesabPay documentation: https://docs.hesab.com/
Metadata
Release files for django-hesabpay 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_hesabpay-0.1.1.tar.gz | 22.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_hesabpay-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 52.7 kB
Release files / django_hesabpay-0.1.1.tar.gz
| Download URL | django_hesabpay-0.1.1.tar.gz |
|---|---|
| Size | 22.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5faa5d0106aab395544974f037f0ac14c5bde90d8c12b9a6d9c3b8ac5c75eabb
|
|
BLAKE2b-256 checksum How to use checksums |
a72c5dbe0ac2ddaabccda132ebb40e0fa880afca53c8f970bc1b5e3c27cccc70
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 4, 2026.
Transparency logRelease files / django_hesabpay-0.1.1-py3-none-any.whl
| Download URL | django_hesabpay-0.1.1-py3-none-any.whl |
|---|---|
| Size | 30.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
461fdbeeae7e9c9183a25a4a22861aba9c8450f3db0314adc9182b5d5ef4853b
|
|
BLAKE2b-256 checksum How to use checksums |
91471809a11bb34ba73e694034ea692b36e0f3178f21686c0b27f1e265b2474e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Aug 4, 2026.
Transparency log