# Stripe Revenue Sync

:::tip Available
This integration is active and ready to use on all Pro plans.
:::

Automatically import your Stripe collections as invoices registered in Frihet. Ideal for SaaS businesses that collect with Stripe and need to keep their invoicing in order.

## What is it for?

If you collect with Stripe and want those collections to appear as invoices in Frihet without creating them manually:

- **Automatic import** — Each paid invoice in Stripe becomes an invoice in Frihet
- **Incremental synchronization** — Only imports new collections since the last sync
- **Deduplication** — An invoice is never duplicated even if you run the import multiple times
- **VeriFactu compatible** — Imported invoices go through the hash chain and gap-free numbering

## Difference with Stripe integration

| | Stripe (OAuth) | Stripe Revenue Sync |
|---|---|---|
| **Connection** | OAuth (redirect to Stripe) | Restricted API Key |
| **Direction** | Bidirectional | Stripe only → Frihet |
| **Type** | Payments + subscriptions + Connect | Paid invoices only |
| **Invoices** | Automatic by webhook | On-demand import + auto-sync |
| **Use case** | Collect from Frihet | Record Stripe collections in Frihet |

**Use Revenue Sync if:** you collect directly from Stripe (Dashboard, Billing, etc.) and you want those collections to appear in Frihet for your accounting and declarations.

## Requirements

- **Active Stripe account** — [Create one at stripe.com](https://stripe.com)
- **Restricted API Key** — With read-only permissions on invoices and customers
- **Frihet Pro or higher** — Not available on Free plan

## Set up Stripe Revenue Sync

### Step 1: Create a restricted API Key in Stripe

1. Go to [Stripe Dashboard → Developers → API Keys](https://dashboard.stripe.com/apikeys)
2. Click on **Create restricted key**
3. Name: `Frihet Revenue Sync`
4. Required permissions:
   - **Invoices** → Read
   - **Customers** → Read
5. Copy the key (`rk_live_...`)

### Step 2: Connect in Frihet

1. Go to **Settings** → **Integrations**
2. Search for **Stripe Revenue Sync**
3. Click on **Connect**
4. Paste your restricted API Key
5. Select the date from which you want to import
6. Click on **Save and connect**

### Step 3: Import invoices

1. Click on **Import now**
2. Frihet will query paid invoices in Stripe from the selected date
3. Each invoice is created as a draft and marked as paid
4. Gap-free numbering and the VeriFactu hash are applied automatically

### Step 4: Activate auto-sync (optional)

1. In the settings tab, activate **Auto-sync**
2. Frihet will automatically import new collections every 6 hours
3. Only new invoices are imported (incremental synchronization)

## How it works

### Manual import

1. You click **Import now**
2. Frihet queries `GET /v1/invoices?status=paid` in Stripe
3. For each invoice that does not already exist in Frihet (by `stripeInvoiceId`):
   - Creates a draft invoice with the client's data
   - Marks it as paid
   - Server-side processes are executed: numbering and VeriFactu hash
4. Result: invoices ready for your ledger and declarations

### Auto-sync (every 6 hours)

1. A scheduled function runs every 6 hours
2. Queries only invoices from `lastSync` (incremental)
3. Automatically imports the new ones
4. Updates `lastSync` with the current date
5. If it detects that your API Key has expired, it marks the integration as `requiresReconnect`

### Deduplication

Each imported invoice saves the Stripe invoice ID (`stripeInvoiceId`) in its metadata. If you try to import the same invoice twice, Frihet automatically ignores it.

### Data mapping

| Stripe | Frihet |
|--------|--------|
| `invoice.customer_name` or `customer_email` | Client name |
| `invoice.number` | Reference (in concept) |
| `line_items[].description` | Invoice lines |
| `line_items[].amount` | Amount per line |
| `invoice.tax` | Taxes (if applicable) |
| `invoice.created` | Invoice date |
| `invoice.id` | `stripeInvoiceId` (metadata) |

## Security

- **Restricted API Key** — Read-only access to invoices and customers. No access to money.
- **AES-256-GCM encryption** — Your API Key is stored encrypted on the server
- **Instant disconnection** — Revoke access in Settings whenever you want
- **No data in transit** — Communication with Stripe is HTTPS, the key is never exposed to the frontend

## Disconnect

1. Go to **Settings** → **Integrations**
2. Search for **Stripe Revenue Sync**
3. Click on **Disconnect**
4. Confirm the action

Already imported invoices remain in Frihet. They are not deleted upon disconnection.

## Troubleshooting

### "No invoices imported"

- Verify that your API Key has read permissions on **Invoices** and **Customers**
- Make sure the import date is prior to your collections
- Only invoices with status `paid` are imported in Stripe
- Check that you are not in Stripe test mode (use live keys)

### "Reconnect your account"

- Your API Key has expired or been revoked
- Go to Stripe Dashboard → API Keys and create a new one
- Disconnect and reconnect in Frihet with the new key

### "Duplicate invoice"

- It should not happen. Deduplication by `stripeInvoiceId` prevents it
- If you see duplicates, contact support

### "Amounts do not match"

- Frihet imports the amount as reported by Stripe
- Stripe fees are not deducted from the invoice (they are a separate expense)
- Verify the currency: Stripe reports in cents, Frihet converts automatically

## Next steps

- [Use Stripe to collect directly](./stripe)
- [Set up payment links with Stripe Connect](./stripe-connect)
- [Also connect WooCommerce if you have a store](./woocommerce)

---

**Next:** [Stripe Connect - Payment links on your invoices](./stripe-connect)
