Skip to main content

django-khalti is a Django app based on djangorestframework to conduct server based payment verification of khalti payment gateway. For each payment,it can verify and return status of payment through transaction token and paid amount.

Detailed documentation is in the “docs” directory.

Quick start

  1. Intall the django-khalti and django rest framework like this:

    pip install djangorestframework
    pip install django-khalti
  2. Add “django-khalti” and “djangorestframework “to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = [
        ...
        'rest_framework',
        'khalti',
    ]
  3. Include the django-khalti URLconf in your project urls.py like this:

    path('khalti/', include('khalti.urls')),
  4. Add Khalti Merchant API key and Verify URL in your settings.py

    KHALTI_SECRET_KEY = "<your api key>"
    KHALTI_VERIFY_URL = "https://khalti.com/api/v2/payment/verify/"

5.Test your endpoints like this:

POST: /khalti/verifypayment/
body:{
    'token':<transaction token>,
    'amount':<transaction amount>
}

6.You will get responses like this:

On Success:
    {
        'status':True,
        'details':{
                      "idx": "8xmeJnNXfoVjCvGcZiiGe7",
                      "type": {
                        "idx": "e476BL6jt9kgagEmsakyTL",
                        "name": "Wallet payment"
                      },
                      "state": {
                        "idx": "DhvMj9hdRufLqkP8ZY4d8g",
                        "name": "Completed",
                        "template": "is complete"
                      },
                      "amount": 1000,
                      "fee_amount": 30,
                      "refunded": false,
                      "created_on": "2018-06-20T14:48:08.867125+05:45",
                      "ebanker": null,
                      "user": {
                        "idx": "cCaPkRPQGn5D8StkiqqMJg",
                        "name": "Test User",
                        "mobile": "98XXXXXXX9"
                      },
                      "merchant": {
                        "idx": "UM75Gm2gWmZvA4TPwkwZye",
                        "name": "Test Merchant",
                        "mobile": "testmerchant@khalti.com"
                      }
                }
    }

On Error:
    {
        'status':False,
        'details':{'token': ['Invalid token.']}
    }

Release files for django-khalti 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-khalti 1.0
File Size Uploaded
django-khalti-1.0.tar.gz 3.9 kB Details

Release files / django-khalti-1.0.tar.gz

Download URL django-khalti-1.0.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
428d116d5b18a717b6cc5805f5d3941781d73a252609cbccdbb5097820428578
BLAKE2b-256 checksum
How to use checksums
cdf3061a06997844b087d1e87604c79729a2841442d19e0729f60c8803e8b983
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

1.0 This release

1 release file

0.2

1 release file

0.1

1 release file

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