![]() 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/.cursor-server/data/User/History/77f26ec2/ |
<?php
/**
* User Invoices Page
* Display Stripe invoices for the logged-in user
*/
session_start();
require_once 'config/database.php';
if (!isset($_SESSION['user_id'])) {
header('Location: /auth/login.php?redirect=' . urlencode('/invoices.php'));
exit;
}
$pdo = getDBConnection();
$stripe_secret = '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';
// Get user info
$stmt = $pdo->prepare("SELECT id, name, email, stripe_customer_id FROM users WHERE id = ?");
$stmt->execute([$_SESSION['user_id']]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
$invoices = [];
$error_message = null;
if (!empty($user['stripe_customer_id'])) {
try {
// Fetch invoices from Stripe
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.stripe.com/v1/invoices?customer=' . urlencode($user['stripe_customer_id']) . '&limit=100');
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) {
$data = json_decode($response, true);
$invoices = $data['data'] ?? [];
} else {
$error_message = "Unable to fetch invoices. Please try again later.";
error_log("Stripe invoices API error: HTTP {$http_code} - {$response}");
}
} catch (Exception $e) {
$error_message = "Error loading invoices: " . htmlspecialchars($e->getMessage());
error_log("Invoice fetch error: " . $e->getMessage());
}
} else {
$error_message = "No payment history found. Invoices will appear here after your first subscription or purchase.";
}
$page_title = 'My Invoices';
include 'includes/header.php';
?>
<style>
.invoices-page {
max-width: 1000px;
margin: 60px auto;
padding: 40px 20px;
}
.invoices-page h1 {
color: white;
font-size: 3.5rem;
font-weight: 800;
margin-bottom: 50px;
text-align: center;
}
.invoices-container {
background: rgba(255, 255, 255, 0.05);
border-radius: 20px;
padding: 30px;
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
}
.invoice-item {
background: rgba(255, 255, 255, 0.05);
border-radius: 12px;
padding: 20px;
margin-bottom: 15px;
border: 1px solid rgba(255, 255, 255, 0.1);
display: flex;
justify-content: space-between;
align-items: center;
transition: all 0.3s ease;
}
.invoice-item:hover {
background: rgba(255, 255, 255, 0.08);
transform: translateY(-2px);
}
.invoice-info {
flex: 1;
}
.invoice-number {
font-weight: 600;
color: white;
font-size: 1.1rem;
margin-bottom: 5px;
}
.invoice-date {
color: rgba(255, 255, 255, 0.7);
font-size: 0.9rem;
margin-bottom: 5px;
}
.invoice-description {
color: rgba(255, 255, 255, 0.8);
font-size: 0.95rem;
margin-top: 8px;
}
.invoice-amount {
font-size: 1.5rem;
font-weight: 700;
color: #48bb78;
margin-right: 20px;
}
.invoice-status {
display: inline-block;
padding: 4px 12px;
border-radius: 20px;
font-size: 0.85rem;
font-weight: 600;
margin-top: 5px;
}
.status-paid {
background: rgba(72, 187, 120, 0.2);
color: #48bb78;
}
.status-open {
background: rgba(255, 193, 7, 0.2);
color: #ffc107;
}
.status-draft {
background: rgba(255, 255, 255, 0.1);
color: rgba(255, 255, 255, 0.7);
}
.status-void {
background: rgba(220, 38, 38, 0.2);
color: #dc2626;
}
.status-uncollectible {
background: rgba(220, 38, 38, 0.2);
color: #dc2626;
}
.invoice-actions {
display: flex;
gap: 10px;
align-items: center;
}
.btn-download {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
border: none;
padding: 10px 20px;
border-radius: 8px;
cursor: pointer;
text-decoration: none;
font-weight: 600;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
gap: 8px;
}
.btn-download:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}
.empty-state {
text-align: center;
padding: 60px 20px;
color: rgba(255, 255, 255, 0.7);
}
.empty-state i {
font-size: 4rem;
margin-bottom: 20px;
opacity: 0.5;
}
.error-message {
background: rgba(220, 38, 38, 0.2);
border: 1px solid rgba(220, 38, 38, 0.5);
color: #fca5a5;
padding: 15px;
border-radius: 8px;
margin-bottom: 20px;
}
</style>
<div class="invoices-page">
<h1>My Invoices</h1>
<div class="invoices-container">
<?php if ($error_message): ?>
<div class="error-message">
<i class="fas fa-exclamation-circle"></i> <?= htmlspecialchars($error_message) ?>
</div>
<?php endif; ?>
<?php if (empty($invoices) && !$error_message): ?>
<div class="empty-state">
<i class="fas fa-file-invoice"></i>
<h3>No Invoices Yet</h3>
<p>Your invoices will appear here after you make a purchase or subscribe to a plan.</p>
</div>
<?php elseif (!empty($invoices)): ?>
<?php foreach ($invoices as $invoice): ?>
<div class="invoice-item">
<div class="invoice-info">
<div class="invoice-number">
Invoice #<?= htmlspecialchars($invoice['number'] ?? $invoice['id']) ?>
</div>
<div class="invoice-date">
<?= date('F j, Y', $invoice['created']) ?>
</div>
<?php if (!empty($invoice['description'])): ?>
<div class="invoice-description">
<?= htmlspecialchars($invoice['description']) ?>
</div>
<?php elseif (!empty($invoice['lines']['data'][0]['description'])): ?>
<div class="invoice-description">
<?= htmlspecialchars($invoice['lines']['data'][0]['description']) ?>
</div>
<?php else: ?>
<div class="invoice-description">
<?php
if (!empty($invoice['subscription'])) {
echo "Subscription Payment";
} else {
echo "Payment";
}
?>
</div>
<?php endif; ?>
<span class="invoice-status status-<?= htmlspecialchars($invoice['status']) ?>">
<?= ucfirst($invoice['status']) ?>
</span>
</div>
<div class="invoice-actions">
<div class="invoice-amount">
$<?= number_format(($invoice['amount_paid'] ?? $invoice['amount_due'] ?? 0) / 100, 2) ?>
</div>
<?php if (!empty($invoice['invoice_pdf'])): ?>
<a href="<?= htmlspecialchars($invoice['invoice_pdf']) ?>" target="_blank" class="btn-download">
<i class="fas fa-download"></i>
Download PDF
</a>
<?php elseif (!empty($invoice['hosted_invoice_url'])): ?>
<a href="<?= htmlspecialchars($invoice['hosted_invoice_url']) ?>" target="_blank" class="btn-download">
<i class="fas fa-external-link-alt"></i>
View Invoice
</a>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?php include 'includes/footer.php'; ?>