This article provides a step-by-step guide on building a Payment Gateway API using Django and PayPal, enabling secure online transactions.
The project uses minimal data, skips authentication for simplicity, and includes automated tests for efficient development.
Requirements include Python 3.12, Django 5.0.6, Django REST Framework 3.15.1, a PayPal Developer Account, PostgreSQL 16+, and Git.
Obtain PayPal credentials (Client ID and Secret) by creating an app in the PayPal Developer Portal and storing them securely in a .env file.
The project setup involves creating a Django project, configuring settings, setting up PostgreSQL, and defining the data model for payment transactions.
Endpoints are built to initiate, execute, cancel, and check payments, supported by serializers, views, and URLs.
Testing the API is crucial and can be done using test cases covering various scenarios such as payment creation, execution, cancellation, and handling errors.
The deployment process involves setting up CI/CD with GitHub Actions and deploying the project to Render, ensuring environment variables match the .env file.
Common pitfalls like PayPal errors and test failures are addressed, along with suggestions to prevent database issues by using PostgreSQL consistently.
Readers are encouraged to test the live Payment Gateway API functionality with sample data provided and explore further enhancements like frontend integration or refund features.