Stripe CLI — Command-Line Tools for Development and Testing
In this tutorial, you will learn about Stripe CLI. We cover key concepts, practical examples, and best practices to help you master this topic.
The Stripe CLI is a command-line tool for interacting with Stripe, enabling Webhook listening, event triggering, resource management, and local development without a dashboard.
What You'll Learn
By the end of this lesson you will understand how to install and configure the Stripe CLI, listen for Webhooks locally, trigger test events, manage Stripe resources, and automate testing.
Why It Matters
The Stripe CLI eliminates the need to deploy code to test webhooks or manually create resources in the dashboard. It accelerates development by bringing Stripe operations to your terminal.
Real-World Use
DodaTech's developers use the Stripe CLI daily: stripe listen forwards webhooks to local servers, stripe trigger generates test events, and stripe fixtures loads test data.
flowchart LR
C[Developer] -->|stripe listen| S[Stripe]
S -->|Forward events| L[localhost:3000]
C -->|stripe trigger| S
C -->|stripe logs| S
C -->|stripe fixtures| S
style S fill:#6772e5,color:#fff
Installation and Login
Install the Stripe CLI and authenticate with your account.
# Install on macOS
brew install stripe/stripe-cli/stripe
# Install on Linux
# Download from https://github.com/stripe/stripe-cli/releases
# Login and link your account
stripe login
# Verify
stripe --version
# cli_setup.py
# Verifying CLI setup
def check_cli():
commands = {
"stripe login": "Opens browser to authenticate CLI with your Stripe account",
"stripe status": "Shows connection status and account info",
"stripe config": "Shows current configuration",
"stripe listen": "Starts listening for webhook events",
}
print("Stripe CLI Commands:")
for cmd, desc in commands.items():
print(f" {cmd:30s} {desc}")
check_cli()
Webhook Forwarding
Forward Stripe events to your local development server.
# Forward all webhook events to local server
stripe listen --forward-to localhost:3000/api/webhooks
# Forward to a specific path
stripe listen --forward-to localhost:3000/api/stripe/webhooks
# Output:
# > Ready! You are using Stripe API Key [sk_test_...]
# > Your webhook signing secret is whsec_abc123...
# > Forwarding to localhost:3000/api/webhooks
# >
# > 2026-06-28 10:00:00 --> checkout.session.completed
# > 2026-06-28 10:00:01 --> customer.subscription.updated
Triggering Events
Generate test events without making real API calls.
# Trigger specific events
stripe trigger payment_intent.succeeded
stripe trigger checkout.session.completed
stripe trigger customer.subscription.deleted
stripe trigger invoice.payment_failed
# Trigger with specific data
stripe trigger checkout.session.completed \
--stripe-account acct_123
# trigger_events.py
# Understanding triggered events
def describe_triggers():
events = [
("payment_intent.succeeded", "Payment completed successfully"),
("payment_intent.payment_failed", "Payment failed"),
("checkout.session.completed", "Checkout payment completed"),
("customer.subscription.created", "New subscription"),
("customer.subscription.updated", "Subscription changed"),
("customer.subscription.deleted", "Subscription canceled"),
("invoice.payment_succeeded", "Invoice paid"),
("invoice.payment_failed", "Invoice payment failed"),
]
print("Common `stripe trigger` events:")
for event, desc in events:
print(f" {event:40s} {desc}")
describe_triggers()
Using Fixtures
Load test data using fixture files.
// fixtures.json
{
"fixtures": [
{
"name": "create_customer",
"path": "/v1/customers",
"method": "post",
"params": {
"email": "test@example.com",
"name": "Test Customer"
}
},
{
"name": "create_product",
"path": "/v1/products",
"method": "post",
"params": {
"name": "Test Product"
}
}
]
}
# Load fixtures
stripe fixtures fixtures.json
Common Mistakes
Not running stripe login first: The CLI must be authenticated with your Stripe account before use.
Using the wrong webhook secret: The webhook secret shown by stripe listen is temporary. Use your endpoint secret for production.
Forgetting to restart stripe listen: If your server restarts, the CLI needs to reconnect. Use a Process manager.
Not filtering forwarded events: stripe listen forwards all events. Monitor only what you need in development.
Using live mode CLI with test keys: The CLI uses your default API key. Set STRIPE_API_KEY to switch modes.
Practice Questions
What is the Stripe CLI used for? Listening for webhooks locally, triggering test events, managing resources, and loading test fixtures.
How do you forward webhooks to a local server? Use
stripe listen --forward-to localhost:3000/webhook.How do you trigger a test checkout.session.completed event? Use
stripe trigger checkout.session.completed.What is the webhook signing secret used for? Verifying that webhook events came from Stripe during local development.
Challenge: Create a fixture file that sets up a complete test environment with a customer, product, price, and subscription.
FAQ
Mini Project
Create a development workflow script that starts stripe listen, runs test events, and validates webhook responses.
import json
import time
def dev_workflow():
steps = [
"Starting Stripe CLI listener...",
"Listening for events on localhost:3000/webhook",
"Triggering checkout.session.completed...",
"Event received by application",
"Verifying webhook signature...",
"Processing event...",
"Triggering invoice.payment_failed...",
"Event received by application",
"Processing failed payment notification",
]
for step in steps:
print(f" {step}")
time.sleep(0.2)
print("\nDevelopment workflow complete!")
print("2 events processed successfully.")
dev_workflow()
What's Next
Next: Stripe Security for securing your integration.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro