# Stripe: connect with a restricted key

> Connect Stripe to Reveata with a read-only restricted key, and let Reveata create the webhook or add it yourself.

A restricted key is a Stripe API key that can only do what you allow. Reveata only needs to read your payments, plus permission to create one webhook endpoint. This is the way to connect Stripe on every Reveata website. If the Stripe card also offers **Connect with Stripe**, you can use that instead: see [Stripe: Connect with Stripe](https://reveata.com/docs/stripe-connect).

## Create the key

1. Open your website in Reveata, then **Settings → Payments**. Under **Pick your payment provider**, choose **Stripe**.
2. Select **Create the key in Stripe**. Stripe opens its restricted-key form, named Reveata, with the permissions below already ticked. If the link does not open, copy the address shown under the button into your browser.
3. In Stripe, check the permissions and create the key. Copy it: it starts with `rk_live_` (or `rk_test_` in test mode).
4. Back in Reveata, paste it into **Restricted key** and select **Connect Stripe**.

The key needs read access to:

| Stripe permission | Why Reveata reads it                                                    |
| ----------------- | ------------------------------------------------------------------------ |
| Payment Intents   | One-off payments, including Elements and mobile apps                     |
| Invoices          | Subscription payments and renewals                                       |
| Subscriptions     | MRR, trials, upgrades, downgrades and cancellations                      |
| Checkout Sessions | The visitor id your checkout carries                                     |
| Refunds           | Refunds, booked as negative revenue on the day they happen               |
| Charges           | Refund and dispute links back to the original payment                    |
| Customers         | The buyer's email and name, used to match the payment to a visitor       |
| Disputes          | Lost disputes, which leave revenue like a refund (optional, recommended) |

Reveata checks the key when you connect. If one of the first five reads is missing, it says which one so you can edit the key in Stripe and paste it again. A key without Disputes still connects; past disputes are then skipped by the import.

A live key (`rk_live_`) only counts live payments, and a test key (`rk_test_`) only test payments, so test purchases never mix into real revenue. To try the setup end to end, connect a test key to a test website first.

## The webhook

New payments reach Reveata through a Stripe webhook, within seconds.

- **With Webhook Endpoints write access** (ticked by the **Create the key in Stripe** link), Reveata creates the endpoint for you, subscribed to the events it needs, and removes it again when you disconnect. The card shows **Set up in Stripe by Reveata** next to **Webhook**.
- **Without it**, the connection still works, and the card asks you to add the endpoint yourself. In Stripe, open **Developers → Webhooks**, add an endpoint with the URL Reveata shows, and select these events. Then paste its signing secret (`whsec_…`) into the card and choose **Save secret**.

```text
checkout.session.completed
checkout.session.async_payment_succeeded
payment_intent.succeeded
invoice.paid
charge.refunded
refund.created
refund.updated
charge.dispute.closed
customer.subscription.created
customer.subscription.updated
customer.subscription.deleted
customer.subscription.paused
customer.subscription.resumed
```

You can also paste a signing secret in the optional **Webhook signing secret** field while connecting, if you created the endpoint first.

Until a webhook works, Reveata still reads Stripe on a schedule (every hour without a webhook, every six hours with one), so payments arrive late rather than never.

## What gets imported

When you connect, Reveata imports the last 12 months of payments, refunds, lost disputes and subscriptions, oldest first. The card shows the import's progress; you can leave the page. **Sync now** reads Stripe again at any time.

- A subscription invoice is one payment, without tax. A first invoice is new revenue; later cycles are renewals that keep the first payment's source.
- A one-off PaymentIntent is one payment. A PaymentIntent that pays an invoice is counted once, through its invoice.
- Amounts are stored in your website currency at the rate of the payment day.

## Link payments to visits

Connecting brings in the money. To credit each payment to the visit that led to it, the checkout has to carry the visitor id:

- [Stripe Checkout](https://reveata.com/docs/stripe-checkout) for sessions your server creates.
- [Stripe Payment Links and buy buttons](https://reveata.com/docs/stripe-payment-links), which need no code.
- [Stripe Elements and mobile apps](https://reveata.com/docs/stripe-payment-intents) for PaymentIntents.

Payments without a visitor id are still matched by email for visitors you [identify](https://reveata.com/docs/identify-visitors).

## Check it works

1. In the card, select **Test connection**: Reveata asks Stripe with the stored key and says whether it still works.
2. Make a purchase from a link ending in `?ref=test`: with a test key on a test website, or a small real purchase you refund 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`, and **Last delivery** on the card shows the webhook arrived.

## Change or remove the key

- **Update key** replaces the key for the same Stripe account without losing anything. A key from a different Stripe account is refused: connect it as a new provider instead.
- **Disconnect** removes the webhook endpoint Reveata created. You choose whether to keep the imported payments or delete them.
