![]() 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/ |
<?php
/**
* Fix Stephane Bergeron's Missing 3 Track Purchases - November 29, 2025
*
* From cart_payment_detailed.log:
* - Payment Intent: pi_3SYv2BD0zXLMB4gH0nOEitol
* - User ID: 5 (Stephane Bergeron)
* - Tracks: 236, 226, 197
*
* Root cause: Stripe SDK missing from vendor/stripe/ directory
* Webhooks were logged but not processed.
*/
session_start();
require_once __DIR__ . '/config/database.php';
// Check if admin
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
die("Admin access required. Please log in as admin first.");
}
$pdo = getDBConnection();
// Known data from logs
$user_id = 5;
$payment_intent_id = 'pi_3SYv2BD0zXLMB4gH0nOEitol';
$tracks_to_add = [
['track_id' => 236, 'title' => 'Hey OHA', 'artist' => 'DRUMAHON'],
['track_id' => 226, 'title' => 'Elle débarque', 'artist' => 'Jabëla'],
['track_id' => 197, 'title' => 'THE CIRCLE THAT BREATHES', 'artist' => 'SoundStudioPro']
];
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Fix Stephane's Nov 29 Purchases</title>";
echo "<style>
body { font-family: Arial, sans-serif; padding: 20px; background: #1a1a1a; color: #e0e0e0; }
h1, h2, h3 { color: #667eea; }
table { border-collapse: collapse; width: 100%; margin: 20px 0; background: #2a2a2a; }
th, td { border: 1px solid #444; padding: 12px; text-align: left; }
th { background: #667eea; color: white; }
.success { color: #48bb78; font-weight: bold; }
.error { color: #e53e3e; font-weight: bold; }
.warning { color: #ffc107; font-weight: bold; }
.info { color: #667eea; }
.section { margin: 30px 0; padding: 25px; background: #2a2a2a; border-radius: 8px; }
.btn { display: inline-block; padding: 12px 24px; background: #667eea; color: white; text-decoration: none; border-radius: 5px; margin: 10px 5px; border: none; cursor: pointer; font-size: 16px; }
.btn:hover { background: #5a67d8; }
.btn-danger { background: #e53e3e; }
.btn-danger:hover { background: #c53030; }
</style></head><body>";
echo "<h1>🔧 Fix Stephane Bergeron's Missing Purchases</h1>";
echo "<p class='info'>November 29, 2025 - 3 Tracks</p>";
// Get user info
$stmt = $pdo->prepare("SELECT id, name, email FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user) {
die("<p class='error'>User ID {$user_id} not found!</p>");
}
echo "<div class='section'>";
echo "<h2>👤 User Information</h2>";
echo "<p><strong>Name:</strong> {$user['name']}</p>";
echo "<p><strong>Email:</strong> {$user['email']}</p>";
echo "<p><strong>User ID:</strong> {$user_id}</p>";
echo "<p><strong>Payment Intent:</strong> <code>{$payment_intent_id}</code></p>";
echo "</div>";
// Check current status of each track
echo "<div class='section'>";
echo "<h2>📊 Track Status Check</h2>";
echo "<table>";
echo "<tr><th>Track ID</th><th>Title</th><th>Artist</th><th>Price</th><th>Already Purchased?</th><th>In Library?</th></tr>";
$tracks_to_fix = [];
foreach ($tracks_to_add as $track_info) {
$track_id = $track_info['track_id'];
// Get track details from database
$stmt = $pdo->prepare("SELECT id, title, price, user_id as artist_id, status FROM music_tracks WHERE id = ?");
$stmt->execute([$track_id]);
$track = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$track) {
echo "<tr><td>{$track_id}</td><td colspan='5' class='error'>Track not found in database!</td></tr>";
continue;
}
// Check if already purchased
$stmt = $pdo->prepare("SELECT id FROM track_purchases WHERE user_id = ? AND track_id = ?");
$stmt->execute([$user_id, $track_id]);
$existing_purchase = $stmt->fetch();
// Check if in library
$stmt = $pdo->prepare("SELECT id FROM user_library WHERE user_id = ? AND track_id = ?");
$stmt->execute([$user_id, $track_id]);
$in_library = $stmt->fetch();
$purchase_status = $existing_purchase ? "<span class='success'>✓ Yes</span>" : "<span class='error'>✗ No</span>";
$library_status = $in_library ? "<span class='success'>✓ Yes</span>" : "<span class='error'>✗ No</span>";
echo "<tr>";
echo "<td>{$track_id}</td>";
echo "<td>" . htmlspecialchars($track['title']) . "</td>";
echo "<td>{$track_info['artist']}</td>";
echo "<td>\$" . number_format($track['price'], 2) . "</td>";
echo "<td>{$purchase_status}</td>";
echo "<td>{$library_status}</td>";
echo "</tr>";
if (!$existing_purchase) {
$tracks_to_fix[] = [
'track_id' => $track_id,
'title' => $track['title'],
'price' => $track['price'],
'artist_id' => $track['artist_id'],
'in_library' => (bool)$in_library
];
}
}
echo "</table>";
echo "</div>";
// Action section
$action = $_GET['action'] ?? '';
if (empty($tracks_to_fix)) {
echo "<div class='section'>";
echo "<p class='success'>✓ All tracks are already purchased! No fix needed.</p>";
echo "<p><a href='account_settings.php?tab=purchases' class='btn'>View Purchases</a></p>";
echo "</div>";
} elseif ($action === 'fix') {
// Perform the fix
echo "<div class='section'>";
echo "<h2>🔧 Fixing Missing Purchases...</h2>";
$fixed = [];
$errors = [];
foreach ($tracks_to_fix as $track) {
try {
$pdo->beginTransaction();
// Determine revenue recipient
$artist_stmt = $pdo->prepare("SELECT plan FROM users WHERE id = ?");
$artist_stmt->execute([$track['artist_id']]);
$artist = $artist_stmt->fetch(PDO::FETCH_ASSOC);
$is_free_user_track = ($artist && strtolower($artist['plan']) === 'free');
$revenue_recipient = $is_free_user_track ? 'platform' : 'artist';
$recipient_id = $is_free_user_track ? 1 : $track['artist_id'];
// 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['track_id'],
$user_id,
$track['artist_id'],
$track['price'],
$revenue_recipient,
$recipient_id,
$is_free_user_track ? 1 : 0
]);
// Record purchase
$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, 'stripe', ?, NOW())
");
$stmt->execute([$user_id, $track['track_id'], $track['price'], $payment_intent_id]);
$purchase_id = $pdo->lastInsertId();
// Add to library if not already there
if (!$track['in_library']) {
$stmt = $pdo->prepare("INSERT IGNORE INTO user_library (user_id, track_id, purchase_date) VALUES (?, ?, NOW())");
$stmt->execute([$user_id, $track['track_id']]);
}
$pdo->commit();
$fixed[] = [
'track_id' => $track['track_id'],
'title' => $track['title'],
'purchase_id' => $purchase_id
];
} catch (Exception $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
$errors[] = [
'track_id' => $track['track_id'],
'title' => $track['title'],
'error' => $e->getMessage()
];
}
}
if (!empty($fixed)) {
echo "<p class='success'>✓ Successfully fixed " . count($fixed) . " purchase(s):</p>";
echo "<table>";
echo "<tr><th>Purchase ID</th><th>Track ID</th><th>Title</th></tr>";
foreach ($fixed as $f) {
echo "<tr><td>{$f['purchase_id']}</td><td>{$f['track_id']}</td><td>" . htmlspecialchars($f['title']) . "</td></tr>";
}
echo "</table>";
}
if (!empty($errors)) {
echo "<p class='error'>✗ Failed to fix " . count($errors) . " purchase(s):</p>";
echo "<table>";
echo "<tr><th>Track ID</th><th>Title</th><th>Error</th></tr>";
foreach ($errors as $e) {
echo "<tr><td>{$e['track_id']}</td><td>" . htmlspecialchars($e['title']) . "</td><td>{$e['error']}</td></tr>";
}
echo "</table>";
}
// Log the fix
$log_entry = [
'timestamp' => date('Y-m-d H:i:s'),
'action' => 'manual_fix_stephane_nov29',
'user_id' => $user_id,
'payment_intent_id' => $payment_intent_id,
'tracks_fixed' => $fixed,
'errors' => $errors,
'fixed_by' => $_SESSION['user_id'] ?? 'unknown'
];
$log_file = __DIR__ . '/logs/manual_purchase_fixes.log';
file_put_contents($log_file, json_encode($log_entry) . "\n", FILE_APPEND | LOCK_EX);
echo "<p><a href='account_settings.php?tab=purchases' class='btn'>View Purchases</a></p>";
echo "</div>";
} else {
// Show fix button
echo "<div class='section'>";
echo "<h2>⚠️ Action Required</h2>";
echo "<p class='warning'>Found <strong>" . count($tracks_to_fix) . "</strong> missing purchase(s) to fix:</p>";
echo "<ul>";
foreach ($tracks_to_fix as $t) {
echo "<li><strong>Track #{$t['track_id']}</strong>: " . htmlspecialchars($t['title']) . " (\${$t['price']})</li>";
}
echo "</ul>";
echo "<p>Click the button below to add these purchases to Stephane's account:</p>";
echo "<a href='?action=fix' class='btn btn-danger'>🔧 Fix Missing Purchases Now</a>";
echo "</div>";
}
echo "<hr>";
echo "<p><a href='admin.php?tab=purchases' style='color: #667eea;'>← Back to Admin</a> | ";
echo "<a href='investigate_stephane_10_tracks.php' style='color: #667eea;'>Full Investigation</a></p>";
echo "</body></html>";
?>