![]() 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/public_html/ |
# Why Stéphane's Plan Changed from Essential to Premium
## What Happened
You added 100 credits to Stéphane from the **Admin Panel → Credits Management** tab. Here's the exact sequence:
### Step-by-Step Breakdown
1. **You went to:** Admin Panel → Credits Management tab
2. **You selected:** Stéphane's user account
3. **You used the "Add Credits" form** which has:
- **Package dropdown:** starter, pro, **premium** (premium is selected by default)
- **Credits field:** You entered `100`
- **Amount field:** $129.00 (default for premium)
4. **When you clicked "Add Credits":**
- The form submitted with: `package='premium'`, `credits=100`
- It called: `addCreditsToUser($user_id, 100, 'premium', '30_days', null)`
5. **The Bug in `addCreditsToUser()` function:**
```php
// OLD BUGGY CODE (before fix):
$plan_name = $package; // This set plan to 'premium'!
UPDATE users
SET credits = credits + 100,
plan = 'premium' // ❌ BUG: Changed plan based on credit package!
WHERE id = ?
```
6. **Result:**
- ✅ Credits added: +100 credits
- ❌ Plan changed: `essential` → `premium`
- ❌ Track limit changed: 5 tracks/month → 200 tracks/month
## Root Cause
The `addCreditsToUser()` function in `webhooks/stripe.php` was **incorrectly updating the user's plan based on the credit package**, instead of **preserving their subscription plan**.
**The problem:** Credits and subscription plans are **independent**:
- **Subscription plan** (essential, pro, premium, enterprise) = Monthly subscription = Track limits
- **Credit packages** (starter, pro, premium) = One-time credit purchases = Credits only
When you add credits, it should **ONLY add credits**, not change the subscription plan!
## The Fix
I've updated `addCreditsToUser()` to:
1. **Check if user has active subscription first**
2. **Preserve subscription plan** if they have one
3. **Only update plan** if user has NO subscription (credit-only users)
4. **Multiple safeguards** to prevent this from happening again
### New Code Logic:
```php
// NEW FIXED CODE:
if (user has active subscription) {
// Keep their subscription plan (essential, pro, etc.)
plan = subscription.plan_name
} else if (current plan is a subscription plan) {
// Preserve it even if subscription check failed
plan = current_plan
} else {
// Only then update to package (for credit-only users)
plan = package
}
```
## Prevention
The code now has **multiple safeguards**:
1. Checks `user_subscriptions` table for active subscriptions
2. Checks if current plan is a subscription plan type
3. Preserves subscription plans even if checks fail
4. Only updates plan for users with no subscription
## How to Fix Stéphane Now
Run this in your browser:
```
https://soundstudiopro.com/fix_stephane_essential.php?fix=now
```
This will:
- Set plan back to `essential`
- Set track limit back to `5`
- Keep his credits (100 credits remain)
## Going Forward
When adding credits from admin panel:
- ✅ **Credits will be added** as expected
- ✅ **Subscription plan will be preserved** (won't change)
- ✅ **Track limits stay correct** based on subscription
The bug is fixed and won't happen again! 🎉