Shipr is a personal project aimed at helping folks understand distributed microservice architecture. It’s a simple, lightweight system designed to manage products, process orders, and handle payments.
The Payment Service handles the financial transactions that power Shipr.
-
Main Application (
main.py
): This service manages the core payment logic, including order creation, fee calculations, and total price determination. -
Consumer (
consumer.py
): The payment service's consumer is dedicated to handling exceptions in the payment process, such as refund scenarios. It listens to a Redis stream and ensures that any issues with orders are addressed immediately, updating the status and refunding the payment as needed. This consumer helps maintain the consistency and reliability of the payment workflow.
- Python 3.x
- Redis
As a best practice, it is advised to create a virtual environment to store this project's dependencies separately. You can install virtualenv with
-
Install virtualenv (optional)
pip install virtualenv
-
Create env (optional)
python -m venv .venv
-
Activate virtualenv (optional)
source env/bin/activate
-
Install depndencies
pip install -r requirements.txt
-
Make sure you have a
.env
file with following variables.# Redis configuration REDIS_HOST=xxx REDIS_PORT=xxx REDIS_DB=xxx # CORS configuration ALLOW_ORIGINS=xxx ALLOW_METHODS=xxx ALLOW_HEADERS=xxx # Product service URL PRODUCT_SERVICE_URL=xxx # Fee percentage for orders FEE_PERCENTAGE=xxx
-
Run server
uvicorn main:app
-
Run message consumer
python consumer.py