T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/domains/soundstudiopro.com/private_html/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/domains/soundstudiopro.com/private_html/STRIPE_WEBHOOK_SETUP.md
# Stripe Webhook Setup Guide

## What Happens After Subscription

### 1. User Completes Checkout
- User clicks "Subscribe Now" → Redirected to Stripe Checkout
- User enters payment info → Stripe processes payment
- User redirected to `/subscription_success.php`

### 2. Stripe Sends Webhook Events
Stripe automatically sends these events to your webhook endpoint:

**Events You Need:**
- `customer.subscription.created` - New subscription created
- `customer.subscription.updated` - Subscription changed (upgrade/downgrade/renewal)
- `customer.subscription.deleted` - Subscription cancelled
- `invoice.payment_succeeded` - Payment successful
- `invoice.payment_failed` - Payment failed

### 3. Your Webhook Handler Processes Events
Location: `/webhooks/stripe.php`

**What it does:**
- Creates subscription record in `user_subscriptions` table
- Updates user's plan in `users` table
- Initializes monthly track usage in `monthly_track_usage` table
- Saves Stripe customer ID to user account
- Logs everything to `/logs/stripe_actions.log`

---

## 🔧 How to Set Up Webhooks

### Step 1: Go to Stripe Dashboard
1. Login to [Stripe Dashboard](https://dashboard.stripe.com)
2. Go to **Developers → Webhooks**
3. Click **"Add endpoint"**

### Step 2: Configure Webhook Endpoint
- **Endpoint URL**: `https://soundstudiopro.com/webhooks/stripe.php`
- **Description**: "Subscription Management"
- **Events to send**: Select these events:
  - `customer.subscription.created`
  - `customer.subscription.updated`
  - `customer.subscription.deleted`
  - `invoice.payment_succeeded`
  - `invoice.payment_failed`
  - `payment_intent.succeeded` (for one-time purchases)
  - `payment_intent.payment_failed` (for one-time purchases)

### Step 3: Get Webhook Signing Secret
1. After creating endpoint, click on it
2. Copy the **"Signing secret"** (starts with `whsec_`)
3. Update `/webhooks/stripe.php` with this secret (line ~15)

### Step 4: Test Webhook
1. In Stripe Dashboard → Webhooks → Your endpoint
2. Click **"Send test webhook"**
3. Select `customer.subscription.created`
4. Check `/logs/stripe_actions.log` to verify it worked

---

## 📅 Cron Job Setup

### Monthly Reset Cron
Location: `/cron/reset_monthly_limits.php`

**What it does:**
- Resets track usage to 0 for all active subscribers
- Runs on the 1st of each month
- Updates `monthly_track_usage` table

### How to Set Up Cron

**Option 1: cPanel Cron Jobs**
1. Go to cPanel → Cron Jobs
2. Add new cron job:
   - **Minute**: `0`
   - **Hour**: `0`
   - **Day**: `1`
   - **Month**: `*`
   - **Weekday**: `*`
   - **Command**: 
     ```bash
     /usr/bin/php /home/gositeme/domains/soundstudiopro.com/public_html/cron/reset_monthly_limits.php
     ```

**Option 2: Via URL (Less Secure)**
1. Set a secret key in `/cron/reset_monthly_limits.php` (line 9)
2. Add cron job:
   ```bash
   0 0 1 * * curl "https://soundstudiopro.com/cron/reset_monthly_limits.php?cron_key=YOUR_SECRET_CRON_KEY"
   ```

**Option 3: Manual Test**
Visit: `https://soundstudiopro.com/cron/reset_monthly_limits.php?cron_key=YOUR_SECRET_CRON_KEY`

---

## ✅ Verification Checklist

- [ ] Webhook endpoint created in Stripe Dashboard
- [ ] Webhook signing secret added to `/webhooks/stripe.php`
- [ ] Test webhook sent and verified in logs
- [ ] Cron job set up for monthly reset
- [ ] Test subscription signup works
- [ ] Check `/logs/stripe_actions.log` for webhook events
- [ ] Verify subscription appears in `user_subscriptions` table

---

## 🔍 What Gets Stored

### Database Tables:

**`user_subscriptions`**
- `user_id` - User who subscribed
- `stripe_subscription_id` - Stripe subscription ID
- `stripe_customer_id` - Stripe customer ID
- `plan_name` - essential/starter/pro/premium/enterprise
- `status` - active/past_due/canceled/etc
- `current_period_start` - When current billing period started
- `current_period_end` - When current billing period ends

**`monthly_track_usage`**
- `user_id` - User ID
- `year_month` - "2025-01" format
- `tracks_created` - How many tracks used this month
- `track_limit` - Monthly limit (5, 20, 75, 200, 1000)

**`users` table**
- `plan` - Updated to subscription plan name
- `stripe_customer_id` - Saved for future payments

---

## 🐛 Troubleshooting

### Webhooks Not Working?
1. Check `/logs/stripe_actions.log` for errors
2. Verify webhook URL is correct in Stripe Dashboard
3. Check webhook signing secret matches
4. Test with Stripe's "Send test webhook" feature

### Subscriptions Not Activating?
1. Check webhook events are being received
2. Verify database tables exist (`user_subscriptions`, `monthly_track_usage`)
3. Check PHP error logs
4. Verify user exists in database

### Monthly Reset Not Working?
1. Verify cron job is running (check cron logs)
2. Test manually: `/cron/reset_monthly_limits.php?cron_key=YOUR_KEY`
3. Check `/logs/monthly_reset.log` for errors

---

## 📊 Monitoring

**Log Files:**
- `/logs/stripe_actions.log` - All webhook events
- `/logs/monthly_reset.log` - Monthly reset operations

**Admin Tools:**
- `/verify_stripe_prices.php` - Check Price IDs
- `/admin.php?tab=subscriptions` - View all subscriptions


CasperSecurity Mini