Documentation Index
Fetch the complete documentation index at: https://mintlify.com/MatthewSabia1/SubPirate-Pro/llms.txt
Use this file to discover all available pages before exploring further.
Overview
SubPirate uses Stripe for subscription billing. This integration handles:- Subscription checkout and payments
- Plan upgrades and downgrades
- Webhook events for subscription lifecycle
- Customer portal for self-service billing management
Prerequisites
Before starting, you’ll need:- A Stripe account (sign up at dashboard.stripe.com)
- Stripe CLI for local webhook testing (optional but recommended)
- Supabase project with subscription tables migrated
Subscription Tiers
SubPirate offers three subscription tiers:| Tier | Monthly Price | Annual Price | Features |
|---|---|---|---|
| Essentials | $29/mo | $290/year | 10 analyses/month, 1 Reddit account, 2 campaigns, 3 projects |
| Professional | $79/mo | $790/year | 50 analyses/month, 5 Reddit accounts, 10 campaigns, 10 projects, AI scheduler, advanced dashboard, team access |
| Agency | $199/mo | $1,990/year | Unlimited analyses, accounts, campaigns, projects, AI scheduler, advanced dashboard, team access |
Stripe Setup
Create Stripe Account
If you don’t have one, create an account at https://dashboard.stripe.com.Start in Test Mode for development.
Create Products and Prices
Create three products in Stripe Dashboard → Products:
Essentials Product
- Name: SubPirate Essentials
- Metadata:
tier=essentials - Prices:
- Monthly: $29.00 recurring
- Annual: $290.00 recurring
Professional Product
- Name: SubPirate Professional
- Metadata:
tier=professional - Prices:
- Monthly: $79.00 recurring
- Annual: $790.00 recurring
Agency Product
- Name: SubPirate Agency
- Metadata:
tier=agency - Prices:
- Monthly: $199.00 recurring
- Annual: $1,990.00 recurring
Copy Price IDs
After creating prices, copy each Price ID (format:
price_xxxxxxxxxxxxx) from the Stripe Dashboard.You’ll need six Price IDs total (one monthly + one annual for each tier).Environment Variables
Add these to your.env file:
.env
Configure Webhooks
Stripe uses webhooks to notify your app about subscription events (payments, cancellations, etc.).Local Development
Forward Webhooks to Localhost
whsec_...). Copy it to your .env:Production (Vercel)
Create Webhook Endpoint
In Stripe Dashboard → Developers → Webhooks, click Add endpoint.Endpoint URL:
Select Events
Add these events:
checkout.session.completedinvoice.paidinvoice.payment_failedcustomer.subscription.updatedcustomer.subscription.deleted
Webhook Processing
The webhook processor is implemented inapi/_lib/stripeWebhookProcessor.js.
Idempotency
All webhook events are logged in thestripe_webhook_events table to prevent duplicate processing:
failed and can be retried.
Event Handlers
checkout.session.completed
Processed when a user completes Stripe Checkout:invoice.paid
Processed on successful recurring payments:invoice.payment_failed
Processed when a payment fails:customer.subscription.updated
Processed when a subscription is modified (plan changes, cancellations):customer.subscription.deleted
Processed when a subscription is canceled:Identity Resolution
The webhook processor resolves user identity through multiple fallback strategies:- By Stripe Subscription ID: Query
subscriptionstable - By Stripe Customer ID: Query
subscriptionstable - By Metadata: Check
subscription.metadata.user_id
stripe_webhook_unmatched for manual review.
Customer Portal
Stripe Customer Portal allows users to self-manage their subscriptions.Configure Features
Enable:
- Cancel subscription
- Switch plans (upgrade/downgrade with proration)
- Update payment method
- View invoices
Dynamic Payment Methods
Stripe automatically selects optimal payment methods based on customer location.Email Notifications
Configure Stripe to send automatic emails:Testing
Test Cards
Use these cards in Test Mode:| Card Number | Scenario |
|---|---|
4242 4242 4242 4242 | Successful payment |
4000 0000 0000 0341 | Immediate charge failure |
4000 0025 0000 3155 | Requires 3D Secure authentication |
4000 0000 0000 9995 | Insufficient funds |
Test Checklist
- Complete checkout with test card
4242 4242 4242 4242 - Verify
checkout.session.completedwebhook fires - Confirm subscription appears in database with status
active - Check
/settingspage shows correct plan - Click “Manage Subscription” and verify portal opens
- Test plan upgrade (Starter → Creator)
- Test plan downgrade and verify
downgrade_action_requiredis set - Cancel subscription and verify status updates to
canceled - Test failed payment with card
4000 0000 0000 0341 - Verify grace period is set and user can still access features
Database Schema
subscriptions Table
stripe_webhook_events Table
Logs all processed webhook events for idempotency:stripe_webhook_unmatched Table
Stores events where user identity couldn’t be resolved:Go-Live Checklist
Before switching to Live Mode:- Review Stripe Go-Live Checklist
- Create live-mode Products and Prices
- Update all 6 Price ID environment variables with live-mode IDs
- Switch
STRIPE_SECRET_KEYfromsk_test_tosk_live_ - Create live-mode webhook endpoint
- Update
STRIPE_WEBHOOK_SECRETwith live-mode webhook secret - Test a live-mode checkout with a real card (then refund)
- Verify webhook events are processed correctly in production
- Enable fraud detection in Stripe Radar
- Set up billing email notifications
Troubleshooting
”No signature found” Error
Cause: Missing or incorrectSTRIPE_WEBHOOK_SECRET.
Solution: Verify the webhook secret matches the one shown in Stripe Dashboard (or Stripe CLI output).
Webhook Event Not Processing
Cause: Webhook endpoint unreachable or returning errors. Solution:- Check Stripe Dashboard → Webhooks → click your endpoint → view event logs
- Verify your server is publicly accessible (use ngrok for local testing)
- Check server logs for errors in webhook handler
Subscription Not Found in Database
Cause: Identity resolution failed or webhook processing error. Solution:- Check
stripe_webhook_unmatchedtable for the event - Verify
metadata.user_idis set when creating checkout sessions - Review logs in
stripe_webhook_eventstable
Security Considerations
Next Steps
- Reddit OAuth Integration - Connect user accounts
- OpenRouter AI Integration - Configure analysis quotas per plan