The SMILE SALES Order Microservice is a critical component of the SMILE SALES e-commerce, which is dedicated to handling order and payment processes. It provides robust functionalities for managing orders from creation to completion, including payment processing, order tracking, and returns.
- Checkout: Facilitates the creation of new orders.
- Cancellation: Allows users to cancel orders before shipment.
- Returns: Enables customers to initiate returns for purchased items.
- Tracking: Provides real-time order tracking information.
- Archiving/Unarchiving: Enables the management of order history.
- Filtering: Offers advanced filtering options based on dates and order status.
- PayPal Integration: Supports secure payments via PayPal.
- Refund Management: Handles and processes refund requests according to approval status.
git clone https://github.com/GhostMEn20034/SMILE_SALES_ORDER_MICROSERVICE.git
on Windows (PowerShell), run:
New-Item -Path ".env" -ItemType "File"
on Unix or MacOS, run:
touch .env
SUPER_USER_PWD=some_pwd # Password of the Postgres user
SECRET_KEY=124555asdadas # Django's secret key
JWT_SIGNING_KEY=some_key # Signing key for JWT Tokens (Use the same value as in User microservice)
DEBUG=0_or_1 # Determines whether the debug mode turned on (1 - on, 0 - off)
ALLOWED_HOSTS=localhost,127.0.0.1,[::1] # Your allowed hosts
FRONTEND_BASE_URL=http://localhost:3000 # Base URL of the main frontend webserver
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001 # CORS allowed origins (Main frontend's host must be included)
SQL_ENGINE=django.db.backends.postgresql # DB Engine
SQL_DATABASE=smile_sales_orders # Database Name
SQL_USER=smile_sales_orders_usr # Database Owner
SQL_PASSWORD=xxxx4444 # DB user's password
SQL_HOST=db # Database host
SQL_PORT=5432 # Database Port
SQL_CONN_MAX_AGE=60 # Maximum Connection's age
AMPQ_CONNECTION_URL=url_rabbit_mq # Message broker URL
PRODUCT_CRUD_EXCHANGE_TOPIC_NAME=product_replication # Just copy that
USERS_DATA_CRUD_EXCHANGE_TOPIC_NAME=users_data_replication # Just copy that
ORDER_PROCESSING_EXCHANGE_TOPIC_NAME=order_processing_replication # Just copy that
PAYPAL_API_BASE_URL=https://api-m.sandbox.paypal.com # BASE URL of the PayPal API
PAYPAL_CLIENT_ID=afdfd2324323 # Client ID of PayPal account
PAYPAL_SECRET=aasfdsf53123123121 # Secret key for PayPal API
DRAMATIQ_BROKER_URL=# Redis url for dramatiq broker
CHECK_ABANDONED_ORDERS_EVERY_MINUTES=5 # How often to check for abandoned orders and delete them (In minutes)
EMAIL_HOST=some.smtp.com # SMTP Host for sending email
EMAIL_PORT=your_port
[email protected] # the email from which you want to send emails
EMAIL_HOST_PASSWORD=some_pwd # The password of the Gmail (Or other provider) app
If you want to run this app you have two options:
- Run it using
docker-compose
- Run it using
k8s
1.1 Add permission to execute the init-database.sh
file inside the docker-compose's Postgres service:
chmod +x init-database.sh
docker compose up -d --build
If you want to do that, you need to use the file docker-compose-prod.yml
and the file name with env variables should be .env.prod
.
This option assumes that you have already run db in AWS or any other providers.
Also you need to use different command to run the app:
docker compose -f docker-compose-prod.yml --env-file=.env.prod up -d
Now, you can go to localhost or 127.0.0.1 and use the API.
Note: If you want to run this API using Kubernetes, you need to start and expose Postgres and Redis servers manually
kubectl create namespace smile-sales-users
kubectl create secret generic web-secrets --from-env-file=.env
cd k8s
kubectl apply -f config-maps/
kubectl apply -f persistent-volumes/
kubectl apply -f persistent-volume-claims/
kubectl apply -f jobs/
kubectl get jobs
kubectl apply -f services/
kubectl apply -f deployments/
Caution: make sure you're in the default directory
To run tests you need to complete 3 steps:
- Run the test app with another
docker-compose
file:
docker compose -f docker-compose-test-env.yaml up -d
- Run the command below:
docker compose exec web python manage.py test -v 2
- Shutdown
docker-compose
services:
docker compose -f docker-compose-test-env.yaml down