Stripe Payment Service
A Flask-based service to handle Stripe payments for mkultra.monster, supporting both one-time donations and $5 monthly subscriptions.
Features
- One-time donations (custom amounts $1-$999)
- $5 monthly subscriptions
- Webhook handling for payment confirmations
- CORS enabled for frontend integration
- Health check endpoint
- Rate limiting support
Server Setup (Digital Ocean VPS)
1. Prerequisites
Ensure you have Python 3.8+ installed on your VPS:
python3 --version
sudo apt update
sudo apt install python3 python3-pip python3-venv
2. Get Stripe API Keys
- Create a Stripe account at https://stripe.com
- Go to Dashboard > Developers > API Keys
- Copy your Publishable key (pk_test_…) and Secret key (sk_test_…)
- For webhooks, you’ll get the signing secret after creating the webhook endpoint
3. Deploy to VPS
Upload the stripe-service directory to your VPS. You can do this several ways:
Option A: Using scp from your local machine:
# From your local machine
scp -r stripe-service/ root@159.223.156.156:/var/www/
Option B: Using git (if you commit these files):
# On your VPS
cd /var/www
git clone https://github.com/cmdr-nova/cmdr-nova.github.io.git temp
mv temp/stripe-service .
rm -rf temp
Option C: Manual upload via SFTP/rsync:
# Use your preferred file transfer method to upload the stripe-service folder to /var/www/
4. Run Setup Script
sudo chmod +x /var/www/stripe-service/setup.sh
sudo /var/www/stripe-service/setup.sh
Edit the environment file with your actual Stripe keys: (skip til later)
sudo nano /var/www/stripe-service/.env
Update:
STRIPE_SECRET_KEY - Your secret key from Stripe
STRIPE_PUBLISHABLE_KEY - Your publishable key from Stripe
DOMAIN - Your actual domain (e.g., https://mkultra.monster)
6. Update Nginx Configuration
Step 6a: Add rate limiting to main nginx.conf
sudo nano /etc/nginx/nginx.conf
# Add this line inside the "http {" block:
# limit_req_zone $binary_remote_addr zone=stripe_api:10m rate=10r/m;
Step 6b: Update your site configuration
sudo cp /var/www/stripe-service/new-nginx-config /etc/nginx/sites-available/your-site
sudo nginx -t
sudo systemctl reload nginx
7. Start the Service
sudo systemctl enable stripe-payment
sudo systemctl start stripe-payment
sudo systemctl status stripe-payment
8. Test the Service
curl http://localhost:5001/health
# Should return: {"status":"healthy","service":"stripe-payment-service"}
9. Set Up Stripe Webhooks
- In Stripe Dashboard, go to Developers > Webhooks
- Click “Add endpoint”
- Set URL to:
https://mkultra.monster/api/stripe/webhook
- Select events:
checkout.session.completed
invoice.payment_succeeded
customer.subscription.deleted
- Copy the webhook signing secret and update it in your
.env file
- Restart the service:
sudo systemctl restart stripe-payment
API Endpoints
GET /health - Health check
POST /create-checkout-session - Create one-time payment session
POST /create-subscription - Create monthly subscription session
POST /webhook - Stripe webhook handler
GET /config - Get publishable key for frontend
Usage Examples
One-time Donation
fetch('/api/stripe/create-checkout-session', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ amount: 1000 }) // $10.00
})
.then(response => response.json())
.then(data => window.location.href = data.checkout_url);
Monthly Subscription
fetch('/api/stripe/create-subscription', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})
.then(response => response.json())
.then(data => window.location.href = data.checkout_url);
Monitoring
Check service logs:
sudo journalctl -u stripe-payment -f
Check service status:
sudo systemctl status stripe-payment
Security Notes
- Always use HTTPS in production
- Keep your Stripe secret key secure
- Use environment variables, never commit keys to git
- Enable webhook signature verification
- Consider IP whitelisting for webhook endpoints
- Regularly update dependencies
Troubleshooting
- Service won’t start: Check logs with
sudo journalctl -u stripe-payment
- Nginx 502 errors: Ensure the Flask service is running on port 5001
- CORS issues: Verify the nginx CORS headers are configured correctly
- Webhook failures: Check the webhook signing secret matches Stripe dashboard