# Stripe

Match payments to posts, and keep refunds in step.

## What we read

Payments, refunds and disputes. We write nothing. We never ask for a full secret key.

## Connect

1. Open **Integrations**, then Stripe.
2. Copy our webhook address.
3. In Stripe, open **Developers**, then **Webhooks**. Add our address and choose the events listed on our page.
4. Copy Stripe's signing secret, which starts with `whsec_`, and paste it into our page.
5. To bring in old payments, also add a **restricted** read key. It starts with `rk_`. We refuse full secret keys.
6. Make a test payment in Stripe's test mode.

## Pass the visitor id

This is the best proof. For a Stripe Payment Link, add the id as `client_reference_id`:

```text title="Payment Link"
https://buy.stripe.com/YOUR_LINK?client_reference_id=v_...
```

For Checkout made by your server, send the visitor id from the page and add it:

```ts title="Your server"
const session = await stripe.checkout.sessions.create({
  mode: "payment",
  line_items: [{ price: "price_123", quantity: 1 }],
  success_url: "https://coach.example/thanks",
  client_reference_id: visitorId,
  metadata: { tm_visitor: visitorId },
});
```

If you already use `client_reference_id` for something else, keep it and use metadata only.

## One payment, many events

Stripe can send several events for one payment. We use the payment intent as the main id, so it counts once.

## If it doesn't match

See [Why a sale is unknown](/docs/sales/unknown).
