Skip to main content

Django Commerce

A lightweight and extensible commerce foundation for Django projects.

django-commerce provides reusable commerce primitives such as products, carts, orders, transactions, and pluggable offsite payment gateways — designed to integrate cleanly with modular Django architectures and plugin-based systems.

This package is built on top of django-plugin-system.

CAUTION: The package has been changed signifactly and README does not guide well right now. Will be modified in near future.


Features

  • Base product abstraction
  • Shopping cart system
  • Order management
  • Transaction tracking
  • Extensible offsite payment gateway architecture
  • Plugin-based payment providers
  • Designed for reusable Django applications

Installation

Install using pip:

pip install django-commerce

Add applications to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...

    'django_plugin_system',

    'django_commerce.product',
    'django_commerce.cart',
    'django_commerce.order',
    'django_commerce.transaction',
    'django_commerce.offsite_payment_gateway',
]

Run migrations:

python manage.py migrate

Package Structure

django_commerce/
├── product/
├── cart/
├── order/
├── transaction/
└── offsite_payment_gateway/

Base Product

The package provides a reusable BaseProduct model abstraction that can be extended in your own project.

Example:

from django.db import models
from django_commerce.product.models import BaseProduct


class Product(BaseProduct):
    description = models.TextField()

Offsite Payment Gateway

The package includes an abstract offsite payment gateway system that allows developers to integrate external payment providers such as:

  • Zarinpal
  • Stripe Checkout
  • PayPal
  • Mollie
  • Any redirect-based payment provider

To create a custom gateway, extend AbstractOffsitePaymentGateway.


Creating a Payment Gateway

Example:

from django.http import HttpRequest

from django_commerce.offsite_payment_gateway.models import (
    AbstractOffsitePaymentGateway
)


class ZarinpalGateway(AbstractOffsitePaymentGateway):
    name = 'zarinpal'
    _gateway_base_url = 'https://sandbox.zarinpal.com'

    def get_payment_gateway(self, order):
        transaction = self.create_transaction(order)

        callback = self.callback_url(transaction)

        return f'{self._gateway_base_url}/start/{transaction.id}?callback={callback}'

    def verify_payment(self, transaction, callback_request: HttpRequest) -> bool:
        authority = callback_request.GET.get('Authority')

        if not authority:
            return False

        # Verify payment using provider API
        # ...

        transaction.is_verified = True
        transaction.save()

        return True

Registering Gateway Plugins

Gateways are designed to work with the plugin system.

Example registration:

from django_plugin_system import register_plugin

from .gateway import ZarinpalGateway


register_plugin(
    manager='django_commerce.offsite_payment_gateway',
    title='Zarinpal Gateway',
    plugin=ZarinpalGateway,
)

Payment Callback View

The package provides a callback endpoint handler for payment verification.

Example URL configuration:

from django.urls import path

from django_commerce.offsite_payment_gateway.views import callback_view


urlpatterns = [
    path(
        'payment-callback/<int:transaction_id>',
        callback_view,
        name='payment_callback'
    ),
]

After the payment provider redirects the user back to your application, the callback view:

  1. Loads the related transaction
  2. Resolves the payment gateway plugin
  3. Calls verify_payment
  4. Verifies and finalizes the transaction

Transactions

Each payment attempt creates a Transaction object associated with:

  • Order
  • Payment plugin
  • Verification state

This makes payment tracking and auditing easier across multiple providers.


Design Goals

This package focuses on:

  • Reusability
  • Extensibility
  • Minimal assumptions
  • Plugin-oriented architecture
  • Separation of concerns

It is intended to act as a commerce foundation rather than a complete e-commerce platform.


Development

Clone the repository:

git clone <repository-url>

Install in editable mode:

pip install -e .

Run migrations from the development project:

python manage.py migrate

License

MIT License

Metadata

Release files for extensible-django-commerce 1.0.1

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

Source distribution (sdist)

Source distribution for extensible-django-commerce 1.0.1
File Size Uploaded
extensible_django_commerce-1.0.1.tar.gz 14.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for extensible-django-commerce 1.0.1
File Interpreter ABI Platform
extensible_django_commerce-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 38.4 kB

Release files / extensible_django_commerce-1.0.1.tar.gz

Download URL extensible_django_commerce-1.0.1.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
0e22df6d5cbbaaf811d866a2b082de6cb7b42624a94ab441127c97de0fa4002f
BLAKE2b-256 checksum
How to use checksums
cb6acfb6fa311e81a8b436b73cbf80fbdb24d0a3a8838a3eed051bed16c0c524
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / extensible_django_commerce-1.0.1-py3-none-any.whl

Download URL extensible_django_commerce-1.0.1-py3-none-any.whl
Size 23.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ab204ed6b80de9a26b782fc0fd48a032be7f154e226c4212941ae8de5a9212ac
BLAKE2b-256 checksum
How to use checksums
03ab1d77b6bd7d25514bee8e348fc0a666a65704b598413436092c8571b4c5b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

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