Skip to main content

Basic yet highly extensible requirements for commerce in django.

Project description

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

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

extensible_django_commerce-1.0.0.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

extensible_django_commerce-1.0.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file extensible_django_commerce-1.0.0.tar.gz.

File metadata

File hashes

Hashes for extensible_django_commerce-1.0.0.tar.gz
Algorithm Hash digest
SHA256 964bd462109c69c8074785f683be5a79f14dc250ee3ca121a47ebff66ca584f0
MD5 269fc04b3d723a23da1e9ad6c4bb4377
BLAKE2b-256 5cb154ad8e58a9af9ca3b9d4867218114d4b73e4ec6dcd4789526f782aae52a1

See more details on using hashes here.

File details

Details for the file extensible_django_commerce-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for extensible_django_commerce-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbf4385fba0b5073626f4cf50327f79a7b4c120ec585d929d2905e0cbd09cde6
MD5 f5db518ac2271020a23e8b7881dffd51
BLAKE2b-256 5de990a3cfabc71b75e32b70bd526cffcf7cabc0aadf9ddab00012e2401d46fc

See more details on using hashes here.

Supported by

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