Skip to content

Stripe CLI — Command-Line Tools for Development and Testing

DodaTech Updated 2026-06-28 4 min read

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

  1. Not running stripe login first: The CLI must be authenticated with your Stripe account before use.

  2. Using the wrong webhook secret: The webhook secret shown by stripe listen is temporary. Use your endpoint secret for production.

  3. Forgetting to restart stripe listen: If your server restarts, the CLI needs to reconnect. Use a Process manager.

  4. Not filtering forwarded events: stripe listen forwards all events. Monitor only what you need in development.

  5. Using live mode CLI with test keys: The CLI uses your default API key. Set STRIPE_API_KEY to switch modes.

Practice Questions

  1. What is the Stripe CLI used for? Listening for webhooks locally, triggering test events, managing resources, and loading test fixtures.

  2. How do you forward webhooks to a local server? Use stripe listen --forward-to localhost:3000/webhook.

  3. How do you trigger a test checkout.session.completed event? Use stripe trigger checkout.session.completed.

  4. What is the webhook signing secret used for? Verifying that webhook events came from Stripe during local development.

  5. Challenge: Create a fixture file that sets up a complete test environment with a customer, product, price, and subscription.

FAQ

Is the Stripe CLI free?

Yes. The Stripe CLI is free and open-source.

Can I run stripe listen in production?

No. stripe listen is for local development. Use webhook endpoints configured in the Dashboard for production.

How do I switch between test and live mode?

Set the STRIPE_API_KEY environment variable to your test or live secret key.

Can I trigger custom event payloads?

Yes. Use the --override parameter to customize event data.

Does the CLI support CI/CD?

Yes. Use stripe trigger in automated tests to validate webhook handling.

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