Django Payment Gateways Package
A pluggable Django package for integrating multiple payment gateways including Paystack, Flutterwave, Interswitch, and Stripe, with an extensible architecture for adding more gateways.
✨ Features
- 🔌 Plug-and-play integration
- 🔐 Paystack, Flutterwave, Interswitch, Stripe, PayPal support
- 📦 Dispatcher pattern for gateway switching
- 🧱 Abstract
BaseOrdermodel for customization - ✅ Built-in Payment Verification View (redirect-based gateways)
- 🟦 Webhook-based verification for Stripe, PayPal, Paystack, Flutterwave, and Interswitch
- 🧠 Smart unique order reference generation
- 🧪 Built-in signal handling for order reference
- 🔔
payment_confirmedsignal fired on every webhook-confirmed payment, for your own post-payment side effects - 💡 Fully customizable frontend and views
Example Project
A sample Django project demonstrating how to use this package is available here:
📦 Installation
pip install django-pg
⚙️ Project Setup
- Add the app to INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
...
'django_pg', # Your payment package
]
- Configure your Order model (Extend the BaseOrder abstract model) In your own app, create your order model by extending gateways.models.BaseOrder:
# yourapp/models.py
from django.db import models
from django_pg.models import BaseOrder
from django.contrib.auth.models import User
class Order(BaseOrder):
user = models.ForeignKey(User, on_delete=models.CASCADE)
total_price = models.DecimalField(max_digits=10, decimal_places=2)
# Add your fields here
- Define the model that handles the Order in settings.py
# settings.py
# Models used for order
PAYMENT_ORDER_MODEL = 'yourapp.Order'
🎯 Choose Your Payment Gateway
If you're using multiple payment methods (e.g. Paystack, Flutterwave, Interswitch, and stripe), make sure your template checks for the selected payment_method. If you're only using one payment method, you can pass the preferred payment method in a hidden field when the order is created.
| Gateway | Region | Best For | Webhook | Setup Guide |
|---|---|---|---|---|
| Paystack | Nigeria, Ghana, SA | Cards, Bank Transfer, USSD | ✅ | 📘 Paystack Setup |
| Flutterwave | Africa | Pan-African payments | ✅ | 📘 Flutterwave Setup |
| Interswitch | Nigeria | Enterprise, WebPAY | ✅ | 📘 Interswitch Setup |
| Stripe | Global | International customers | ✅ | 📘 Stripe Setup |
| PayPal | Global | International customers | ✅ | 📘 PayPal Setup |
Each guide covers:
- 🔑 API key configuration
- ⚙️ Gateway-specific settings
- 🧪 Testing with sandbox credentials
- 🚀 Going live checklist
- 🔧 Troubleshooting common issues
- 🟦 Webhook setup (recommended for every gateway above - a redirect-only integration never confirms a payment if the customer closes the tab before the redirect fires; the webhook confirms it independently of the browser)
- Built-in Payment Verification View django-pg provides a built-in payment_verification view that handles verifying transactions for all the payment gateways out of the box.
🔌 URL Configuration
You can use the built-in view directly in your urls.py:
from django.urls import path
from django_pg.views import payment_verification # Import from the package
urlpatterns = [
path("verify/<int:order_id>/<str:payment_method>/", payment_verification, name="payment_verification"),
]
Note: Users attempting to make a payment via Paystack and Flutterwave must have a valid email address. The Paystack and Flutterwave gateway requires this for transaction initiation. Make sure you enforce email submission when a user registers
🔁 Signals (Auto Order Reference)
You don’t need to register anything. The gateways app automatically registers a pre_save signal that generates a unique order_reference.
# gateways/signals.py
@receiver(pre_save, sender=Order)
def set_order_reference(sender, instance, **kwargs):
if not instance.order_reference:
instance.order_reference = generate_unique_order_reference()
⚠️ Since a webhook is what looks the order up (by matching order_reference
against whatever reference the gateway reports), your checkout must pass
order.order_reference as the transaction reference you hand to the gateway
(Paystack's ref, Flutterwave's/Interswitch's tx_ref) - not a randomly
generated one. Each gateway's setup guide shows this in its template example.
🔔 Signal (Payment Confirmed via Webhook)
Every webhook handler (Stripe, PayPal, Paystack, Flutterwave, Interswitch) sends this signal after successfully confirming a payment, so your project can run its own post-payment side effects - an audit log, a custom fulfilment timeline, a confirmation email - without django_pg needing to know anything about them:
from django.dispatch import receiver
from django_pg.signals import payment_confirmed
@receiver(payment_confirmed)
def on_payment_confirmed(sender, order, provider, reference, raw_response, via, **kwargs):
# via is currently always "webhook" - the client-triggered
# payment_verification view does NOT send this signal, only the
# webhook handlers do.
...
This only fires from the webhook path, not from the client-triggered
payment_verification/PaymentVerificationJSONView flow - if you need to
react to both, keep your own logic in whatever view calls
django_pg.payment.verify_payment in addition to this receiver.
🧠 Gateway Dispatcher (Behind the scenes)
The following function routes the verification based on the selected payment method:
# gateways/payment.py
def verify_payment(order_id, reference, user, payment_method):
if payment_method == 'paystack':
return verify_paystack_payment(order_id, reference, user)
# elif payment_method == 'flutterwave': ...
You don't need to modify this — it's extendable internally.
🛡 License
This project is licensed under the MIT License – see the LICENSE file for details.
🤝 Contributing
Pull requests are welcome! If you find a bug or have a feature request, feel free to open an issue.
See full Changelog.
Metadata
Release files for django-pg 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_pg-0.6.0.tar.gz | 20.1 kB | Without provenance | Details for django_pg-0.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_pg-0.6.0-py3-none-any.whl | Python 3 | none | any | Details for django_pg-0.6.0-py3-none-any.whl |
Total release size: 48.4 kB
Release files / django_pg-0.6.0.tar.gz
| Download URL | django_pg-0.6.0.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e6fdfb4fb3596d889e670f461e64005fa70f3328425223b62d5ed6e1f537131e
|
|
BLAKE2b-256 checksum How to use checksums |
52b0c476165893f53a74993fd0a632029db7daab4be2f6cd8281b4fb97c29fee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.0
|
Release files / django_pg-0.6.0-py3-none-any.whl
| Download URL | django_pg-0.6.0-py3-none-any.whl |
|---|---|
| Size | 28.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13a0abf8ff901ff727f9113654046c8d173b31bf1f02c83a4152f9e026a88b93
|
|
BLAKE2b-256 checksum How to use checksums |
a6a7fcb9a9465cf1de0369ee7dbfe2885848246ef3ad8197728ac17ead0da7e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.7.0
|
Security for django-pg 0.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.