How rsusik/stripe-fastapi-demo works
Project type and purpose
• This is a lightweight full-stack sample application demonstrating how to integrate Stripe’s prebuilt checkout page using FastAPI on the backend and static HTML/JavaScript on the frontend.
• The goal is to accept payments via Stripe Checkout with minimal custom code.
File structure
Top-level files and folders:
• .env.example, .gitignore, README.md, etc. – project-wide configuration and metadata
• client/ – static frontend assets (HTML, CSS, JS) for user interaction
• server/ – backend API powered by FastAPI, responsible for creating Stripe Checkout sessions
Key observations:
• The server directory contains server.py and requirements.txt, indicating a single service.
• No database folder—persistent state is managed by Stripe.
• Environment files (.env.example) on both root and server levels for API keys and configuration.
README for additional insights
• Confirms the use of FastAPI and Stripe’s Python SDK.
• Emphasizes this is the “prebuilt checkout page” flow: redirect user to Stripe’s hosted checkout.
• No custom payment logic beyond session creation—no multiple microservices or complex orchestration.
Components
a. Main components
• Client UI (Static website)
– index.html, success.html, canceled.html
– CSS modules (global.css, normalize.css)
– success.js for post-checkout logic
• Backend API (FastAPI service)
– server.py – exposes endpoints to create a Stripe Checkout session
– requirements.txt – dependencies including fastapi, stripe
• Stripe External Service
– Stripe Checkout hosted page
– Webhook callbacks (if implemented or future extension)
• Configuration
– Environment variables (.env) for Stripe secret key, webhook signing secret
b. Relationships and data flow
1. User visits client/index.html (served by static host or directly opened).
2. Frontend JavaScript calls backend (e.g., POST /create-checkout-session) with purchase details.
3. FastAPI endpoint uses Stripe SDK to create a Checkout Session and returns session ID.
4. Frontend redirects the browser to Stripe’s hosted URL.
5. User completes payment on Stripe.
6. Stripe redirects user back to success.html or canceled.html.
c. Architectural patterns and design principles
• Separation of concerns: static assets (client) vs. business logic (server)
• Minimal backend: no local database, delegating state to Stripe
• Environment-driven configuration for keys and secrets
d. Key technologies and frameworks
• FastAPI for backend routing and JSON responses
• Stripe Python SDK for session creation
• Plain HTML/CSS/JavaScript for frontend
• Environment variables for secret management
Additional details
• Notes on where to place .env files and how secrets flow into the backend.