This Stripe sample shows how to accept payments using
Elements with Checkout Sessions
(ui_mode: 'elements'). A Checkout Session is created on the server,
its client_secret is passed to the front end, and Stripe Elements renders
the payment form.
.
├── client
│ ├── html # Vanilla HTML/JS client
│ │ ├── index.html
│ │ ├── index.css
│ │ ├── index.js
│ │ ├── complete.html
│ │ ├── complete.css
│ │ └── complete.js
│ └── react-cra # React client (Vite dev server)
│ └── ...
├── server
│ ├── node
│ ├── python
│ ├── ruby
│ ├── php
│ ├── java
│ ├── go
│ └── dotnet
├── testing
│ └── manual-test.sh # Run all 14 server×client combinations
├── .mise.toml # Tool versions (mise install)
└── .env.example # Root env template
- A Stripe account
- One of the following runtimes:
- Node >= 18
- Python >= 3.12
- Ruby >= 3.3
- PHP >= 8.2 with Composer
- Java >= 17 with Maven
- Go >= 1.22
- .NET >= 9.0
- Or install all runtimes automatically with mise:
mise install
| Variable | Description | Default |
|---|---|---|
STRIPE_SECRET_KEY |
Your Stripe secret key (sk_test_...) |
required |
STRIPE_PUBLISHABLE_KEY |
Your Stripe publishable key (pk_test_...) |
required |
STRIPE_WEBHOOK_SECRET |
Your Stripe webhook secret (whsec_...) |
optional |
STATIC_DIR |
Path to the static files directory | ../../client/html |
DOMAIN |
Base URL for return URLs | http://localhost:${PORT} |
PORT |
Port the server listens on | 4242 |
Copy the .env.example file into the server directory you plan to use and
fill in your Stripe API keys:
cp .env.example server/node/.env
# Edit server/node/.env and add your keyscd server/node
cp ../../.env.example .env # add your keys
npm install
npm startcd server/python
cp ../../.env.example .env # add your keys
pip install -r requirements.txt
python server.pycd server/ruby
cp ../../.env.example .env # add your keys
bundle install
ruby server.rbcd server/php
cp ../../.env.example .env # add your keys
composer install
php -S localhost:4242 router.phpcd server/java
cp ../../.env.example .env # add your keys
mvn compile exec:javacd server/go
cp ../../.env.example .env # add your keys
go run server.gocd server/dotnet
cp ../../.env.example .env # add your keys
dotnet runVisit http://localhost:4242 to see the payment form.
The HTML client lives in client/html/. Every server is configured
to serve this directory as static files by default (via the STATIC_DIR
environment variable). No separate build step is needed.
The React client uses Vite and proxies API requests to the backend:
cd client/react-cra
npm install
npm startThe dev server starts on port 3000 and proxies /api requests to
http://127.0.0.1:4242. Navigate to
http://localhost:3000 to see the payment form.
Make sure a backend server is running on port 4242 first.
Important: Set DOMAIN to your Vite dev server URL so Stripe
redirects back to the React app after payment:
# In your server's .env
DOMAIN=http://localhost:3000