# Payment Gateway Setup
CloudPOS supports Stripe for subscription payments. This guide covers setting up Stripe integration.
# Overview
Stripe integration allows tenants to:
- Subscribe to plans via Stripe Checkout
- Pay monthly or yearly
- Automatically renew subscriptions
- Manage subscriptions via Stripe Customer Portal
# Step 1: Create Stripe Account
- Go to: https://stripe.com
- Sign up for an account
- Complete account verification
- Access Stripe Dashboard
# Step 2: Get Stripe API Keys
# Test Mode (Development)
- Stripe Dashboard → Developers → API keys
- Copy:
- Publishable key:
pk_test_... - Secret key:
sk_test_...
- Publishable key:
# Live Mode (Production)
- Toggle Test mode off in Stripe Dashboard
- Copy:
- Publishable key:
pk_live_... - Secret key:
sk_live_...
- Publishable key:
⚠️ Never share your secret keys!
# Step 3: Create Products and Prices in Stripe
For each subscription plan, create a product in Stripe:
# Create Product
- Stripe Dashboard → Products → Add product
- Fill in:
- Name: Plan name (e.g., "Basic Plan")
- Description: Plan description
- Click Save
# Create Prices
For each product, create two prices (monthly and yearly):
Monthly Price:
- Click Add price
- Set:
- Price: Monthly amount (e.g.,
29.99) - Billing period: Recurring → Monthly
- Currency: USD (or your currency)
- Price: Monthly amount (e.g.,
- Click Save
- Copy Price ID (e.g.,
price_1234567890)
Yearly Price:
- Click Add price again
- Set:
- Price: Yearly amount (e.g.,
299.99) - Billing period: Recurring → Yearly
- Currency: USD
- Price: Yearly amount (e.g.,
- Click Save
- Copy Price ID
Repeat for each plan (Trial, Basic, Pro, Enterprise).
# Step 4: Configure Payment Gateway in Admin Panel
# Method 1: Via Admin Panel (Recommended)
Login to Admin Panel:
http://localhost:5173/admin/loginNavigate to Settings → Payment Gateways
Click Create or Edit Stripe gateway
Fill in:
Test Mode:
- Publishable Key (Test):
pk_test_... - Secret Key (Test):
sk_test_... - Webhook Secret (Test):
whsec_...(get from Step 5)
Live Mode:
- Publishable Key (Live):
pk_live_... - Secret Key (Live):
sk_live_... - Webhook Secret (Live):
whsec_...(get from Step 5)
- Publishable Key (Test):
Toggle Test Mode on/off as needed
Toggle Is Active to enable gateway
Click Save
# Method 2: Via Environment Variables (Legacy)
Add to .env file:
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key_here
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret_here
Note: Admin Panel method is recommended as it supports test/live mode switching.
# Step 5: Configure Stripe Webhooks
Webhooks notify CloudPOS when payments succeed or fail.
# Create Webhook Endpoint
- Stripe Dashboard → Developers → Webhooks
- Click Add endpoint
- Set Endpoint URL:
- Development:
http://localhost:3000/api/subscriptions/webhook - Production:
https://yourdomain.com/api/subscriptions/webhook
- Development:
- Click Add endpoint
# Select Events
Select these events to listen to:
- ✅
checkout.session.completed - ✅
customer.subscription.created - ✅
customer.subscription.updated - ✅
customer.subscription.deleted - ✅
invoice.payment_succeeded - ✅
invoice.payment_failed
Click Add events.
# Get Webhook Secret
- After creating webhook, click on it
- Find Signing secret
- Click Reveal and copy the secret (starts with
whsec_) - Add to Admin Panel → Payment Gateways → Webhook Secret
# Step 6: Configure Plan Price IDs
Link Stripe prices to CloudPOS plans:
- Admin Panel → Plans → Select a plan
- Fill in:
- Stripe Price ID (Monthly):
price_xxxxx(from Step 3) - Stripe Yearly Price ID:
price_xxxxx(from Step 3)
- Stripe Price ID (Monthly):
- Click Save
Repeat for each plan.
# Step 7: Test Payment Flow
# Test Mode Setup
- Ensure Test Mode is enabled in Admin Panel
- Use Stripe test card numbers:
- Success:
4242 4242 4242 4242 - Decline:
4000 0000 0000 0002 - 3D Secure:
4000 0025 0000 3155
- Success:
- Use any future expiry date (e.g.,
12/34) - Use any 3-digit CVC
# Test Subscription
- Login as tenant (or register new tenant)
- Navigate to Subscription → Plans
- Select a plan
- Click Subscribe
- Complete Stripe Checkout with test card
- Verify:
- Payment succeeds
- Plan is assigned to tenant
- Subscription status is ACTIVE
# Verify Webhook
- Stripe Dashboard → Developers → Webhooks
- Click on your webhook
- View Events tab
- Check recent events:
checkout.session.completedshould be successful- Check response (should be 200 OK)
# Production Checklist
Before going live:
- [ ] Switch to Live Mode in Admin Panel
- [ ] Add Live API keys (not test keys)
- [ ] Configure Production webhook URL
- [ ] Get Production webhook secret
- [ ] Test with real card (small amount)
- [ ] Verify webhook events are received
- [ ] Monitor webhook logs in Stripe Dashboard
# Local Webhook Testing (Development)
For local development, use Stripe CLI to forward webhooks:
# Install Stripe CLI
# macOS
brew install stripe/stripe-cli/stripe
# Windows
# Download from: https://github.com/stripe/stripe-cli/releases
# Linux
# Download from: https://github.com/stripe/stripe-cli/releases
# Forward Webhooks
# Login to Stripe
stripe login
# Forward webhooks to local server
stripe listen --forward-to localhost:3000/api/subscriptions/webhook
This will:
- Show webhook secret (use this in Admin Panel)
- Forward all webhook events to your local server
# Trigger Test Events
# Trigger checkout completion
stripe trigger checkout.session.completed
# Trigger subscription creation
stripe trigger customer.subscription.created
# Troubleshooting
# Payment Succeeds But Plan Not Assigned
Issue: Stripe payment completes but tenant doesn't get plan
Solutions:
Check webhook configuration:
- Verify webhook URL is correct
- Check webhook secret matches
- View webhook events in Stripe Dashboard
Check webhook logs:
- Stripe Dashboard → Webhooks → Select webhook → Events
- Look for failed events
- Check error messages
Check application logs:
# PM2 logs pm2 logs cloudpos # Or server logs tail -f logs/pm2-error.logManually assign plan:
- Admin Panel → Tenants → Select tenant
- Manually assign plan
# Webhook Not Receiving Events
Issue: Webhook endpoint not receiving events from Stripe
Solutions:
Verify webhook URL:
- Must be publicly accessible (not localhost in production)
- Must use HTTPS in production
- Must be exactly:
https://yourdomain.com/api/subscriptions/webhook
Check firewall/security:
- Allow Stripe IPs (see Stripe docs)
- Check server firewall rules
Test webhook manually:
- Stripe Dashboard → Webhooks → Select webhook
- Click Send test webhook
- Check if received
# Invalid Webhook Secret
Error: No signatures found matching the expected signature
Solutions:
Verify webhook secret:
- Get secret from Stripe Dashboard → Webhooks → Signing secret
- Must match exactly (no spaces, correct test/live mode)
Check test/live mode:
- Test mode webhook secret ≠ Live mode webhook secret
- Use correct secret for current mode
# CORS Errors
Issue: Frontend can't connect to Stripe
Solutions:
Check CORS settings:
- Verify
CORS_ORIGINin.envmatches frontend URL - Restart API server after changes
- Verify
Check Stripe keys:
- Use publishable key in frontend (not secret key)
- Verify keys match test/live mode
# Disabling Payments
If you want to disable payments and use manual plan assignment:
- Admin Panel → Payment Gateways
- Toggle Is Active to OFF for Stripe
- Or remove Stripe configuration
Tenants can still be assigned plans manually via Admin Panel.
Next: See Email Notifications to configure email sending.