Skip to content

lealre/stripe-photo-gateway

Repository files navigation

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:

How it works

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.

Running the Project with Docker

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

How to install docker

  1. Clone the project:
git clone https://github.com/lealre/stripe-photo-gateway.git
  1. Navigate to the project directory:
cd stripe-photo-gateway
  1. Create the .env file and pass your personal settings:
cp .env-example .env
  1. Build and run the Docker containers:
docker compose up

About

Payment Gateway and Background Processing for Photo & Portrait Orders using Stripe, Celery, Redis, and FastAPI

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors