PayFast Models for Django

Complete PayFast payment gateway integration for Django. Set up your webhook endpoint and start receiving model updates instantly. A copy of all PayFast models available in Django, as soon as they are updated!

Python ≥3.8 Django ≥3.2 PostgreSQL Ready Production Tested Secure

Why dj-payfast?

Everything you need for PayFast integration in Django

Complete Integration

Full implementation of PayFast models for Django with webhook support and instant model updates.

PayFast Core & Billing

Support for PayFast Core, Billing, Cards (JS v2), Sources (JS v3), and Payment Methods with SCA support.

Built-in Security

Automatic signature verification, IP validation, and server-side validation with PayFast.

Multiple Accounts

Support for multiple PayFast accounts and API keys in a single Django project.

Webhook Handling

Automatic ITN (Instant Transaction Notification) processing with complete audit trail.

Admin Integration

Full Django admin integration for managing payments and viewing transaction history.

Requirements

Tested with PayFast API 2020-08-27

Python

Version 3.8 or higher

Django

Version 3.2 - 5.0

PostgreSQL

Version 12+ (Recommended)

MySQL/MariaDB

MariaDB ≥10.5 or MySQL ≥8.0

Additional

Nginx, Gunicorn, Docker, Celery

Email

Email setup configured

Note: SQLite is not recommended for production use. Minimum version 3.26 required if used.

Installation

Get started in minutes

1

Install via pip

Install the latest version from PyPI

pip install dj-payfast
2

Add to INSTALLED_APPS

Update your Django settings.py

INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', # ... other apps 'payfast', # Add this ]
3

Configure Settings

Add your PayFast credentials

# PayFast Configuration PAYFAST_MERCHANT_ID = 'your_merchant_id' PAYFAST_MERCHANT_KEY = 'your_merchant_key' PAYFAST_PASSPHRASE = 'your_passphrase' PAYFAST_TEST_MODE = True # False for production
4

Add URLs

Include PayFast URLs in your project

urlpatterns = [ path('admin/', admin.site.urls), path('payfast/', include('payfast.urls')), ]
5

Run Migrations

Create the necessary database tables

python manage.py migrate
6

Start Accepting Payments!

You're all set to integrate PayFast payments

# Create a payment payment = PayFastPayment.objects.create( user=request.user, m_payment_id=str(uuid.uuid4()), amount=199.99, item_name='Premium Subscription', email_address=request.user.email, )

Quick Start Example

Create your first payment in minutes

# views.py from django.shortcuts import render from payfast.models import PayFastPayment from payfast.forms import PayFastPaymentForm import uuid def checkout_view(request): # Create a payment payment = PayFastPayment.objects.create( user=request.user, m_payment_id=str(uuid.uuid4()), amount=299.99, item_name='Premium Subscription', email_address=request.user.email, ) # Generate payment form form = PayFastPaymentForm(initial={ 'amount': payment.amount, 'item_name': payment.item_name, 'm_payment_id': payment.m_payment_id, 'email_address': payment.email_address, 'notify_url': request.build_absolute_uri('/payfast/notify/'), }) return render(request, 'checkout.html', {'form': form})

Documentation

Comprehensive guides and API reference

Similar Libraries

Other Django payment integrations