> Markdown version of https://tuna.am/en/docs/tunnels/examples/stripe/. Documentation index: [llms.txt](https://tuna.am/en/llms.txt), full text in one file: [llms-full.txt](https://tuna.am/en/llms-full.txt). Any page is available as Markdown: append `.md` to its URL without the trailing slash.

# Stripe webhook on localhost

Stripe uses webhooks to report payments, subscriptions and refunds. For local development, Stripe has its own CLI: `stripe listen --forward-to localhost:4242/webhook`. tuna comes in handy when you need a real endpoint in the Dashboard: to check the event setup, show the integration to a colleague, or see requests in the inspector with replay.

## Step 1. Install the client

Instructions are available on the [installation page](https://tuna.am/en/docs/guides/install.md).

## Step 2. Run the app

Stripe signs every request with the `Stripe-Signature` header. The signature is computed over the raw request body, so the handler has to get the raw body rather than already parsed JSON. An example with Node.js and Express:

```js
const express = require('express');
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY);

const app = express();

app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
  let event;
  try {
    event = stripe.webhooks.constructEvent(
      req.body,
      req.headers['stripe-signature'],
      process.env.STRIPE_WEBHOOK_SECRET,
    );
  } catch (err) {
    return res.status(400).send(`Webhook Error: ${err.message}`);
  }
  console.log(event.type);
  res.sendStatus(200);
});

app.listen(4242);

```

tuna passes the body unchanged, so the signature matches. The `--verify-webhook` flag doesn't support Stripe — your app verifies the signature.

## Step 3. Start tuna

```bash
tuna http 4242 --subdomain=<your-subdomain>

```

The [free permanent subdomain](https://tuna.am/en/docs/tunnels/http.md#free-subdomain) keeps the address the same across restarts, so you don't have to edit the endpoint in Stripe.

## Step 4. Add an endpoint

In the Dashboard, in test mode, open Webhooks and add an endpoint:

* address: `https://<your-subdomain>.a.tuna.free/webhook`;
* events: for example, `payment_intent.succeeded` and `checkout.session.completed`.

After saving, copy the `whsec_…` signing secret into the `STRIPE_WEBHOOK_SECRET` variable and restart the app.

## Step 5. Check

Create a test event with the Stripe CLI or make a payment with a [test cardOpens in a new tab](https://docs.stripe.com/testing):

```bash
stripe trigger payment_intent.succeeded

```

The request shows up in the [inspector](https://tuna.am/en/docs/tunnels/inspect.md) at `http://127.0.0.1:4040` along with the app's response. Stripe shows delivery attempts and responses on the endpoint's page in the Dashboard.

Replay from the inspector sends the same body and the same signature. The Stripe signature includes the time it was sent, and `constructEvent` rejects events older than 5 minutes by default. So you can replay a request from the inspector within 5 minutes; after that, create a new event.

If it doesn't arrive, follow the steps in [Webhook doesn't reach the app](https://tuna.am/en/docs/troubleshooting/webhook-not-delivered.md).
