Skip to main content

django-hesabpay

Beginner-friendly Django SDK for the HesabPay Payment Gateway.

Mental model: hesabpay.checkout(...) → @on_payment_success for your business logic → optional status poll. Redirects are UX; webhooks are truth.

Install

pip install django-hesabpay

Requires Python 3.10+ and Django 4.2+.

From this repo during development:

pip install -e ".[dev]"

Release process: see RELEASING.md. Changes: CHANGELOG.md.

5-minute 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 (default webhook: /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() → payment_id, checkout_url, 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>

In Django admin: payments, webhook events, vendor payouts, activity logs.
Use Replay fulfillment handlers on webhook events if a handler failed after payment was already acked.

Docs for contributors / AI agents

See AGENTS.md for architecture, guardrails, and progress.

Official HesabPay docs: https://docs.hesab.com/

Metadata

Release files for django-hesabpay 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-hesabpay 0.1.0
File Size Uploaded
django_hesabpay-0.1.0.tar.gz 24.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-hesabpay 0.1.0
File Interpreter ABI Platform
django_hesabpay-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 54.8 kB

Release files / django_hesabpay-0.1.0.tar.gz

Download URL django_hesabpay-0.1.0.tar.gz
Size 24.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d4b9014a1a18ff37412d5bbfbbe7ee28f6e7fb1386e1b0268413f127f89a7d2b
BLAKE2b-256 checksum
How to use checksums
ba24ee99aa9f5e2dfc48aac2b9014665a883dc6fde1d3d73645c8404b0c13bc7
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

Release files / django_hesabpay-0.1.0-py3-none-any.whl

Download URL django_hesabpay-0.1.0-py3-none-any.whl
Size 30.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
060478aa4d40fd8aba279148afe017807d3e1ca95a728ff91fdf46bcf3c08297
BLAKE2b-256 checksum
How to use checksums
30c88efa1acaf27159e40e02b26e7ad79a18f21961245beb2577896a2892b161
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

Release history Release notifications | RSS feed

0.1.9

2 release files

0.1.8

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page