Stripe Payment Service

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

  1. Create a Stripe account at https://stripe.com
  2. Go to Dashboard > Developers > API Keys
  3. Copy your Publishable key (pk_test_…) and Secret key (sk_test_…)
  4. 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

5. Configure Environment

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

  1. In Stripe Dashboard, go to Developers > Webhooks
  2. Click “Add endpoint”
  3. Set URL to: https://mkultra.monster/api/stripe/webhook
  4. Select events:
    • checkout.session.completed
    • invoice.payment_succeeded
    • customer.subscription.deleted
  5. Copy the webhook signing secret and update it in your .env file
  6. 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

  1. Service won’t start: Check logs with sudo journalctl -u stripe-payment
  2. Nginx 502 errors: Ensure the Flask service is running on port 5001
  3. CORS issues: Verify the nginx CORS headers are configured correctly
  4. Webhook failures: Check the webhook signing secret matches Stripe dashboard