Skip to main content

Pluggable Django package for integrating multiple payment gateways like Paystack, Flutterwave, Interswitch, Stripe, etc.

Project description

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 BaseOrder model for customization
  • ✅ Built-in Payment Verification View (redirect-based gateways)
  • 🟦 Webhook-based verification for Stripe
  • 🧠 Smart unique order reference generation
  • 🧪 Built-in signal handling for order reference
  • 💡 Fully customizable frontend and views

Example Project

A sample Django project demonstrating how to use this package is available here:

👉 django_pg_test_project


📦 Installation

pip install django-pg

⚙️ Project Setup

  1. Add the app to INSTALLED_APPS
# settings.py
INSTALLED_APPS = [
    ...
    'django_pg',  # Your payment package
]
  1. 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
  1. 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 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
  1. 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()

🧠 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.

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_pg-0.5.2.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

django_pg-0.5.2-py3-none-any.whl (22.5 kB view details)

Uploaded Python 3

File details

Details for the file django_pg-0.5.2.tar.gz.

File metadata

  • Download URL: django_pg-0.5.2.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.0

File hashes

Hashes for django_pg-0.5.2.tar.gz
Algorithm Hash digest
SHA256 6ffb2992b93d773903984e131e3d2655f1dcbb5612469bac7ac3c85516a79630
MD5 266c49617d94cd448627df725a8e07e8
BLAKE2b-256 c5a13f19a3414b500c2bac6098a826fbd92cdceebfb23e80daf68bb137584dfe

See more details on using hashes here.

File details

Details for the file django_pg-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: django_pg-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 22.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.0

File hashes

Hashes for django_pg-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c9891d0d390055d083dc3d38ff650d76318cbbc2c81af6036b3ec4ac410ec7bf
MD5 9f79f69a0c917fb5a1e2443310ec69df
BLAKE2b-256 6893723629939a04c9b009a3efe099a4f6f320875fa8978214c4c06719e34c52

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