Skip to main content

A Django utility for eSewa signature generation.

Project description

Django-esewa

A simple, developer-friendly package for integrating the eSewa Payment Gateway into Django applications.

Overview

django-esewa was developed by Nischal Lamichhane to simplify eSewa integration for Python/Django developers. It aims to handle common payment gateway tasks like generating HMAC signatures, verifying transactions, and status checks (in future versions).

Features

  • HMAC Key Generation: Easily generate the signature required for eSewa requests.
  • Customization: Configure secret keys, product codes, success URLs, and failure URLs.

Future Goals

  • Transaction status verification.
  • Improved documentation for all class methods.

QuickStart

pip install django-esewa

Note: Ensure you have added necessary settings like ESEWA_SECRET_KEY, ESEWA_SUCCESS_URL, and ESEWA_FAILURE_URL in your settings.py.

Even though you can use the generate_signature function without creating an object of EsewaPayment, if you want to use other features, you need to add ESEWA_SUCCESS_URL, ESEWA_FAILURE_URL (will fallback to localhost:8000/success/ & localhost:8000/failure/) & ESEWA_SECRET_KEY (will fall back to '8gBm/:&EnhH.1/q').

ESEWA_SUCCESS_URL = "localhost:8000/success/"
ESEWA_FAILURE_URL = "localhost:8000/failure/"
ESEWA_SECRET_KEY = "<Custom_key_from_Esewa>"

Usage

Generating a Signature

The generate_signature function helps create the HMAC signature required by eSewa for secure transactions.

Function Signature:

def generate_signature(
    total_amount: float,
    transaction_uuid: str,
    key: str = "8gBm/:&EnhH.1/q",
    product_code: str = "EPAYTEST"
) -> str:

Example:

from esewa import generate_signature

# During Development
signature = generate_signature(1000, "123abc")

# In Production
signature = generate_signature(1000, "123abc", "<your_private_key>", "<product_code>")

Using the EsewaPayment Class

EsewaPayment provides additional configuration options for success and failure URLs. List of all methods in EsewaPayment:

  • __init__()
  • create_signature()
  • generate_payload()
  • get_status()
  • is_completed()
  • verify_signature()
  • log_transaction()
  • __eq__()

List of In-development methods:

  • generate_redirect_url()
  • refund_payment()
  • simulate_payment()

Initialization:

from esewa import EsewaPayment

payment = EsewaPayment(
    product_code="EPAYTEST",
    success_url="http://yourdomain.com/success/",
    failure_url="http://yourdomain.com/failure/",
    secret_key="your_secret_key"
)

Settings

To use custom configurations, add the following keys to your settings.py:

# settings.py

ESEWA_SECRET_KEY = "your_secret_key"
ESEWA_SUCCESS_URL = "http://yourdomain.com/success/"
ESEWA_FAILURE_URL = "http://yourdomain.com/failure/"

If these settings are missing, the package will use the following defaults:

  • ESEWA_SECRET_KEY: "8gBm/:&EnhH.1/q"
  • ESEWA_SUCCESS_URL: "http://localhost:8000/success/"
  • ESEWA_FAILURE_URL: "http://localhost:8000/failure/"

Contributing

Current To-Do List

  • Add is_success() method for transaction status verification.
  • Write documentation for all methods in the EsewaPayment class.

How to Contribute

  1. Fork this repository.
  2. Create a feature branch.
  3. Commit your changes with clear messages.
  4. Submit a pull request (PR) with a detailed description of your changes.

Credits

django-esewa is maintained by Nischal Lamichhane. This package was created as a last-ditch effort to help Python/Django developers integrate eSewa Payment Gateway efficiently.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_esewa-0.1.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

django_esewa-0.1.3-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file django_esewa-0.1.3.tar.gz.

File metadata

  • Download URL: django_esewa-0.1.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.5

File hashes

Hashes for django_esewa-0.1.3.tar.gz
Algorithm Hash digest
SHA256 4f37d59278e9c73bf8e579e369401143d9262e1b61c9f0df24819f2f51835f02
MD5 9caf44439d8de4f21f770ab7c318f28e
BLAKE2b-256 47b3b1ec4876e2bcb98fb51bd8b0c9af8711c2807b4dd1d1ffe6bcc13b0025ec

See more details on using hashes here.

File details

Details for the file django_esewa-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_esewa-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c9ae40193d019c6aea600022143a0de39d206f1e32ae3f6d932da568fcaf9db3
MD5 72a20dce2a1a11816b80348923876a27
BLAKE2b-256 4f0cdfbcd0f863c3831e6ce47e7b63c1494002e56783cbc4327da70bcd003fd0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page