Spaces:
Runtime error
Runtime error
SafeAIScan β Monetization Setup Guide
Goal: $500β1000/month at $1.99/mo Pro plan
1. Run the Database Migration
Go to your Supabase project β SQL Editor β New Query
Paste the entire contents of migration.sql and click Run.
This adds:
- Subscription tracking columns on
users paymentstable (revenue log + audit trail)usage_trackingtablerevenue_summaryview (check your MRR instantly)
2. Set Up PayPal Developer Account
- Go to developer.paypal.com
- Log in with your business PayPal account
- Go to My Apps & Credentials
- Create a Live app (or Sandbox for testing)
- Copy your Client ID and Secret
3. Create a PayPal Billing Plan (for recurring subscriptions)
This is the key step for recurring revenue. Without it, payments are one-time only.
- In PayPal Developer dashboard β Subscriptions β Plans β Create Plan
- Fill in:
- Product: Create new β "SafeAIScan Pro"
- Plan name: SafeAIScan Pro Monthly
- Billing cycle: Monthly, $1.99 USD
- Trial period: None (you handle trials in-app)
- Click Create Plan
- Copy the Plan ID (starts with
P-) - Repeat for Annual plan: $19.08/year, billing cycle = 12 months
4. Set Up PayPal Webhook
- In PayPal Developer β Webhooks β Add Webhook
- Webhook URL:
https://rathious-safeaiscan.hf.space/payment/webhook - Select these events:
BILLING.SUBSCRIPTION.ACTIVATEDBILLING.SUBSCRIPTION.RENEWEDBILLING.SUBSCRIPTION.PAYMENT.FAILEDBILLING.SUBSCRIPTION.CANCELLEDBILLING.SUBSCRIPTION.SUSPENDEDPAYMENT.CAPTURE.COMPLETEDPAYMENT.SALE.COMPLETED
- Save and copy the Webhook ID
5. Add Secrets to HuggingFace Space
Go to your HF Space β Settings β Repository secrets β Add:
| Secret Name | Value |
|---|---|
PAYPAL_CLIENT_ID |
Your PayPal app Client ID |
PAYPAL_CLIENT_SECRET |
Your PayPal app Secret |
PAYPAL_MODE |
live (use sandbox for testing) |
PAYPAL_PLAN_ID_PRO |
The Monthly plan ID (P-...) |
PAYPAL_PLAN_ID_ANNUAL |
The Annual plan ID (P-...) |
PAYPAL_WEBHOOK_ID |
Your webhook ID from step 4 |
APP_BASE_URL |
https://rathious-safeaiscan.hf.space |
SUPABASE_URL |
Already set |
SUPABASE_SERVICE_ROLE_KEY |
Already set |
6. Test the Full Flow (Sandbox First)
- Set
PAYPAL_MODE=sandbox - Create a sandbox buyer account at developer.paypal.com/tools/sandbox
- Register a new user on SafeAIScan
- Go to checkout β click Subscribe β use sandbox buyer account
- Confirm webhook fires: check HF Space logs for
PayPal webhook: BILLING.SUBSCRIPTION.ACTIVATED - Confirm user upgraded: check Supabase β
userstable βplan = 'pro' - Simulate payment failure: PayPal sandbox β Billing β trigger failed payment
- Confirm downgrade: user should revert to
plan = 'free'
Once all tests pass β set PAYPAL_MODE=live and restart the Space.
7. Revenue Path to $500β1000/month
| Target | Paid Users Needed |
|---|---|
| $500/month | 252 users Γ $1.99 |
| $750/month | 377 users Γ $1.99 |
| $1000/month | 503 users Γ $1.99 |
Conversion funnel:
- Every new user gets a 30-day free Pro trial automatically
- At trial end β automatic downgrade β upgrade prompt shown
- Industry benchmark: 5β8% of trial users convert to paid
- To hit $500/mo: need ~3,000β5,000 trial starts (252 Γ· 6%)
Growth levers (no cost):
- Post on r/netsec, r/devops, r/programming with a real scan demo
- Submit to ProductHunt, BetaList, HackerNews Show HN
- Add a "Powered by SafeAIScan" badge to generated PDFs (free ads)
- GitHub README scan results β share button β viral loop
- Offer a free "1 scan report" shareable link (no account needed)
8. Monitor Revenue
Run this query in Supabase SQL Editor anytime:
SELECT * FROM revenue_summary;
Also check the payments table for all transactions:
SELECT event_type, amount, created_at
FROM payments
ORDER BY created_at DESC
LIMIT 50;
API Endpoints Reference
| Endpoint | Method | Description |
|---|---|---|
/payment/create?billing=monthly |
POST | Start PayPal checkout |
/payment/subscription-success |
GET | PayPal return URL after approval |
/payment/success |
GET | One-time order fallback return URL |
/payment/cancel |
GET | PayPal cancel return URL |
/payment/webhook |
POST | PayPal webhook receiver |
/payment/cancel-subscription |
POST | User cancels own subscription |
/payment/activate |
POST | Manual Pro activation (support) |
/api/pricing |
GET | Current pricing (no auth) |
/api/subscription/status |
GET | User's subscription details |
/api/admin/run-migration |
POST | DB migration helper (admin only) |