![]() 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
/**
* Quick Fix for Stephane Bergeron's Purchase Issue
* Removes wrong tracks and adds the 4 correct DRUMAHON tracks
*/
session_start();
require_once 'config/database.php';
// Check if admin
if (!isset($_SESSION['is_admin']) || !$_SESSION['is_admin']) {
die("Admin access required");
}
$pdo = getDBConnection();
$user_id = 5; // Stephane Bergeron
$payment_intent_id = 'pm_1SW5taD0zXLMB4gHVB9lJWVz'; // The confirmed transaction ID
echo "<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Quick Fix - Stephane</title></head><body>";
echo "<style>
body { font-family: Arial; padding: 20px; background: #1a1a1a; color: white; }
.success { color: #48bb78; }
.error { color: #e53e3e; }
.warning { color: #ffc107; }
.section { margin: 20px 0; padding: 15px; background: #2a2a2a; border-radius: 8px; }
button { padding: 10px 20px; background: #48bb78; color: white; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; }
</style>";
echo "<h2>🔧 Quick Fix: Stephane Bergeron's Purchases</h2>";
// Get user info
$stmt = $pdo->prepare("SELECT id, name, email FROM users WHERE id = ?");
$stmt->execute([$user_id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
echo "<div class='section'>";
echo "<p><strong>User:</strong> {$user['name']} (ID: {$user_id})</p>";
echo "<p><strong>Payment Intent:</strong> {$payment_intent_id}</p>";
echo "</div>";
// Step 1: Find current wrong purchases with this payment intent
echo "<div class='section'>";
echo "<h3>Step 1: Current Purchases with This Payment Intent</h3>";
$stmt = $pdo->prepare("
SELECT
tp.id,
tp.track_id,
mt.title as track_title,
u.name as artist_name
FROM track_purchases tp
JOIN music_tracks mt ON tp.track_id = mt.id
JOIN users u ON mt.user_id = u.id
WHERE tp.stripe_payment_intent_id = ? AND tp.user_id = ?
");
$stmt->execute([$payment_intent_id, $user_id]);
$current_purchases = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo "<p>Found <strong>" . count($current_purchases) . "</strong> purchase(s):</p>";
echo "<ul>";
foreach ($current_purchases as $p) {
echo "<li>Track ID: {$p['track_id']} - {$p['track_title']} by {$p['artist_name']}</li>";
}
echo "</ul>";
echo "</div>";
// Step 2: Find DRUMAHON artist
echo "<div class='section'>";
echo "<h3>Step 2: Finding DRUMAHON Tracks</h3>";
$stmt = $pdo->prepare("SELECT id, name FROM users WHERE name LIKE '%DRUMAHON%' OR name LIKE '%Drumahon%' LIMIT 1");
$stmt->execute();
$drumahon = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$drumahon) {
die("<p class='error'>DRUMAHON artist not found!</p>");
}
$drumahon_id = $drumahon['id'];
echo "<p class='success'>✓ Found artist: <strong>{$drumahon['name']}</strong> (ID: {$drumahon_id})</p>";
// Find the 4 tracks
$expected_tracks = [
'Raw DRUMAHON',
'Wild And Free DRUMAHON',
'DrumAhon DRUMAHON',
'Prime Orchestral DRUMAHON'
];
$found_tracks = [];
foreach ($expected_tracks as $title) {
// Try different search patterns
$keywords = explode(' ', $title);
$keyword = $keywords[0]; // "Raw", "Wild", "DrumAhon", "Prime"
$stmt = $pdo->prepare("
SELECT id, title, price
FROM music_tracks
WHERE user_id = ?
AND (title LIKE ? OR title LIKE ?)
AND status = 'complete'
ORDER BY created_at DESC
LIMIT 1
");
$stmt->execute([$drumahon_id, '%' . $keyword . '%', '%' . str_replace('DRUMAHON', '', $title) . '%']);
$track = $stmt->fetch(PDO::FETCH_ASSOC);
if ($track) {
$found_tracks[] = $track;
echo "<p class='success'>✓ Found: {$track['title']} (ID: {$track['id']})</p>";
} else {
echo "<p class='error'>✗ Not found: {$title}</p>";
}
}
echo "<p><strong>Found " . count($found_tracks) . " of 4 expected tracks</p>";
echo "</div>";
// Step 3: Show what will be fixed
echo "<div class='section'>";
echo "<h3>Step 3: What Will Be Fixed</h3>";
if (!empty($current_purchases)) {
echo "<p class='warning'><strong>Will REMOVE " . count($current_purchases) . " wrong purchase(s):</strong></p>";
echo "<ul>";
foreach ($current_purchases as $p) {
echo "<li>Purchase ID: {$p['id']} - Track: {$p['track_title']}</li>";
}
echo "</ul>";
}
if (!empty($found_tracks)) {
echo "<p class='success'><strong>Will ADD " . count($found_tracks) . " correct purchase(s):</strong></p>";
echo "<ul>";
foreach ($found_tracks as $t) {
echo "<li>Track: {$t['title']} (ID: {$t['id']}) - \${$t['price']}</li>";
}
echo "</ul>";
}
echo "</div>";
// Step 4: Execute fix
if (isset($_POST['execute_fix'])) {
echo "<div class='section'>";
echo "<h3>Step 4: Executing Fix...</h3>";
$fixed = [];
$failed = [];
// Remove wrong purchases
foreach ($current_purchases as $purchase) {
try {
$pdo->beginTransaction();
// Delete from track_purchases
$stmt = $pdo->prepare("DELETE FROM track_purchases WHERE id = ?");
$stmt->execute([$purchase['id']]);
// Delete from user_library
$stmt = $pdo->prepare("DELETE FROM user_library WHERE user_id = ? AND track_id = ?");
$stmt->execute([$user_id, $purchase['track_id']]);
// Delete from sales
$stmt = $pdo->prepare("DELETE FROM sales WHERE buyer_id = ? AND track_id = ?");
$stmt->execute([$user_id, $purchase['track_id']]);
$pdo->commit();
$fixed[] = "Removed: {$purchase['track_title']}";
} catch (Exception $e) {
$pdo->rollBack();
$failed[] = "Failed to remove {$purchase['track_title']}: " . $e->getMessage();
}
}
// Add correct purchases
foreach ($found_tracks as $track) {
try {
// Check if already exists
$stmt = $pdo->prepare("SELECT id FROM track_purchases WHERE user_id = ? AND track_id = ?");
$stmt->execute([$user_id, $track['id']]);
if ($stmt->fetch()) {
$failed[] = "Track {$track['title']} already purchased";
continue;
}
$pdo->beginTransaction();
// Get artist info for revenue
$stmt = $pdo->prepare("SELECT plan FROM users WHERE id = ?");
$stmt->execute([$drumahon_id]);
$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 : $drumahon_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['id'],
$user_id,
$drumahon_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['id'],
$track['price'],
$payment_intent_id
]);
// Add to library
$stmt = $pdo->prepare("
INSERT IGNORE INTO user_library (user_id, track_id, purchase_date)
VALUES (?, ?, NOW())
");
$stmt->execute([$user_id, $track['id']]);
$pdo->commit();
$fixed[] = "Added: {$track['title']}";
} catch (Exception $e) {
if ($pdo->inTransaction()) {
$pdo->rollBack();
}
$failed[] = "Failed to add {$track['title']}: " . $e->getMessage();
}
}
// Show results
if (!empty($fixed)) {
echo "<p class='success'><strong>✅ Successfully Fixed:</strong></p>";
echo "<ul>";
foreach ($fixed as $f) {
echo "<li>{$f}</li>";
}
echo "</ul>";
}
if (!empty($failed)) {
echo "<p class='error'><strong>❌ Failed:</strong></p>";
echo "<ul>";
foreach ($failed as $f) {
echo "<li>{$f}</li>";
}
echo "</ul>";
}
echo "<p style='margin-top: 20px;'><a href='/account_settings.php?tab=purchases' style='color: #667eea;'>View Purchases</a></p>";
echo "</div>";
} else {
// Show fix button
echo "<div class='section'>";
echo "<form method='POST'>";
echo "<button type='submit' name='execute_fix' value='1'>🔧 Execute Fix Now</button>";
echo "</form>";
echo "<p class='warning'>⚠️ This will remove wrong purchases and add correct ones. Make sure you've reviewed the changes above.</p>";
echo "</div>";
}
echo "<hr>";
echo "<p><a href='/admin.php' style='color: #667eea;'>← Back to Admin</a></p>";
echo "</body></html>";
?>