INSTALLATION.RST
Installation
This guide will help you install and set up dj-payfast in your Django project.
Requirements
Before installing dj-payfast, ensure you have:
Python 3.8 or higher
Django 3.2 or higher
A PayFast merchant account
pip package manager
Installing dj-payfast
Using pip (Recommended)
Install the latest stable version from PyPI:
pip install dj-payfast
Installing from GitHub
To install the latest development version:
pip install git+https://github.com/carrington-dev/dj-payfast.git
Or clone and install locally:
git clone https://github.com/carrington-dev/dj-payfast.git
cd dj-payfast
pip install -e .
Installing for Development
If you want to contribute or modify the library:
git clone https://github.com/carrington-dev/dj-payfast.git
cd dj-payfast
pip install -e ".[dev]"
This installs additional development dependencies like pytest, black, and flake8.
Verifying Installation
Verify the installation by importing the package:
import payfast
print(payfast.__version__)
Django Configuration
1. Add to INSTALLED_APPS
Add 'payfast' to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# Your apps
'myapp',
# Third-party apps
'payfast', # Add this
]
2. Configure PayFast Settings
Add your PayFast credentials to settings.py:
# PayFast Configuration
PAYFAST_MERCHANT_ID = '10000100' # Your merchant ID
PAYFAST_MERCHANT_KEY = '46f0cd694581a' # Your merchant key
PAYFAST_PASSPHRASE = 'your_secure_passphrase' # Optional but recommended
PAYFAST_TEST_MODE = True # False for production
Warning
Never commit your production credentials to version control! Use environment variables or a secrets management system.
Using Environment Variables (Recommended):
import os
PAYFAST_MERCHANT_ID = os.environ.get('PAYFAST_MERCHANT_ID')
PAYFAST_MERCHANT_KEY = os.environ.get('PAYFAST_MERCHANT_KEY')
PAYFAST_PASSPHRASE = os.environ.get('PAYFAST_PASSPHRASE')
PAYFAST_TEST_MODE = os.environ.get('PAYFAST_TEST_MODE', 'True') == 'True'
3. Include URLs
Add PayFast URLs to your main urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('payfast/', include('payfast.urls')),
# Your other URLs
]
4. Run Migrations
Create the necessary database tables:
python manage.py migrate
You should see output like:
Running migrations:
Applying payfast.0001_initial... OK
Getting PayFast Credentials
Sandbox (Testing)
Sign up for a sandbox account at https://sandbox.payfast.co.za
Log in to your sandbox dashboard
Navigate to Settings → Integration
Copy your Merchant ID and Merchant Key
Generate a passphrase (recommended)
Production
Sign up at https://www.payfast.co.za
Complete the merchant verification process
Log in to your PayFast dashboard
Navigate to Settings → Integration
Copy your Merchant ID and Merchant Key
Generate a secure passphrase
Next Steps
Now that you have dj-payfast installed, proceed to:
Quick Start Guide - Create your first payment
CONFIGURATION.RST - Advanced configuration options
Usage Guide - Detailed usage examples