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:
- Loads the related transaction
- Resolves the payment gateway plugin
- Calls
verify_payment - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file extensible_django_commerce-1.0.0.tar.gz.
File metadata
- Download URL: extensible_django_commerce-1.0.0.tar.gz
- Upload date:
- Size: 14.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
964bd462109c69c8074785f683be5a79f14dc250ee3ca121a47ebff66ca584f0
|
|
| MD5 |
269fc04b3d723a23da1e9ad6c4bb4377
|
|
| BLAKE2b-256 |
5cb154ad8e58a9af9ca3b9d4867218114d4b73e4ec6dcd4789526f782aae52a1
|
File details
Details for the file extensible_django_commerce-1.0.0-py3-none-any.whl.
File metadata
- Download URL: extensible_django_commerce-1.0.0-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbf4385fba0b5073626f4cf50327f79a7b4c120ec585d929d2905e0cbd09cde6
|
|
| MD5 |
f5db518ac2271020a23e8b7881dffd51
|
|
| BLAKE2b-256 |
5de990a3cfabc71b75e32b70bd526cffcf7cabc0aadf9ddab00012e2401d46fc
|