Payment Gateway and Background Processing for Photo & Portrait Orders using Stripe, Celery, Redis, and FastAPI
This project handles a payment gateway and the processing of online portrait photos.
It receives customers' photos and caches them in Redis until payment is confirmed, at which point it processes the storage and owner notification in the background using Celery.
The idea behind this approach is to ensure that the photos are only stored after payment is confirmed and to process them in the background to avoid performance issues.
Below is a quick demonstration of how it works.

The project uses:
- Jinja templates for frontend and email templates
- FastAPI for the backend and template rendering endpoints
- Stripe to process the payment gateway
- Celery to process tasks in the background
- Redis to cache values and also serve as the Celery broker and backend
- PostgreSQL to store all the order information
- Google API to perform address validation
- Fastapi-mail to send emails
- boto3 to store photos in AWS S3
- pytest, pytest-cov, testscontainers-python, and pytest-mock to perform tests
- Docker to orchestrate all the services together
The project was designed to avoid storing client data in the database before the payment is confirmed. This way, on the first page, when the user submits the uploaded photos and their respective quantities, the app stores the photos as Base64-encoded data in Redis. It then sends a session identifier as a cookie in the response, which will be used as the Redis key.
On the second page, the address is validated to ensure it corresponds to a single location and is exclusively in Portugal. Since the address is validated using the Google API, each search query sent for validation is cached to prevent multiple requests to the paid API with the same query.
Once the address is validated, the order details are stored in the database, and a Stripe Checkout session is generated. If the payment is confirmed, two background tasks are triggered using Celery: storage of the images in AWS S3 and sending an email to the host (business owner) with the order details.
All the values stored in Redis are set to expire after 1 day.
This section explains how to run this project using Docker, which will build both the PostgreSQL and Redis databases along with the app.
All the necessary environment variables are listed in the .env-example file. You need to set the following:
- The Stripe API key and the price ID to be displayed
- AWS credentials for writing to S3
- The Google API key
- The email app password along with its configuration
- Clone the project:
git clone https://github.com/lealre/stripe-photo-gateway.git- Navigate to the project directory:
cd stripe-photo-gateway- Create the
.envfile and pass your personal settings:
cp .env-example .env- Build and run the Docker containers:
docker compose up