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/STEPHANE_500_CREDITS_ISSUE_FIX.md
# Stephane's 500 Credits Purchase Issue - Root Cause & Fix

**Date:** 2025-12-19  
**User:** Stephane (Taz) - User ID: 5, Email: stevenberg450@gmail.com  
**Issue:** Purchased 500 credits (Premium package) for $129.00 but credits were not added to account

---

## What Happened

1. **Payment Intent Created:** `pi_3SbUdyD0zXLMB4gH1P4poDyJ` on 2025-12-06 23:12:02
2. **Payment Succeeded:** Status confirmed in Stripe on 2025-12-06 23:12:16
3. **Webhook Received:** `payment_intent.succeeded` event received
4. **Credits NOT Added:** Credits were not added to user's account

---

## Root Cause

The webhook handler (`webhooks/stripe.php`) in `processMixedCartPayment()` function was **not handling the minimal format** for credit items in cart metadata.

### The Problem

Stripe metadata used **minimal format** for cart items:
```json
{
  "t": "credit",    // type (minimal)
  "i": "premium",   // package/ID (minimal)
  "q": 1,           // quantity (minimal)
  "a": 12900        // amount (minimal)
}
```

But the code only checked for **full format**:
```php
if ($item['type'] === 'credit') {
    if (isset($item['credits']) && isset($item['package'])) {
        // Process credits
    }
}
```

This meant:
- ✅ Webhook was received
- ✅ Payment was confirmed
- ❌ Credits were NOT processed (missing `credits` and `package` fields in minimal format)
- ❌ Error was logged but credits were never added

---

## The Fix

### 1. Updated Webhook Handler (`webhooks/stripe.php`)

**Changed:** Credit processing now handles both full and minimal formats:

```php
// Handle both full format (type, credits, package) and minimal format (t, i, q, a)
$item_type = $item['type'] ?? $item['t'] ?? null;

if ($item_type === 'credit') {
    // Handle both formats
    $package = $item['package'] ?? $item['i'] ?? null;
    $credits = $item['credits'] ?? null;
    $quantity = $item['quantity'] ?? $item['q'] ?? 1;
    
    // If credits not provided, calculate from package
    if (!$credits && $package) {
        $package_credits_map = [
            'starter' => 30,
            'pro' => 150,
            'premium' => 500
        ];
        $credits = ($package_credits_map[$package] ?? 0) * $quantity;
    }
    
    if ($credits && $credits > 0 && $package) {
        addCreditsToUser($user_id, $credits, $package, $subscription_period, $paymentIntent->id);
    }
}
```

**Benefits:**
- ✅ Handles both full format (`type`, `credits`, `package`) and minimal format (`t`, `i`, `q`, `a`)
- ✅ Automatically calculates credits from package name if not provided
- ✅ Better error logging with detailed information

### 2. Created Diagnostic Script (`check_stephane_500_credits.php`)

**Purpose:** Verify payment in Stripe and fix database if needed

**Features:**
- ✅ Checks user's current credits in database
- ✅ Verifies payment intent in Stripe
- ✅ Checks webhook logs
- ✅ Checks action logs
- ✅ Checks credit purchase records
- ✅ **One-click fix button** to add missing credits (admin only)

**Usage:**
1. Visit: `https://soundstudiopro.com/check_stephane_500_credits.php`
2. Review all information
3. Click "🔧 Fix: Add 500 Credits" button (admin only)
4. Credits will be added immediately

---

## Verification Steps

### Check Payment in Stripe:
```bash
# Payment Intent ID: pi_3SbUdyD0zXLMB4gH1P4poDyJ
# Status: succeeded
# Amount: $129.00
# User ID: 5
# Package: premium
# Credits: 500
```

### Check Database:
```sql
SELECT * FROM credit_purchases WHERE payment_intent_id = 'pi_3SbUdyD0zXLMB4gH1P4poDyJ';
SELECT credits FROM users WHERE id = 5;
```

### Check Logs:
- `logs/stripe_webhooks.log` - Webhook received ✅
- `logs/stripe_actions.log` - Action processed (check for errors)
- `logs/mixed_cart_payments.log` - Cart processing
- `logs/user_credits.log` - Credit addition (should show success)

---

## Immediate Action Required

1. **Run Diagnostic Script:**
   - Visit: `https://soundstudiopro.com/check_stephane_500_credits.php`
   - Click "🔧 Fix: Add 500 Credits" button
   - Verify credits are added

2. **Verify Fix:**
   - Check user's credits in database
   - Confirm credit purchase record exists
   - Test that future purchases work correctly

---

## Prevention

The fix ensures that:
- ✅ **Future purchases** will work correctly (both formats supported)
- ✅ **Better error logging** helps identify issues faster
- ✅ **Automatic credit calculation** from package name prevents missing credits

---

## Related Files

- `webhooks/stripe.php` - Webhook handler (FIXED)
- `check_stephane_500_credits.php` - Diagnostic script (NEW)
- `logs/stripe_webhooks.log` - Webhook logs
- `logs/mixed_cart_payments.log` - Cart processing logs

---

## Status

- ✅ **Root cause identified**
- ✅ **Fix implemented**
- ✅ **Diagnostic script created**
- ⏳ **Action required:** Run diagnostic script to add missing credits

---

**Next Steps:**
1. Admin should visit the diagnostic script
2. Click "Fix" button to add 500 credits
3. Verify credits are added to user account
4. Confirm credit purchase record is created

CasperSecurity Mini