# Billing App

Subscription and billing management for Dexxy.

## Purpose

This app manages pricing plans and workspace subscriptions. It provides the data model for SaaS billing, with external payment processing handled separately (e.g., Stripe webhooks).

## Models

### Plan

Represents a pricing tier.

| Field | Type | Description |
|-------|------|-------------|
| `name` | CharField | Plan display name |
| `price_cents` | IntegerField | Price in cents |
| `currency` | CharField | Currency code (e.g., "usd") |
| `active` | BooleanField | Available for new subscriptions |
| `features` | JSONField | Feature list for plan comparison |

### Subscription

Links a workspace to a billing plan.

| Field | Type | Description |
|-------|------|-------------|
| `workspace` | ForeignKey | The subscribing workspace |
| `plan` | ForeignKey | The selected plan |
| `status` | CharField | Subscription state |
| `current_period_end` | DateTimeField | When current billing period ends |

**Status Values:**
- `active` - Subscription is current and paid
- `past_due` - Payment failed, grace period
- `canceled` - Subscription ended

## GraphQL API

### Queries

- `plans(active_only?)` - List available pricing plans
- `plan(id)` - Get a specific plan
- `subscriptions(workspace_id)` - Get workspace subscriptions
- `subscription(id)` - Get a specific subscription

### Mutations

None - Subscription changes are handled via external payment provider webhooks.

## Key Patterns

1. **Price in Cents**: Avoids floating-point currency issues
2. **Feature Flags**: JSON features field for flexible plan differentiation
3. **External Sync**: Subscription state managed by payment webhooks

## Dependencies

- `accounts.Workspace`

## File Structure

```
billing/
├── models.py      # Plan, Subscription models
├── graphql.py     # GraphQL types and queries
├── apps.py        # Django app config
└── migrations/    # Database migrations
```
