# `PhoenixKit.Migrations.Postgres.V33`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.87/lib/phoenix_kit/migrations/postgres/v33.ex#L1)

PhoenixKit V33 Migration: Payment Providers and Subscriptions

This migration introduces payment provider integrations (Stripe, PayPal, Razorpay)
and the subscription system with internal billing control.

## Design Philosophy

PhoenixKit uses **Internal Subscription Control** - subscriptions are managed
in our database as the source of truth, not by payment providers. This approach:
- Allows using providers without subscription API support
- Gives full control over subscription lifecycle
- Enables pause, resume, proration calculations
- Supports multiple providers for the same subscription

## Changes

### Payment Methods Table (phoenix_kit_payment_methods)
- Saved payment methods (cards, wallets) for recurring billing
- Tokenized data from providers (no raw card data stored)
- Display info for user (last4, brand, expiration)

### Subscription Plans Table (phoenix_kit_subscription_plans)
- Subscription pricing plans
- Interval configuration (day/week/month/year)
- Trial period support
- Feature list (JSONB)

### Subscriptions Table (phoenix_kit_subscriptions)
- User subscriptions (master record)
- Status tracking with grace period and dunning
- Billing cycle management
- Payment method association

### Payment Provider Configs Table (phoenix_kit_payment_provider_configs)
- Provider credentials (encrypted)
- Webhook secrets
- Test/Live mode configuration

### Webhook Events Table (phoenix_kit_webhook_events)
- Webhook event logging for idempotency
- Event processing status tracking
- Retry count for failed events

### Modifications to Existing Tables
- Orders: checkout session fields
- Invoices: subscription reference

### Settings Seeds
- Provider enable/disable settings
- Subscription grace period configuration
- Dunning retry configuration

# `down`

Rollback the V33 migration.

# `up`

Run the V33 migration to add payment providers and subscriptions.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
