# Connect a payment provider

> Connect Stripe, Polar or Dodo Payments and pass the visitor id at checkout.

Open your website’s **Settings → Payments** and connect Stripe, Polar or Dodo Payments. Reveata then receives new payments through webhooks and imports recent history. Provider credentials are stored encrypted.

To link a payment to the visit that led to it, the checkout needs to carry the visitor id. The tracking script provides it:

```js
window.reveata.metadata();
// → { reveata_visitor_id: "…", reveata_session_id: "…" }
```

Without it, Reveata still matches payments by user id or email for visitors you [identified](https://reveata.com/docs/identify-visitors). In cookieless mode there is no visitor id in the browser, so identify is the way to link payments.

## Step-by-step guides

Each setup option also has its own guide:

- **Stripe:** [restricted key](https://reveata.com/docs/stripe-restricted-key), [Connect with Stripe](https://reveata.com/docs/stripe-connect), [Stripe Checkout](https://reveata.com/docs/stripe-checkout), [Payment Links and buy buttons](https://reveata.com/docs/stripe-payment-links), [Elements and mobile apps](https://reveata.com/docs/stripe-payment-intents).
- [Polar](https://reveata.com/docs/polar)
- [Dodo Payments](https://reveata.com/docs/dodo-payments)
- **Platforms without an integration:** [Ghost](https://reveata.com/docs/revenue-ghost), [Kajabi](https://reveata.com/docs/revenue-kajabi), [Podia](https://reveata.com/docs/revenue-podia), [Easytools](https://reveata.com/docs/easytool), and [apps built with AI](https://reveata.com/docs/revenue-ai-builders).

Every payment is stored once, however many times it arrives: see [Why payments are never counted twice](https://reveata.com/docs/no-double-counting).

## Stripe

**Payment Links, Buy Buttons and Pricing Tables** need no code: the script adds a `client_reference_id` to `buy.stripe.com` links and to `<stripe-buy-button>` and `<stripe-pricing-table>` elements on your pages.

**Checkout Sessions** created on your server: send the metadata from the browser to your server, then add it to the session:

```js
// browser: include the ids in the request that creates the checkout
await fetch('/api/checkout', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ priceId, ...window.reveata.metadata() }),
});
```

```js
// server (Node.js)
const session = await stripe.checkout.sessions.create({
  mode: 'subscription',
  line_items: [{ price: priceId, quantity: 1 }],
  success_url: 'https://example.com/thanks',
  metadata: {
    reveata_visitor_id: body.reveata_visitor_id,
    reveata_session_id: body.reveata_session_id,
  },
});
```

**Disputes.** A dispute that closes lost takes its amount out of revenue like a refund. Give the restricted key read access to Disputes (the **Create the key in Stripe** button in Reveata ticks it) so past disputes are imported too.


## Polar

Add the ids to the checkout `metadata` when you create it. Polar copies checkout metadata onto orders and subscriptions:

```js
const checkout = await polar.checkouts.create({
  products: [productId],
  successUrl: 'https://example.com/thanks',
  metadata: { reveata_visitor_id: visitorId, reveata_session_id: sessionId },
});
```

When you connect Polar, create a webhook endpoint in Polar (**Settings → Webhooks**, format **Raw**) with the URL shown in Reveata and paste its secret. Disconnecting removes that endpoint from Polar when the token has the `webhooks:write` scope.


## Dodo Payments

Add the ids to the checkout session or payment `metadata`:

```js
metadata: { reveata_visitor_id: visitorId, reveata_session_id: sessionId }
```

When you connect Dodo Payments, add a webhook in Dodo (**Developer → Webhooks**) with the URL shown in Reveata, paste its signing secret (`whsec_…`), and send these events:

`payment.succeeded`, `refund.succeeded`, `subscription.active`, `subscription.renewed`, `subscription.on_hold`, `subscription.cancelled`, `subscription.failed`, `subscription.expired`, `subscription.plan_changed`, `subscription.updated`, `dispute.lost`, `dispute.accepted`

Subscription events that arrive late never overwrite a newer state. A lost or accepted dispute takes its amount out of revenue like a refund. Disconnecting removes that webhook from Dodo.



## Anything else

Send payments from your server with the [Payments API](https://reveata.com/docs/payments-api).

## Links opened outside your site

Payment links sent by email, put in a social bio or printed as a QR code are opened without the tracking script, so they carry no visitor id. Point their success URL at your own thank-you page with the provider's checkout id (for example `?session_id={CHECKOUT_SESSION_ID}` for Stripe) and Reveata links the payment when the customer lands there. See [thank-you page payments](https://reveata.com/docs/thank-you-page-payments) for every provider and for `reveata('payment', { email })`.

## Check it works

1. Open your site in a private window from a link ending in `?ref=test`.
2. Buy something in your provider’s test mode, or make a small real purchase and refund it afterwards. A free, fully discounted checkout is not a payment, so it does not show up.
3. The payment appears under Revenue with the source `test` once the provider’s webhook arrives.

If nothing arrives, **Settings → Payments** shows each provider’s last webhook delivery and the latest error. From there you can register the webhook again or replace its signing secret.
