A Python Flask backend and vanilla JS frontend implementing Stripe Checkout for single subscriptions, configured for EC2 deployment.
https://github.com/davidbmar/stripe-single-subscription-ec2 · public · shipped
This project is a reference implementation of a subscription payment flow using Stripe Checkout. It consists of a lightweight Flask server that manages API keys and retrieves checkout session details, paired with a static client-side interface that dynamically loads price IDs and handles post-payment success display. It includes build scripts to validate environment configuration before deployment.
python3 -m venv myenv source myenv/bin/activate cp env.example .env # Edit .env to set STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY, BASIC_PRICE_ID, PRO_PRICE_ID python3 server/build.py pip install flask stripe python-dotenv python3 server/server.py
flowchart TD
Client[Browser Client] -->|GET /| Server[Flask Server]
Client -->|GET /config| Server
Client -->|GET /checkout-session| Server
Server -->|Retrieve Session| StripeAPI[Stripe API]
Server -->|Read Env| DotEnv[(.env File)]
BuildScript[build.py] -->|Validate| DotEnv
The backend is built with Python 3.8+ using Flask for HTTP routing and the `stripe` Python library for API interactions. Environment variables are managed via `python-dotenv`. The frontend uses vanilla JavaScript (ES6+) with `fetch` API calls to communicate with the backend. Configuration validation is handled by a custom Python script (`build.py`).
sequenceDiagram
participant Browser
participant FlaskServer
participant StripeAPI
Browser->>FlaskServer: GET /
FlaskServer->>Browser: Render index.html
Browser->>FlaskServer: GET /config
FlaskServer->>Browser: Return {publishableKey, basicPrice, proPrice}
Note over Browser: User initiates checkout (client-side Stripe.js)
Browser->>StripeAPI: Create Checkout Session
StripeAPI->>Browser: Return Session ID & Redirect URL
Browser->>Browser: Redirect to Success Page
Browser->>FlaskServer: GET /checkout-session?sessionId=...
FlaskServer->>StripeAPI: Retrieve Session Details
StripeAPI->>FlaskServer: Return Session Object
FlaskServer->>Browser: Return Session JSON
Use this as a starting point for integrating Stripe Subscriptions into a Python web application. It demonstrates how to securely expose publishable keys and price IDs to the client while keeping secret keys on the server. It is specifically structured for deployment on AWS EC2, including instructions for installing the Stripe CLI on Linux (ARM/x86).