This guide explains how to set up Stripe payments in the Rain OS frontend to work with the backend payment system.
- Rain OS Backend running with Stripe configured
- Stripe account with products and prices created
- Node.js and npm installed
Create a .env file in the root directory (copy from .env.example):
cp .env.example .envUpdate the values in .env:
# Your backend API URL
REACT_APP_API_BASE_URL=http://localhost:3001/api
# Your Stripe publishable key
REACT_APP_STRIPE_PUBLISHABLE_KEY=pk_test_your_key_here- Log in to Stripe Dashboard
- Go to Products section
- Click on each product to see its prices
- Copy the Price ID (starts with
price_)
Edit /src/constants.ts and replace the placeholder price IDs:
export const STRIPE_PRICE_IDS = {
// Basic Plan: $29.99/month - 50 analyses
basic: 'price_YOUR_BASIC_PRICE_ID',
// Pro Plan: $99.99/month - 200 analyses
pro: 'price_YOUR_PRO_PRICE_ID',
// Enterprise Plan: $299.99/month - Unlimited
enterprise: 'price_YOUR_ENTERPRISE_PRICE_ID',
};The application supports three subscription tiers:
| Plan | Price | Analyses/Month | Features |
|---|---|---|---|
| Free | $0 | 5 | Basic features |
| Basic | $29.99 | 50 | Email support, Analytics |
| Pro | $99.99 | 200 | Priority support, Multiple sites, API access |
| Enterprise | $299.99 | Unlimited | Dedicated support, Custom integration, White label |
For testing, use Stripe test mode:
- Use test API keys (start with
pk_test_andsk_test_) - Use test card numbers:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - Authentication:
4000 0025 0000 3155
- Success:
- Any future expiry date and any 3-digit CVC
The payment flow works as follows:
- User clicks "Upgrade" on a plan
- Frontend calls
/api/stripe/create-checkout-sessionwith price ID - Backend creates Stripe Checkout session
- User is redirected to Stripe Checkout
- After payment, user returns to
/dashboard?status=success - Frontend shows success message and refreshes user data
- Backend webhook updates user subscription in database
Users can manage their subscriptions through:
- Billing Portal: Click "Manage Subscription" button
- Available actions:
- Update payment method
- Change subscription plan
- Cancel subscription
- View invoices
The frontend uses these backend endpoints:
POST /api/stripe/create-checkout-session- Start subscriptionPOST /api/stripe/create-portal-session- Manage subscriptionGET /api/users/me- Get user subscription status
"No checkout URL received"
- Check backend is running
- Verify API_BASE_URL is correct
- Check price ID exists in Stripe
"Failed to start upgrade process"
- Verify user is authenticated
- Check API key is valid
- Ensure backend Stripe keys are configured
Subscription not updating
- Check webhook is configured in Stripe
- Verify webhook endpoint is accessible
- Check webhook secret is correct
For production:
- Switch to live Stripe keys
- Update environment variables
- Use HTTPS for all endpoints
- Configure production webhook URL
- Test with real payment methods
- Never expose secret keys in frontend code
- Always use environment variables for sensitive data
- Validate webhook signatures on backend
- Use HTTPS in production
- Implement proper error handling
/services/stripe.ts- Stripe service functions/components/dashboard/BillingPage.tsx- Subscription plans UI/components/dashboard/DashboardHomePage.tsx- User subscription status/constants.ts- Stripe configuration
createCheckoutSession(priceId)- Start subscription checkoutcreatePortalSession()- Open billing portalhandleCheckoutRedirect()- Handle return from StripegetSubscriptionTier(limit)- Determine user's planformatSubscriptionStatus(status)- Format status for display
For issues or questions:
- Check backend logs for API errors
- Review Stripe Dashboard logs
- Ensure webhook events are being received
- Contact support with error messages and logs