![]() 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/admin_includes/ |
<?php
/**
* Purchase Validation & Prevention Tools
* Admin interface for monitoring and managing purchase validation
*/
$pdo = getDBConnection();
?>
<div class="admin-tab-content">
<h2>🔍 Purchase Validation & Prevention</h2>
<p class="admin-description">Monitor purchase validation, reconcile discrepancies, and manage the prevention system.</p>
<div class="admin-section">
<h3>📊 Quick Status</h3>
<?php
// Check if cart_snapshots table exists
$table_exists = false;
try {
$stmt = $pdo->query("SHOW TABLES LIKE 'cart_snapshots'");
$table_exists = $stmt->rowCount() > 0;
} catch (Exception $e) {
$table_exists = false;
}
// Count recent validation failures
$validation_failures = 0;
$validation_log_file = __DIR__ . '/../logs/purchase_validation_failures.log';
if (file_exists($validation_log_file)) {
$lines = file($validation_log_file);
foreach (array_slice($lines, -100) as $line) {
$log = json_decode($line, true);
if ($log && isset($log['timestamp'])) {
$log_time = strtotime($log['timestamp']);
if ($log_time > (time() - 86400)) { // Last 24 hours
$validation_failures++;
}
}
}
}
// Count recent alerts
$recent_alerts = 0;
$alert_log_file = __DIR__ . '/../logs/purchase_failure_alerts.log';
if (file_exists($alert_log_file)) {
$lines = file($alert_log_file);
foreach (array_slice($lines, -100) as $line) {
$log = json_decode($line, true);
if ($log && isset($log['timestamp'])) {
$log_time = strtotime($log['timestamp']);
if ($log_time > (time() - 86400)) { // Last 24 hours
$recent_alerts++;
}
}
}
}
?>
<div class="status-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; margin: 20px 0;">
<div class="status-card" style="background: <?= $table_exists ? '#2d5016' : '#5a1a1a'; ?>; padding: 20px; border-radius: 8px;">
<h4><?= $table_exists ? '✅' : '❌'; ?> Cart Snapshots Table</h4>
<p><?= $table_exists ? 'Active' : 'Not Created'; ?></p>
<?php if (!$table_exists): ?>
<a href="/create_cart_snapshots_table.php" class="btn" style="display: inline-block; margin-top: 10px; padding: 8px 16px; background: #667eea; color: white; text-decoration: none; border-radius: 5px;">Create Table</a>
<?php endif; ?>
</div>
<div class="status-card" style="background: <?= $validation_failures > 0 ? '#5a1a1a' : '#2d5016'; ?>; padding: 20px; border-radius: 8px;">
<h4>⚠️ Validation Failures (24h)</h4>
<p style="font-size: 24px; font-weight: bold;"><?= $validation_failures; ?></p>
</div>
<div class="status-card" style="background: <?= $recent_alerts > 0 ? '#5a1a1a' : '#2d5016'; ?>; padding: 20px; border-radius: 8px;">
<h4>🚨 Active Alerts (24h)</h4>
<p style="font-size: 24px; font-weight: bold;"><?= $recent_alerts; ?></p>
</div>
</div>
</div>
<div class="admin-section" style="margin-top: 30px;">
<h3>🛠️ Tools</h3>
<div class="tools-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; margin: 20px 0;">
<div class="tool-card" style="background: #2a2a2a; padding: 20px; border-radius: 8px; border: 1px solid #444;">
<h4>🔍 Monitor Purchase Failures</h4>
<p>View active alerts and recent purchase failures</p>
<a href="/monitor_purchase_failures.php" class="btn" style="display: inline-block; margin-top: 10px; padding: 8px 16px; background: #667eea; color: white; text-decoration: none; border-radius: 5px;">Open Monitor</a>
</div>
<div class="tool-card" style="background: #2a2a2a; padding: 20px; border-radius: 8px; border: 1px solid #444;">
<h4>🔄 Reconcile Purchases</h4>
<p>Compare Stripe payments with database purchases</p>
<a href="/reconcile_stripe_purchases.php" class="btn" style="display: inline-block; margin-top: 10px; padding: 8px 16px; background: #667eea; color: white; text-decoration: none; border-radius: 5px;">Run Reconciliation</a>
</div>
<div class="tool-card" style="background: #2a2a2a; padding: 20px; border-radius: 8px; border: 1px solid #444;">
<h4>🔧 Fix Purchase Discrepancies</h4>
<p>Fix missing or wrong purchases for specific payment intents</p>
<a href="/fix_purchase_discrepancies.php" class="btn" style="display: inline-block; margin-top: 10px; padding: 8px 16px; background: #48bb78; color: white; text-decoration: none; border-radius: 5px;">Fix Issues</a>
</div>
<div class="tool-card" style="background: #2a2a2a; padding: 20px; border-radius: 8px; border: 1px solid #444;">
<h4>⚙️ Run Auto Reconciliation</h4>
<p>Manually trigger automatic reconciliation check</p>
<a href="/auto_reconcile_purchases.php" target="_blank" class="btn" style="display: inline-block; margin-top: 10px; padding: 8px 16px; background: #667eea; color: white; text-decoration: none; border-radius: 5px;">Run Now</a>
</div>
</div>
</div>
<div class="admin-section" style="margin-top: 30px;">
<h3>📋 Recent Validation Failures</h3>
<?php
if (file_exists($validation_log_file)) {
$lines = file($validation_log_file);
$recent_failures = [];
foreach (array_slice($lines, -20) as $line) {
$log = json_decode($line, true);
if ($log && isset($log['timestamp'])) {
$log_time = strtotime($log['timestamp']);
if ($log_time > (time() - 86400)) { // Last 24 hours
$recent_failures[] = $log;
}
}
}
if (!empty($recent_failures)) {
echo "<table style='width: 100%; border-collapse: collapse; margin-top: 15px;'>";
echo "<tr style='background: #333;'>";
echo "<th style='padding: 10px; text-align: left; border: 1px solid #444;'>Time</th>";
echo "<th style='padding: 10px; text-align: left; border: 1px solid #444;'>Payment Intent</th>";
echo "<th style='padding: 10px; text-align: left; border: 1px solid #444;'>User ID</th>";
echo "<th style='padding: 10px; text-align: left; border: 1px solid #444;'>Issues</th>";
echo "<th style='padding: 10px; text-align: left; border: 1px solid #444;'>Action</th>";
echo "</tr>";
foreach (array_reverse($recent_failures) as $failure) {
echo "<tr style='background: #2a2a2a;'>";
echo "<td style='padding: 10px; border: 1px solid #444;'>" . htmlspecialchars($failure['timestamp'] ?? 'N/A') . "</td>";
echo "<td style='padding: 10px; border: 1px solid #444;'><code>" . htmlspecialchars(substr($failure['payment_intent_id'] ?? 'N/A', 0, 30)) . "...</code></td>";
echo "<td style='padding: 10px; border: 1px solid #444;'>" . htmlspecialchars($failure['user_id'] ?? 'N/A') . "</td>";
echo "<td style='padding: 10px; border: 1px solid #444;'>" . htmlspecialchars(implode(', ', $failure['issues'] ?? [])) . "</td>";
echo "<td style='padding: 10px; border: 1px solid #444;'><a href='/fix_purchase_discrepancies.php?payment_intent_id=" . urlencode($failure['payment_intent_id'] ?? '') . "' style='color: #667eea;'>Fix</a></td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<p style='color: #48bb78; margin-top: 15px;'>✅ No validation failures in the last 24 hours</p>";
}
} else {
echo "<p style='color: #ffc107; margin-top: 15px;'>⚠️ Validation log file not found. System may not be fully set up.</p>";
}
?>
</div>
<div class="admin-section" style="margin-top: 30px;">
<h3>📖 Documentation</h3>
<p>For detailed information about the purchase prevention system, see:</p>
<ul style="margin: 15px 0; padding-left: 30px;">
<li><a href="/PURCHASE_PREVENTION_SYSTEM.md" target="_blank" style="color: #667eea;">Purchase Prevention System Documentation</a></li>
<li>All tools are accessible from the links above</li>
<li>Set up cron job for automatic hourly reconciliation</li>
</ul>
</div>
</div>
<style>
.admin-section {
background: #2a2a2a;
padding: 20px;
border-radius: 8px;
margin-bottom: 20px;
}
.admin-section h3 {
margin-top: 0;
color: #fff;
border-bottom: 2px solid #667eea;
padding-bottom: 10px;
}
.btn:hover {
opacity: 0.9;
}
</style>