Introduction
When integrating Stripe into your web application, testing webhooks is a critical part of development. Stripe sends webhook events to notify your backend about successful payments, failed charges, payouts, and more. With the Stripe CLI, you can receive these events on your local server without deploying to production. In this blog post, we'll walk you through installing Stripe CLI, setting it up, and forwarding webhooks locally for seamless Stripe integration and testing.
What is Stripe CLI?
Stripe CLI (Command Line Interface) is a tool provided by Stripe to simplify development tasks. It allows developers to authenticate, manage resources, and test webhooks without writing any code. The most useful feature is the ability to listen to Stripe webhook events locally during development.
Install Stripe CLI
To get started, download the Stripe CLI from the official GitHub release page:
👉 Download Stripe CLI v1.28.0
After downloading:
Verify the Installation
Open your terminal and run the following to confirm Stripe CLI is installed:
If it returns the version number, you're good to go!
Login to Stripe CLI
Authenticate with your Stripe account using one of the following methods:
Or use interactive mode:
stripe login --interactive
Or use an API key directly:
stripe login --api-key YOUR_STRIPE_SECRET_KEY
Forward Webhooks to Localhost
To test your webhook integration locally, forward Stripe events to your local server using:
stripe listen --forward-to localhost:8000/webhook/stripe
After starting the listener, Stripe will output a webhook secret that you should copy and use in your application:
STRIPE_WEBHOOK_SECRET=your_webhook_secret_here
Trigger Test Events
You can simulate various webhook events using the Stripe CLI's trigger
command. Some commonly used ones:
stripe trigger payment_intent.succeeded
stripe trigger payout.paid
These commands will send simulated events to your local server, allowing you to test your webhook logic without making real transactions.
Conclusion
Stripe CLI is a powerful tool for developers working with Stripe. By enabling local webhook testing, it saves time and provides a smooth development experience. If you're building a Stripe integration, setting up the CLI should be one of your first steps. With just a few commands, you’ll be testing payment flows and handling real-world events in no time.