8.2 KiB
Pricing Configuration Feature
This document describes the new configurable pricing feature that allows MASTER instances to manage pricing plans through the admin interface.
Overview
The pricing configuration feature allows administrators on MASTER instances to:
- Create, edit, and delete pricing plans
- Configure plan features, prices, and settings
- Set resource quotas for rooms, conversations, storage, and users
- Mark plans as "Most Popular" or "Custom"
- Control plan visibility and ordering
- Update pricing without code changes
Features
Pricing Plan Management
- Plan Name: Display name for the pricing plan
- Description: Optional description shown below the plan name
- Pricing: Monthly and annual prices (annual prices are typically 20% lower)
- Features: Dynamic list of features with checkmarks
- Button Configuration: Customizable button text and URL
- Plan Types: Regular plans with prices or custom plans
- Popular Plans: Mark one plan as "Most Popular" with special styling
- Active/Inactive: Toggle plan visibility
- Ordering: Control the display order of plans
Resource Quotas
- Room Quota: Maximum number of rooms allowed (0 = unlimited)
- Conversation Quota: Maximum number of conversations allowed (0 = unlimited)
- Storage Quota: Maximum storage in gigabytes (0 = unlimited)
- Manager Quota: Maximum number of manager users allowed (0 = unlimited)
- Admin Quota: Maximum number of admin users allowed (0 = unlimited)
Admin Interface
- Pricing Tab: New tab in admin settings (MASTER instances only)
- Add/Edit Modals: User-friendly forms for plan management
- Real-time Updates: Changes are reflected immediately
- Feature Management: Add/remove features dynamically
- Quota Configuration: Set resource limits for each plan
- Status Toggles: Quick switches for plan properties
Setup Instructions
1. Database Migration
Run the migrations to create the pricing_plans table and add quota fields:
# Apply the migrations
alembic upgrade head
2. Initialize Default Plans (Optional)
Run the initialization script to create default pricing plans:
# Set MASTER environment variable
export MASTER=true
# Run the initialization script
python init_pricing_plans.py
This will create four default plans with quotas:
- Starter: 5 rooms, 10 conversations, 10GB storage, 10 managers, 1 admin
- Professional: 25 rooms, 50 conversations, 100GB storage, 50 managers, 3 admins
- Enterprise: 100 rooms, 200 conversations, 500GB storage, 200 managers, 10 admins
- Custom: Unlimited everything
3. Access Admin Interface
- Log in as an admin user on a MASTER instance
- Go to Settings
- Click on the "Pricing" tab
- Configure your pricing plans
Usage
Creating a New Plan
- Click "Add New Plan" in the pricing tab
- Fill in the plan details:
- Name: Plan display name
- Description: Optional description
- Monthly Price: Price per month
- Annual Price: Price per month when billed annually
- Quotas: Set resource limits (0 = unlimited)
- Features: Add features using the "Add Feature" button
- Button Text: Text for the call-to-action button
- Button URL: URL the button should link to
- Options: Check "Most Popular", "Custom Plan", or "Active" as needed
- Click "Create Plan"
Editing a Plan
- Click the "Edit" button on any plan card
- Modify the plan details in the modal
- Click "Update Plan"
Managing Plan Status
- Active/Inactive: Use the toggle switch in the plan header
- Most Popular: Check the "Most Popular" checkbox (only one plan can be popular)
- Custom Plan: Check "Custom Plan" for plans without fixed pricing
Deleting a Plan
- Click the "Delete" button on a plan card
- Confirm the deletion in the modal
Technical Details
Database Schema
The pricing_plans table includes:
id: Primary keyname: Plan name (required)description: Optional descriptionmonthly_price: Monthly price (float)annual_price: Annual price (float)features: JSON array of feature stringsbutton_text: Button display textbutton_url: Button link URLis_popular: Boolean for "Most Popular" stylingis_custom: Boolean for custom plansis_active: Boolean for plan visibilityorder_index: Integer for display orderingroom_quota: Maximum rooms (0 = unlimited)conversation_quota: Maximum conversations (0 = unlimited)storage_quota_gb: Maximum storage in GB (0 = unlimited)manager_quota: Maximum managers (0 = unlimited)admin_quota: Maximum admins (0 = unlimited)created_by: Foreign key to user who created the plancreated_at/updated_at: Timestamps
API Endpoints
POST /api/admin/pricing-plans- Create new planGET /api/admin/pricing-plans/<id>- Get plan detailsPUT /api/admin/pricing-plans/<id>- Update planDELETE /api/admin/pricing-plans/<id>- Delete planPATCH /api/admin/pricing-plans/<id>/status- Update plan status
Template Integration
The pricing page automatically uses configured plans:
- Falls back to hardcoded plans if no plans are configured
- Supports dynamic feature lists
- Handles custom plans without pricing
- Shows/hides billing toggle based on plan types
- Displays quota information in plan cards
Quota Enforcement
The PricingPlan model includes utility methods for quota checking:
check_quota(quota_type, current_count): Returns True if quota allows the operationget_quota_remaining(quota_type, current_count): Returns remaining quotaformat_quota_display(quota_type): Formats quota for displayget_storage_quota_bytes(): Converts GB to bytes for storage calculations
Example usage in your application:
# Check if user can create a new room
plan = PricingPlan.query.get(user_plan_id)
current_rooms = Room.query.filter_by(created_by=user.id).count()
if plan.check_quota('room_quota', current_rooms):
# Allow room creation
pass
else:
# Show upgrade message
pass
Security
- Only admin users can access pricing configuration
- Only MASTER instances can configure pricing
- All API endpoints require authentication and admin privileges
- CSRF protection is enabled for all forms
Customization
Styling
The pricing plans use the existing CSS variables:
--primary-color: Main brand color--secondary-color: Secondary brand color--shadow-color: Card shadows
Button URLs
Configure button URLs to point to:
- Contact forms
- Payment processors
- Sales pages
- Custom landing pages
Features
Features can include:
- Storage limits
- User limits
- Feature availability
- Support levels
- Integration options
Quota Integration
To integrate quotas into your application:
- User Plan Assignment: Associate users with pricing plans
- Quota Checking: Use the
check_quota()method before operations - Upgrade Prompts: Show upgrade messages when quotas are exceeded
- Usage Tracking: Track current usage for quota calculations
Troubleshooting
Common Issues
-
Pricing tab not visible
- Ensure you're on a MASTER instance (
MASTER=true) - Ensure you're logged in as an admin user
- Ensure you're on a MASTER instance (
-
Plans not showing on pricing page
- Check that plans are marked as "Active"
- Verify the database migration was applied
- Check for JavaScript errors in browser console
-
Features not saving
- Ensure at least one feature is provided
- Check that feature text is not empty
-
Quota fields not working
- Verify the quota migration was applied
- Check that quota values are integers
- Ensure quota fields are included in form submissions
-
API errors
- Verify CSRF token is included in requests
- Check that all required fields are provided
- Ensure proper JSON formatting for features
Debugging
- Check browser console for JavaScript errors
- Review server logs for API errors
- Verify database connectivity
- Test with default plans first
Future Enhancements
Potential future improvements:
- Plan categories/tiers
- Regional pricing
- Currency support
- Promotional pricing
- Plan comparison features
- Analytics and usage tracking
- Automatic quota enforcement middleware
- Usage dashboard for quota monitoring