Flask Stripe Sample - Open-Source Code

Hello! This article presents an open-source codebase that provides simple eCommerce features powered by Flask and Stripe. The products are loaded from JSON files (no database) and all related pages and cards are generated during the runtime. This codebase can be used to bootstrap fast a minimal eCommerce project or simply for eLearning activities that involve Flask and Stripe. For newcomers, Flask is a popular web framework and Stripe is a leading payment gateway widely used in eCommerce projects. Thanks for reading!


✨ How it works

Once the Flask source code is downloaded and compiled we need to set up the environment to bind correctly the app with the Stripe platform.

The .env.sample should be renamed to .env and edited to provide valid Stripe Credentials:

  • Edit STRIPE_SECRET_KEY - provided by Stripe Platform
  • Edit STRIPE_PUBLISHABLE_KEY - provided by Stripe Platform

The app comes with product samples defined in the templates directory. During the runtime, Flask scans the directory, generates the pages, and publishes all discovered products. Let's take a look at a real sample: Air Zoom Pegasus

JSON File - saved in the templates directory
{
    "name": "Air ZOOM Pegasus",
    "price": 499,
    "currency": "usd",
    "info": "Men's Road Running Shoes",
    "short_description": "A workhorse built to help power you through every mile of the race.",
    "full_description": "A workhorse built to help power you through every mile of the race, the Nike Air Zoom Pegasus 38 Ekiden continues to put a spring in your step, using the same responsive foam as its predecessor. Mesh in the upper combines the comfort and durability you want with a fit that nods back to the classic Peg."
}
Flask Stripe App - Product JSON 
Media Files: Product card and Cover Image:

The app detects all this information and builds the pages as shown in this GIF animated presentation:

Flask Stripe App - Product Sale. 

To complete the payment, make sure your Stripe account runs in the TEST mode. For a successful payment a test CC provided by Stripe can be used:

  • CC Number: 4242 4242 4242 4242
  • Any data for the rest of the fields
Flask Stripe App - Payment Page 
Stripe and Flask - Payment Confirmation page
Flask Stripe App - Confirmation Page 

Thanks for reading! For more resources & support please access: