Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RESTful Payment Gateway API for SME

Project Overview and Philosophy

This project aims to provide small and medium enterprises (SMEs) with a simple, secure, and scalable backend API to accept payments from customers. The philosophy centers on delivering a minimal yet robust payment processing system that minimizes friction for SMEs to integrate digital payment acceptance without requiring complex user authentication or frontend dependencies.

Payments are essential for modern commerce, yet many SMEs struggle with integrating payment gateways securely and efficiently. This project responds to that challenge by offering a RESTful API focusing on:

Minimal required customer information (name, email, phone, amount, location).

Clear versioning of API endpoints to future-proof integration and allow smooth evolution.

No user authentication, simplifying access while emphasizing idempotent, secure payment flow where appropriate.

Automated testing and deployment pipelines to ensure reliability and rapid iteration.

Problem Addressed

  • SMEs increasingly need to accept online payments but face challenges including:

  • Complexity of payment gateway integrations with diverse APIs.

  • Managing sensitive customer financial data requires compliance and security.

  • Providing clear, real-time feedback about payment status.

  • Keeping the backend maintainable and extensible over time.

  • Ensuring that changes to API endpoints do not disrupt existing clients (hence versioning).

  • Automating tests and deployment to maintain quality and reduce manual overhead.

This API seeks to solve these through a targeted design anchored on Django and third-party payment integration with Paystack, backed by PostgreSQL database management and solid CI/CD practices.

Technologies and Tools

  • Django & Django REST Framework: Web framework and REST API toolkit powering secure, maintainable backend logic.

  • Paystack Payment Gateway: Robust, trusted payment provider offering APIs for seamless transaction processing.

  • PostgreSQL: Reliable, scalable relational database for persisting payment data and transaction records.

  • Unit Testing: Using Django's testing framework to verify core features like payment initiation, status retrieval, and edge cases.

  • GitHub Actions: Automates testing and deployment workflows, ensuring code quality and enabling continuous delivery.

  • API Versioning: Implemented with URL path versioning (/api/v1/) to allow backward-compatible API evolution.

API Endpoints

POST /api/v1/payments/ Initiates a payment with customer details and amount. Returns payment reference and status.

GET /api/v1/payments/{id}/ Retrieves status and details of a specific payment transaction by its ID.

Example response for GET payment status: { "payment": { "id": "PAY-123", "customer_name": "John Doe", "customer_email": "john@example.com", "amount": 50.00, "status": "completed" }, "status": "success", "message": "Payment details retrieved successfully." }

Installation and Running Locally

Clone the repository:

bash
git clone https://github.com/yourusername/payment-gateway-api.git
cd payment-gateway-api
Create and activate a Python virtual environment:

bash
python3 -m venv venv
source venv/bin/activate
Install dependencies:

bash
pip install -r requirements.txt
Configure environment variables (e.g., Paystack API key, database credentials) in .env.

Run migrations to set up the PostgreSQL database:

bash
python manage.py migrate
Start the development server:

bash
python manage.py runserver
Testing
Run unit tests to ensure API correctness and integration with the payment gateway:

bash
python manage.py test
Tests cover payment initiation, success and failure scenarios, and status retrieval.

CI/CD Pipeline with GitHub Actions
Automated tests run on every push and pull request to the main branch.

Ensures that code changes do not break existing functionality before merging.

Deployment steps can be customized to deploy to platforms like Render, Vercel, or Heroku.

Sample workflow is configured in .github/workflows/django.yml:

text
name: Django CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.8]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Run Tests
      run: python manage.py test

Learning Outcomes Mastering integration of payment gateways like Paystack within Django backend apps.

Understanding RESTful API design with versioning for financial transactions.

Emphasizing automated testing for sensitive operations like payments.

Implementing CI/CD workflows for reliable backend delivery.

Grasping security and compliance considerations when handling financial data even without user authentication.

Designing scalable payment systems ready for retry and idempotency considerations.

This project exemplifies modern backend development for commerce systems, blending reliability, security, and developer ergonomics for SMEs to confidently accept payments online.

If you need sample code snippets or further details on any sections, feel free to ask.

Related How do I structure Django models for the payment and customer fields Which Paystack endpoints should I call to initialize and verify payments How should I design API responses to comply with the example JSON format What Django REST Framework versioning approach fits this task best How can I write unit tests to mock Paystack and test status retrieval

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages