This project demonstrates a secure and efficient approach to implementing payment functionality using the SeerBit Standard Checkout API. Built with FastAPI and MongoDB, this application is designed to simplify the process of creating and managing online payments, making it ideal for developers working on financial integrations.
- Payment Initialization: Create and initialize payments securely using SeerBit's Standard Checkout API.
- MongoDB Integration: Store and manage payment records in a robust database for easy retrieval and tracking.
- RESTful API: A FastAPI-powered API to handle payment requests with structured validation using Pydantic.
- FastAPI: A modern, high-performance web framework for building APIs.
- SeerBit Standard Checkout API: A reliable payment API for initiating and managing transactions.
- MongoDB: A NoSQL database for efficient data storage and management.
- Pydantic: Used for data validation and serialization.
- Requests: Handles HTTP communication with external APIs.
- Python Dotenv: Manages environment variables for secure configuration.
- Python 3.8 or higher
- A running MongoDB instance (local or cloud-based)
- SeerBit API credentials (Public Key, Encrypted Key, and API URL)
.env
file containing the following environment variables:DATABASE_URL="your_mongodb_connection_string" SEERBIT_PAYMENT_API="seerbit_standard_checkout_url" ENCRYPTED_KEY="your_seerbit_encrypted_key" PUBLIC_KEY="your_public_key"
-
Clone the Repository
git clone https://github.com/your-repo/seerbit-fastapi-checkout.git cd seerbit-fastapi-checkout
-
Install Dependencies
pip install -r requirements.txt
-
Set Environment Variables
Create a.env
file in the project root and add the required keys as shown in the prerequisites. -
Start the Application
fastapi dev app.py
-
Access the API Documentation
Navigate to http://127.0.0.1:8000/docs to explore and test the endpoints using FastAPI's Swagger UI.
- Endpoint:
/checkout/create
- Method: POST
- Request Body:
{ "amount": 1000, "currency": "NGN", "country": "NG", "paymentReference": "unique_reference", "email": "[email protected]", "fullName": "User Name", "tokenize": false, "callbackUrl": "https://your-callback-url.com" }
- Response:
- Success:
{ "Message": "Payment is successful!" }
- Failure: Returns an HTTP error with the status code and error details.
- Success:
-
Payment Initialization:
- The client sends payment details to the
/checkout/create
endpoint. - The app validates the data and sends it to the SeerBit API with the necessary headers.
- On successful response from SeerBit, the payment data is stored in MongoDB.
- The client sends payment details to the
-
Error Handling:
- API failures are captured, and meaningful error messages are returned to the client.
- Database insertion errors are also handled gracefully.
-
Data Security:
- Sensitive keys are stored securely in environment variables.
- The app uses HTTPS for secure API communication.
- Ensure your MongoDB instance is accessible and properly configured.
- Use a valid
paymentReference
for unique transaction identification. - Configure your SeerBit callback URL to handle post-payment actions effectively.
We welcome contributions! Feel free to fork the repository, raise issues, or submit pull requests to improve this project.
This project is open-source and available under the MIT License.