Guides
Stripe
Local testing with NextJs

Set up local tests for Stripe integration with NextJs

Testing Stripe integration locally is extremely important and has certain caveats.

Read this carefully

Install the stripe cli

brew install stripe/stripe-cli/stripe

Log in to stripe cli in terminal

Open a terminal window and log in to stripe.

Suggested method is login via API key. You will need access to the API key from the Stripe dashboard. If you don't have access ask for the API key.

Test mode API keys are here (opens in a new tab).

️🚫

Make sure you're in the correct project before taking the keys

stripe login --api-key {api key}

More details how to log in to Stripe cli are here (opens in a new tab)

Start listening for incoming webhook events

️🚫

You need to have a functional route in /api/webhooks/stripe or change the forward address to the local URL you expect to process incoming webhooks

stripe listen --forward-to http://localhost:3000/api/webhooks/stripe

This wil open a tunnel from Stripe to your local machine. You will now receive webhooks from Stripe or you can trigger events directly from another terminal window.

️🚫

This will create a webhook signing secret! You MUST use that one to process the webhook successfully.

Add this to an .env an process is that way because it is necessary in production as well!!

You can check all the webhooks here (opens in a new tab). You should see your local webhook now.

Testing Stripe subscription flow

Detailed instructions (opens in a new tab)

You can trigger stripe events from your terminal to test for specific webhook processing.

stripe trigger checkout.session.completed

You can find a full list of events here (opens in a new tab)