![]() 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/ |
<?php
/**
* Check Stephane's 500 Credit Purchase
* Verify payment in Stripe and fix database if needed
*/
session_start();
require_once __DIR__ . '/config/database.php';
require_once __DIR__ . '/includes/translations.php';
// Only allow admin or the user themselves
$is_admin = isset($_SESSION['is_admin']) && $_SESSION['is_admin'];
$user_id = $_SESSION['user_id'] ?? null;
$target_user_id = 5; // Stephane's user ID
if (!$is_admin && $user_id != $target_user_id) {
die("Access denied. Admin only or user themselves.");
}
$pdo = getDBConnection();
$stripe_secret = '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';
// Payment intent ID from logs
$payment_intent_id = 'pi_3SbUdyD0zXLMB4gH1P4poDyJ';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Check Stephane's 500 Credits Purchase</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 1200px;
margin: 40px auto;
padding: 20px;
background: #1a1a1a;
color: #fff;
}
.section {
background: #2a2a2a;
padding: 20px;
margin: 20px 0;
border-radius: 8px;
border: 1px solid #444;
}
.success { color: #48bb78; }
.error { color: #e53e3e; }
.warning { color: #ffc107; }
.info { color: #667eea; }
pre {
background: #1a1a1a;
padding: 15px;
border-radius: 4px;
overflow-x: auto;
font-size: 12px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 10px 0;
}
th, td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #444;
}
th {
background: #333;
font-weight: bold;
}
.btn {
display: inline-block;
padding: 10px 20px;
background: #667eea;
color: white;
text-decoration: none;
border-radius: 4px;
margin: 10px 5px;
cursor: pointer;
border: none;
}
.btn:hover {
background: #5568d3;
}
.btn-danger {
background: #e53e3e;
}
.btn-danger:hover {
background: #c53030;
}
</style>
</head>
<body>
<h1>🔍 Check Stephane's 500 Credits Purchase</h1>
<?php
// Get user info
$stmt = $pdo->prepare("SELECT id, name, email, credits, plan FROM users WHERE id = ?");
$stmt->execute([$target_user_id]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user) {
die("<div class='error'>User not found!</div>");
}
echo "<div class='section'>";
echo "<h2>👤 User Information</h2>";
echo "<table>";
echo "<tr><th>ID</th><td>{$user['id']}</td></tr>";
echo "<tr><th>Name</th><td>{$user['name']}</td></tr>";
echo "<tr><th>Email</th><td>{$user['email']}</td></tr>";
echo "<tr><th>Current Credits</th><td><strong style='font-size: 1.5rem; color: #667eea;'>{$user['credits']}</strong></td></tr>";
echo "<tr><th>Current Plan</th><td>{$user['plan']}</td></tr>";
echo "</table>";
echo "</div>";
// Check credit purchases
echo "<div class='section'>";
echo "<h2>💳 Credit Purchase Records</h2>";
$stmt = $pdo->prepare("
SELECT id, package, credits, amount, payment_intent_id, expires_at, created_at
FROM credit_purchases
WHERE user_id = ?
ORDER BY created_at DESC
");
$stmt->execute([$target_user_id]);
$purchases = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($purchases)) {
echo "<div class='warning'>⚠️ No credit purchase records found in database!</div>";
} else {
echo "<table>";
echo "<tr><th>ID</th><th>Package</th><th>Credits</th><th>Amount</th><th>Payment Intent</th><th>Expires</th><th>Created</th></tr>";
foreach ($purchases as $purchase) {
$highlight = ($purchase['payment_intent_id'] === $payment_intent_id) ? "style='background: #48bb7820;'" : "";
echo "<tr $highlight>";
echo "<td>{$purchase['id']}</td>";
echo "<td>{$purchase['package']}</td>";
echo "<td><strong>{$purchase['credits']}</strong></td>";
echo "<td>\${$purchase['amount']}</td>";
echo "<td><code>{$purchase['payment_intent_id']}</code></td>";
echo "<td>" . ($purchase['expires_at'] ? date('Y-m-d H:i:s', strtotime($purchase['expires_at'])) : 'Never') . "</td>";
echo "<td>" . date('Y-m-d H:i:s', strtotime($purchase['created_at'])) . "</td>";
echo "</tr>";
}
echo "</table>";
}
echo "</div>";
// Check Stripe payment intent
echo "<div class='section'>";
echo "<h2>💳 Stripe Payment Intent Check</h2>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.stripe.com/v1/payment_intents/{$payment_intent_id}");
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $stripe_secret]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code === 200) {
$payment_intent = json_decode($response, true);
echo "<div class='success'>✅ Payment Intent Found in Stripe</div>";
echo "<table>";
echo "<tr><th>Payment Intent ID</th><td><code>{$payment_intent['id']}</code></td></tr>";
echo "<tr><th>Status</th><td><strong style='color: " . ($payment_intent['status'] === 'succeeded' ? '#48bb78' : '#e53e3e') . ";'>{$payment_intent['status']}</strong></td></tr>";
echo "<tr><th>Amount</th><td>\$" . ($payment_intent['amount'] / 100) . "</td></tr>";
echo "<tr><th>Currency</th><td>{$payment_intent['currency']}</td></tr>";
echo "<tr><th>Created</th><td>" . date('Y-m-d H:i:s', $payment_intent['created']) . "</td></tr>";
// Check metadata
if (isset($payment_intent['metadata'])) {
echo "<tr><th colspan='2'>Metadata</th></tr>";
foreach ($payment_intent['metadata'] as $key => $value) {
echo "<tr><td style='padding-left: 30px;'>$key</td><td>$value</td></tr>";
}
}
echo "</table>";
// Check if payment succeeded
if ($payment_intent['status'] === 'succeeded') {
echo "<div class='success'>✅ Payment Succeeded in Stripe</div>";
// Check if credits were added
$expected_credits = 500;
$found_purchase = false;
foreach ($purchases as $purchase) {
if ($purchase['payment_intent_id'] === $payment_intent_id) {
$found_purchase = true;
break;
}
}
if (!$found_purchase) {
echo "<div class='error'>❌ Payment succeeded but credits NOT found in database!</div>";
echo "<div class='info'>🔧 Fix: Need to add credits manually</div>";
// Show fix button
if ($is_admin && isset($_GET['fix']) && $_GET['fix'] === 'yes') {
try {
require_once __DIR__ . '/webhooks/stripe.php';
// Extract metadata
$metadata = $payment_intent['metadata'] ?? [];
$user_id_from_meta = $metadata['user_id'] ?? null;
$cart_items_json = $metadata['cart_items'] ?? '[]';
$cart_items = json_decode($cart_items_json, true);
// Find credit package in cart - handle both full and minimal formats
$credits_to_add = 0;
$package = 'premium';
foreach ($cart_items as $item) {
// 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') {
$package = $item['package'] ?? $item['i'] ?? 'premium';
$credits_to_add = $item['credits'] ?? null;
$quantity = $item['quantity'] ?? $item['q'] ?? 1;
// If credits not provided, calculate from package
if (!$credits_to_add && $package) {
$package_credits_map = [
'starter' => 30,
'pro' => 150,
'premium' => 500
];
$credits_to_add = ($package_credits_map[$package] ?? 0) * $quantity;
}
break;
}
}
// Fallback: use total_credits from metadata if available
if ($credits_to_add == 0 && isset($metadata['total_credits'])) {
$credits_to_add = (int)$metadata['total_credits'];
}
if ($credits_to_add > 0 && $user_id_from_meta == $target_user_id) {
echo "<div class='info'>Adding {$credits_to_add} credits (package: {$package})...</div>";
// Call addCreditsToUser function
addCreditsToUser($target_user_id, $credits_to_add, $package, '30_days', $payment_intent_id);
echo "<div class='success'>✅ Credits added successfully!</div>";
echo "<script>setTimeout(function(){ location.reload(); }, 2000);</script>";
} else {
echo "<div class='error'>❌ Could not extract credit information from metadata</div>";
echo "<div class='info'>User ID from meta: " . ($user_id_from_meta ?? 'null') . "</div>";
echo "<div class='info'>Credits to add: " . ($credits_to_add ?? 'null') . "</div>";
echo "<div class='info'>Package: " . ($package ?? 'null') . "</div>";
echo "<pre>" . print_r($metadata, true) . "</pre>";
echo "<pre>Cart items: " . print_r($cart_items, true) . "</pre>";
}
} catch (Exception $e) {
echo "<div class='error'>❌ Error adding credits: " . htmlspecialchars($e->getMessage()) . "</div>";
echo "<pre>" . htmlspecialchars($e->getTraceAsString()) . "</pre>";
}
} else {
echo "<a href='?fix=yes' class='btn btn-danger' onclick=\"return confirm('Are you sure you want to add 500 credits to Stephane? This will process the payment.');\">🔧 Fix: Add 500 Credits</a>";
}
} else {
echo "<div class='success'>✅ Credits purchase record found in database</div>";
// Check if credits match
if ($user['credits'] < $expected_credits) {
echo "<div class='warning'>⚠️ User has {$user['credits']} credits, but should have at least {$expected_credits} from this purchase</div>";
echo "<div class='info'>Note: User may have spent some credits already</div>";
}
}
} else {
echo "<div class='warning'>⚠️ Payment status: {$payment_intent['status']}</div>";
if ($payment_intent['status'] === 'requires_payment_method') {
echo "<div class='info'>Payment was created but not completed</div>";
}
}
} else {
echo "<div class='error'>❌ Could not fetch payment intent from Stripe (HTTP $http_code)</div>";
echo "<pre>" . htmlspecialchars($response) . "</pre>";
}
echo "</div>";
// Check webhook logs
echo "<div class='section'>";
echo "<h2>📋 Webhook Logs</h2>";
$webhook_log_file = __DIR__ . '/logs/stripe_webhooks.log';
$webhook_logs = [];
if (file_exists($webhook_log_file)) {
$lines = file($webhook_log_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$log = json_decode($line, true);
if ($log && isset($log['event_type']) && $log['event_type'] === 'payment_intent.succeeded') {
// Check if this payment intent is in the payload
if (isset($log['payload'])) {
$payload = json_decode($log['payload'], true);
if (isset($payload['data']['object']['id']) && $payload['data']['object']['id'] === $payment_intent_id) {
$webhook_logs[] = $log;
}
}
}
}
}
if (empty($webhook_logs)) {
echo "<div class='warning'>⚠️ No webhook logs found for this payment intent</div>";
} else {
echo "<div class='success'>✅ Found " . count($webhook_logs) . " webhook log(s)</div>";
foreach ($webhook_logs as $log) {
echo "<div style='margin: 10px 0; padding: 10px; background: #1a1a1a; border-radius: 4px;'>";
echo "<strong>Timestamp:</strong> " . ($log['timestamp'] ?? 'N/A') . "<br>";
echo "<strong>Event Type:</strong> " . ($log['event_type'] ?? 'N/A') . "<br>";
echo "<strong>Event ID:</strong> " . ($log['event_id'] ?? 'N/A') . "<br>";
echo "</div>";
}
}
echo "</div>";
// Check action logs
echo "<div class='section'>";
echo "<h2>📋 Action Logs</h2>";
$action_log_file = __DIR__ . '/logs/stripe_actions.log';
$action_logs = [];
if (file_exists($action_log_file)) {
$lines = file($action_log_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$log = json_decode($line, true);
if ($log && isset($log['payment_intent_id']) && $log['payment_intent_id'] === $payment_intent_id) {
$action_logs[] = $log;
}
}
}
if (empty($action_logs)) {
echo "<div class='warning'>⚠️ No action logs found for this payment intent</div>";
} else {
echo "<div class='success'>✅ Found " . count($action_logs) . " action log(s)</div>";
foreach ($action_logs as $log) {
echo "<pre>" . json_encode($log, JSON_PRETTY_PRINT) . "</pre>";
}
}
echo "</div>";
// Check credit logs
echo "<div class='section'>";
echo "<h2>📋 Credit Addition Logs</h2>";
$credit_log_file = __DIR__ . '/logs/user_credits.log';
$credit_logs = [];
if (file_exists($credit_log_file)) {
$lines = file($credit_log_file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line) {
$log = json_decode($line, true);
if ($log && isset($log['payment_intent_id']) && $log['payment_intent_id'] === $payment_intent_id) {
$credit_logs[] = $log;
}
}
}
if (empty($credit_logs)) {
echo "<div class='warning'>⚠️ No credit addition logs found for this payment intent</div>";
} else {
echo "<div class='success'>✅ Found " . count($credit_logs) . " credit log(s)</div>";
foreach ($credit_logs as $log) {
echo "<pre>" . json_encode($log, JSON_PRETTY_PRINT) . "</pre>";
}
}
echo "</div>";
?>
<div class="section">
<h2>🔧 Actions</h2>
<a href="?" class="btn">🔄 Refresh</a>
<a href="/account_settings.php" class="btn">← Back to Account</a>
</div>
</body>
</html>