Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,43 @@ METRICS_PORT=9090
ENABLE_COLLABORATION=true
ENABLE_GIT_INTEGRATION=true
ENABLE_CUSTOM_DOMAINS=true

# Payment Gateway Configuration
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret

# PayPal Configuration
PAYPAL_CLIENT_ID=your_paypal_client_id
PAYPAL_SECRET=your_paypal_secret
PAYPAL_MODE=sandbox

# Cryptocurrency Payment (Coinbase Commerce)
COINBASE_COMMERCE_API_KEY=your_coinbase_commerce_api_key
COINBASE_COMMERCE_WEBHOOK_SECRET=your_coinbase_webhook_secret

# Email Notification Service (choose one)
# Option 1: SendGrid
SENDGRID_API_KEY=your_sendgrid_api_key

# Option 2: SMTP
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
[email protected]
SMTP_PASSWORD=your_app_password
[email protected]

# SMS Notification Service (Twilio)
TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_PHONE_NUMBER=+1234567890

# Billing Configuration
[email protected]
INVOICE_GENERATION_ENABLED=true
INVOICE_STORAGE_PATH=./invoices

# Usage Tracking
USAGE_TRACKING_ENABLED=true
USAGE_BILLING_DAY=1
120 changes: 120 additions & 0 deletions MONETIZATION_IMPLEMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Monetization System - Implementation Summary

## Overview

This document provides a comprehensive summary of the monetization system implementation for the Algo Cloud IDE platform. The system includes subscription management, usage-based billing, payment processing, prepaid credits, and usage alerts.

## What Has Been Implemented

### 1. Database Schema βœ…

**File:** `backend/database/monetization-schema.sql`

Created comprehensive database schema with 15+ tables including subscription_plans, usage_metrics, billing_history, stored_payment_methods, usage_alerts, prepaid_credits, and more.

**Default Plans:**
- Free Tier: $0/month (500MB storage, 500 compute hours, 10GB bandwidth)
- Pro Tier: $15/month (5GB storage, 2000 compute hours, 50GB bandwidth)
- Team Tier: $49/month (20GB storage, 5000 compute hours, 200GB bandwidth)
- Enterprise Tier: Custom pricing (unlimited resources)

### 2. Backend Services βœ…

Four comprehensive TypeScript services:
- **SubscriptionService**: Plan management, upgrades, downgrades, cancellations with proration
- **UsageTrackingService**: Real-time usage tracking, cost calculation, alert triggering
- **BillingService**: Invoice generation, payment processing, webhook handling
- **CreditsService**: Prepaid credits, auto-reload, transaction management

### 3. API Routes βœ…

30+ RESTful API endpoints across 5 route modules:
- Subscription routes: plans, subscribe, upgrade, downgrade, cancel
- Usage routes: current usage, history, project summaries
- Billing routes: invoices, payments, payment methods, webhooks
- Credits routes: balance, purchase, auto-reload
- Alerts routes: configure, history, toggle

### 4. Frontend Components βœ…

Four polished React components with responsive CSS:
- **Pricing Page**: Tier comparison with monthly/yearly toggle
- **Billing Dashboard**: Usage visualization, invoice history
- **Credits Management**: Purchase, auto-reload, transaction history
- **Usage Alerts**: Configure thresholds and notifications

### 5. Documentation βœ…

- **MONETIZATION_SYSTEM.md**: Complete technical documentation
- **SECURITY_WARNINGS.md**: Critical security considerations
- Environment configuration added to .env.example

## Usage-Based Pricing

- Deployment Hours: $0.01/hour
- Database Storage: $0.10/GB/month
- Bandwidth: $0.05/GB beyond quota
- AI API Usage: Cost + 20% markup (for platform-managed keys)

## Critical TODOs Before Production ⚠️

1. **Payment Processing**: Replace mock with Stripe SDK integration
2. **Webhook Verification**: Implement signature verification
3. **Notifications**: Implement email/SMS alert system
4. **Auto-Reload**: Implement payment processing for auto-reload
5. **Authentication**: Add auth middleware to routes
6. **TypeScript**: Enable strict mode and fix type errors
7. **Testing**: Add unit and integration tests
8. **Dependencies**: Run npm install and verify build

See SECURITY_WARNINGS.md for detailed information.

## File Structure

```
backend/
β”œβ”€β”€ database/monetization-schema.sql
β”œβ”€β”€ src/
β”‚ β”œβ”€β”€ services/
β”‚ β”‚ β”œβ”€β”€ subscription-service.ts
β”‚ β”‚ β”œβ”€β”€ usage-tracking-service.ts
β”‚ β”‚ β”œβ”€β”€ billing-service.ts
β”‚ β”‚ └── credits-service.ts
β”‚ └── routes/
β”‚ β”œβ”€β”€ subscription-routes.ts
β”‚ β”œβ”€β”€ usage-routes.ts
β”‚ β”œβ”€β”€ billing-routes.ts
β”‚ β”œβ”€β”€ credits-routes.ts
β”‚ └── alerts-routes.ts
src/components/
β”œβ”€β”€ Pricing.tsx/css
β”œβ”€β”€ BillingDashboard.tsx/css
β”œβ”€β”€ CreditsManagement.tsx/css
└── UsageAlerts.tsx/css
```

## Quick Start

1. Apply database schema:
```bash
psql -U algo_user -d algo_ide -f backend/database/monetization-schema.sql
```

2. Install dependencies:
```bash
cd backend && npm install
```

3. Configure environment variables in .env

4. Start backend:
```bash
npm run dev
```

5. Test API:
```bash
curl http://localhost:4000/api/subscriptions/plans
```

For complete documentation, see MONETIZATION_SYSTEM.md and SECURITY_WARNINGS.md.
Loading
Loading