# Client Portal

Each client has access to a personalized portal where they can view their invoices, quotes, and payment status. No account or password creation is required.

## Portal Access

### For the Client

Frihet generates a **secure link** for each invoice:

```
https://app.frihet.io/pay/{userId}/{invoiceId}/{token}
```

The client clicks and accesses directly without logging in. The link is automatically included in invoice emails with a "View and Pay Invoice" button.

### No Account Required

No need to:
- Create user
- Remember password
- Configure 2FA

The link is **unique per invoice** and identified by an HMAC-SHA256 token. Each user+invoice combination generates a deterministic token, without database storage.

## What the Client Sees in the Portal

Upon opening the link, the client sees a page with your branding (logo and brand color):

### Header
- Your company's logo or initial with your brand color
- Your business name
- Invoice number

### Invoice Details
- Highlighted total amount
- Due date
- Issue date
- Client name
- Line item table: description, quantity, unit price, amount
- Breakdown: subtotal, VAT, IRPF (if applicable), total

### Status
- Green banner if already paid
- Red banner if overdue

### Notes
If the invoice includes notes, they are shown at the end.

### Payment Button
If you have Stripe Connect configured, a "Pay [amount]" button appears, which redirects to the Stripe checkout. The payment is processed, and the invoice is automatically marked as paid.

## Features by Plan

### Free Plan

- View invoices: ✅
- Download PDF: ✅
- View quotes: ✅
- Direct message: ❌
- Accept quote: ❌

### Pro Plan

- All Free Plan features +
- Accept quotes: ✅
- Send message: ✅ (received in your email)
- History: ✅

### Premium Plan

- All Pro Plan features +
- Custom branded portal (your logo, colors)
- Project status (if using Projects module)
- Download consolidated statement
- Portal integration: accept quote → automatic invoice

## Portal Customization

### In Pro and Premium Plans

Customize the client experience:

1. Go to **Settings > Client Portal**
2. Upload **logo** (JPG, PNG, max 2MB)
3. Choose **primary color** (your brand)
4. Write **welcome message**
5. Configure portal **language**

Example:

```
Logo:         Your company logo
Color:        #0066cc
Welcome:   "Secure access to your invoices and documents"
Language:       Spanish / English (automatic based on browser)
```

### Automatic Language

If a client accesses from an English browser, the portal automatically displays in English (if you enabled multi-language in the Premium plan).

## Security

### Authentication

- Unique HMAC-SHA256 token per invoice (deterministic, no DB storage)
- Timing-safe comparison to prevent timing attacks
- HTTPS mandatory
- Security headers: `X-Frame-Options: DENY`, `X-Content-Type-Options: nosniff`

### Privacy

The client **only sees**:
- The specific invoice from the link
- Secure data (no internal IDs or sensitive data are exposed)

Cannot access:
- Other invoices
- Data from other clients
- Expense information
- Your account settings

### Access Revocation

If you delete a client:

1. Their portal links are immediately invalidated
2. Cannot access anything
3. Data is kept for audit (logical deletion, not physical)

## Sending Invoices

### Automatic

When you create an invoice, Frihet asks:

```
¿Send by email to client?
✓ Yes, with link to the portal
○ No, just save
```

### Manual

To resend an invoice:

1. Open invoice in Frihet
2. Click **Send**
3. An email is sent with:
   - PDF file attached
   - Link to the portal
   - Due date
   - Payment details if configured

### Email Template

Default:

```
Subject: Your invoice INV-2026-001 is ready

Hello,

Attached is your invoice from February 5 for 1,250 EUR.

Due: March 7, 2026
Payment term: 30 days

View in portal: [link]
Download PDF: [direct download link]

[Your contact details]
```

In the Premium plan, customize the template and signature.

## Client Notifications

Frihet can automatically send:

- **Invoice issued**: Email when you create a new invoice
- **Payment reminder**: Email 3 days before due date (configurable)
- **Payment received**: Confirmation email when marked as paid
- **Quote expired**: Notification if a quote expires without being accepted

Configure in **Settings > Client Notifications**.

## Support and Questions

If a client has questions via the portal:

### In Pro/Premium Plans

A **"Send message"** field appears for the client. The message reaches your email:

```
From: Acme Corp
Message: "Can I change the shipping address on the invoice?"
```

You reply via normal email (or from Frihet).

### In Free Plan

Client cannot send direct message (incentive for upgrade).

## Usage Metrics

In **Reports > Client Portal**:

- Active clients (who accessed in the last month)
- Documents downloaded
- Messages sent
- Average view time

Useful for knowing if a client reads your invoices or needs a reminder.

## Common Problem: Client Cannot Access

### Expired Link

If a client saves a link and uses it 6 months later:

- If the client is still in your database: normal access (token valid indefinitely)
- If you deleted the client: access blocked

**Solution**: Resend invoice (generates a new valid link).

### Email Spam

Frihet email goes to spam. Solutions:

1. Client adds `noreply@frihet.io` to contacts
2. In the Premium plan, use your own domain (SPF/DKIM configured)
3. Resend from Frihet (not client forwards)

## Upcoming Improvements

We are developing:

- **Portal with chat**: Integrated direct contact
- **Push notifications**: Alert when an invoice is due
- **Bizum payments**: Alternative to card payment
- **Additional documents**: Receipts, credit notes
- **Access control**: Client only sees invoices for a specific project/contract
---
