Overview
Subscriptions in Tresa Contafy manage user access to features and enforce plan limits. Each subscription is linked to a user account and integrates with Stripe for payment processing.Subscriptions determine profile limits, storage quotas, and feature access based on the selected plan tier.
Why Subscriptions Matter
Proper subscription management ensures:- Access Control: Users can only access features available in their plan
- Resource Limits: Enforce profile and data limits per plan tier
- Billing Automation: Stripe handles recurring payments and invoice generation
- Upgrade Path: Clear upgrade paths for growing businesses
Data Structure
Plan Tiers
FREE
Free Forever
- 1 active profile
- Basic features
- Manual XML uploads only
- Community support
BASIC
Starter Plan
- 3 active profiles
- SAT automatic sync
- Email support
- Monthly reports
PRO
Professional Plan
- 10 active profiles
- Advanced analytics
- Priority support
- API access
- Custom categories
ENTERPRISE
Enterprise Plan
- Unlimited profiles
- Dedicated account manager
- SLA guarantees
- Custom integrations
- White-label option
Subscription Status
ACTIVE
ACTIVE
Normal active subscription. User has full access to plan features.
TRIALING
TRIALING
User is in a free trial period (typically 14 days for paid plans).Full plan features available during trial.
PAST_DUE
PAST_DUE
Payment failed but in grace period. User retains limited access.Stripe automatically retries payment. Profile creation may be frozen.
UNPAID
UNPAID
Payment failed after retry attempts. Access severely restricted.User can view data but cannot create new profiles or upload CFDIs.
CANCELLED
CANCELLED
User cancelled subscription but still has access until period end.After period_end, status changes to EXPIRED.
EXPIRED
EXPIRED
Subscription ended. User downgraded to FREE plan.Existing profiles beyond FREE limit are frozen.
Stripe Integration
Subscriptions integrate with Stripe for payment processing:Customer Creation
When a user subscribes to a paid plan:Subscription Creation
Webhook Handling
Tresa processes Stripe webhooks to keep subscription status synchronized:customer.subscription.created: New subscription activatedcustomer.subscription.updated: Plan changed or renewedcustomer.subscription.deleted: Subscription cancelled/expiredinvoice.payment_succeeded: Payment successful, renew periodinvoice.payment_failed: Payment failed, mark as PAST_DUE
All webhook events are verified using Stripe signature validation to ensure authenticity.
Plan Limits Enforcement
Profile Limits
The system enforces profile limits based on the user’s plan:Profile Freezing
When a user downgrades or subscription expires:- Count active profiles
- If exceeds new plan limit, freeze excess profiles
- Set
frozen_reason: 'plan_limit'on frozen profiles
- Cannot upload new CFDIs
- Cannot create expenses
- Existing data remains viewable
- Can be unfrozen by upgrading plan
Relationships
User Relationship
Indexes
Usage Examples
Get Current Subscription
Create Checkout Session
Cancel Subscription
Cancellation takes effect at the end of the current billing period. User retains access until then.
Resume Subscription
cancel_at_period_end: true.
Change Plan
Best Practices
Handle Webhooks Properly
Always verify Stripe webhook signatures and handle all subscription events to keep status synchronized.
Graceful Degradation
When subscription expires, freeze profiles gracefully rather than deleting data.
Clear Upgrade Prompts
Show clear upgrade prompts when users hit plan limits, with direct links to checkout.
Trial Management
Offer trials for paid plans to reduce friction and increase conversions.
Common Scenarios
New User Signup
- User registers → FREE plan subscription created automatically
- Status:
ACTIVE, plan:FREE - Can create 1 profile immediately
Upgrading to Paid Plan
- User clicks “Upgrade to PRO”
- Checkout session created with Stripe
- After payment: webhook updates subscription
- Status:
ACTIVE, plan:PRO, 10 profile limit - Previously frozen profiles (if any) can be unfrozen
Payment Failure
- Payment fails on renewal date
- Webhook:
invoice.payment_failed - Status changes to
PAST_DUE - Stripe retries payment automatically
- If all retries fail: Status →
UNPAID, profiles frozen
Cancellation Flow
- User cancels subscription
cancel_at_period_end: true- Status:
CANCELLED(but still active) - At period end: Status →
EXPIRED - Plan →
FREE, excess profiles frozen
Related Concepts
Profiles
Profile limits enforced by subscription
Invoices
Storage limits based on plan