A Django REST Framework API for initializing, verifying, and handling Paystack payment transactions.
https://mastercraft-stage2.onrender.com/api/v1/payments/str:param
https://mastercraft-stage2.onrender.com/admin
- User: admin, Password: 1234
- Initialize Paystack payment transactions
- Verify transaction status by reference
- Handle Paystack webhook events
- Auto-generated API documentation with Swagger and ReDoc
- Python 3.10+
- pip
- virtualenv (optional but recommended)
- PostgreSQL or your preferred DB (adjust settings accordingly)
1. Clone the repo
git clone https://github.com/PaulImison/MasterCraft-Stage2.git
cd paystack-payments-api2. Create & activate virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows use `.venv\Scripts\activate`3. Install dependencies
pip install -r requirements.txt4. Configure environment variables
Copy .env.example to .env and edit with your secrets.
cp .env.example .env
# Edit .env to add your DB credentials, PAYSTACK_SECRET_KEY, etc.5. Apply migrations
python manage.py migrate6. Run development server
python manage.py runserver7. Access API docs
- Swagger UI: http://localhost:8000/swagger/
- ReDoc: http://localhost:8000/redoc/
Run the full test suite with:
python manage.py test-
Automated pipeline runs tests and deploys on push to
main. -
Deployment environment variables:
DJANGO_SECRET_KEYDATABASE_URLPAYSTACK_SECRET_KEYALLOWED_HOSTS
-
Ensure webhook endpoint security in production.
- DJANGO_SECRET_KEY=your-secret-key
- DATABASE_URL=postgres://user:password@localhost:5432/payments_db
- PAYSTACK_SECRET_KEY=sk_test_xxxxxxxxxxxxxxxxxxxxx
- ALLOWED_HOSTS=localhost,127.0.0.1
cp .env.example .env-
✅ Then edit .env with your real secrets:
-
Use Django Secret Key Generator or similar to generate a secure DJANGO_SECRET_KEY.
-
Add your real PAYSTACK_SECRET_KEY from Paystack dashboard.
-
If using Docker or cloud deploy, update DATABASE_URL accordingly.
Access the live API here:
| Endpoint | Method | Description |
|---|---|---|
/api/v1/payments/ |
POST | Initialize a payment |
/api/v1/payments/<ref>/ |
GET | Verify payment by reference |
/api/v1/payments/webhook/ |
POST | Paystack webhook callback |
Feel free to fork and create PRs. Follow the code style and add tests for new features.
For questions or issues, email paulmison@gmail.com
Happy coding! 🚀