# Connect

Authorize Zernio to read a Stripe account's payments, from the dashboard or with the connect API.

## Connect from the dashboard

1. Sign in to [Zernio](https://zernio.com/dashboard/connections) and open **Connections**.
2. Click **Connect an account**, pick the profile, and choose **Stripe** under **Analytics**.
3. In Stripe, pick the account and approve read-only access.
4. Back in Zernio, the account shows on the profile. Payments from then on count as sales.

## Connect a Stripe account

Request the authorization link for a profile, then send the user to `authUrl`:

```bash
curl "https://zernio.com/api/v1/connect/stripe?profileId=PROFILE_ID&redirect_url=https://example.com/done" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```

```json
{ "authUrl": "https://connect.stripe.com/oauth/authorize?response_type=code&client_id=…", "state": "…" }
```

The user approves read-only access. Stripe returns them to Zernio, which saves the account and redirects to `redirect_url` (or the dashboard) with `connected=stripe`, `profileId`, `accountId` and `username` (the Stripe account name).

## Disconnect

- **From Zernio:** on **Connections**, click **Disconnect** on the Stripe account, or call `DELETE /v1/accounts/{accountId}`. Zernio revokes its access, unless another Zernio profile still uses that Stripe account.
- **From Stripe:** in the Stripe Dashboard, open **Settings > Connected apps** and revoke Zernio. The account shows as needing reconnection in Zernio.

Sales already stored stay in `GET /v1/events`. Payments made while disconnected are not backfilled.

## How it behaves

- A profile holds one Stripe account. Reconnecting the same account refreshes it in place.
- Zernio stores no Stripe key: it reads each payment through Stripe Connect when the payment happens.
- A connection made in Stripe's live mode counts live payments only, never test payments.

## If it fails

| Error | Cause | Fix |
|-------|-------|-----|
| `stripe_profile_has_account` on the redirect | The profile already has a different Stripe account connected | Disconnect it first, or connect this account to another profile. |
| `stripe_access_denied` on the redirect | The user declined access in Stripe | Start the connect again and approve access. |
| `stripe_invalid_state` on the redirect | The link expired or was already used | Request a fresh `authUrl`. |
| `stripe_connection_failed` on the redirect | Stripe refused the code exchange | Start the connect again; contact support if it repeats. |
| `503` on `GET /v1/connect/stripe` | Stripe is not configured on this Zernio environment | Contact support. |

## Related

- [Get Stripe connect URL](/connect/get-stripe-connect-url)
- [Sales](/platforms/stripe/sales)