![]() 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';
require_once __DIR__ . '/includes/translations.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 = t('invoice.fetch_error');
error_log("Stripe invoices API error: HTTP {$http_code} - {$response}");
}
} catch (Exception $e) {
$error_message = t('invoice.load_error') . " " . htmlspecialchars($e->getMessage());
error_log("Invoice fetch error: " . $e->getMessage());
}
} else {
$error_message = t('invoice.no_payment_history');
}
$page_title = t('invoice.page_title');
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;
}
.empty-state h3 {
color: rgba(255, 255, 255, 0.9);
font-size: 1.8rem;
margin-bottom: 15px;
font-weight: 600;
}
.empty-state p {
color: rgba(255, 255, 255, 0.7);
font-size: 1.1rem;
line-height: 1.6;
}
@media (max-width: 768px) {
.invoices-page {
margin: 20px auto;
padding: 20px 15px;
}
.invoices-page h1 {
font-size: 2rem;
margin-bottom: 30px;
}
.invoices-container {
padding: 20px 15px;
border-radius: 16px;
}
.invoice-item {
flex-direction: column;
align-items: flex-start;
padding: 18px 15px;
gap: 15px;
}
.invoice-info {
width: 100%;
}
.invoice-number {
font-size: 1rem;
}
.invoice-date {
font-size: 0.85rem;
}
.invoice-description {
font-size: 0.9rem;
margin-top: 10px;
}
.invoice-amount {
font-size: 1.4rem;
margin-right: 0;
margin-bottom: 12px;
text-align: center;
width: 100%;
padding: 8px 0;
}
.invoice-actions {
width: 100%;
flex-direction: column;
align-items: stretch;
gap: 12px;
}
.btn-download {
width: 100%;
justify-content: center;
padding: 12px 20px;
font-size: 1rem;
}
.empty-state {
padding: 40px 15px;
}
.empty-state i {
font-size: 3rem;
margin-bottom: 15px;
}
.empty-state h3 {
font-size: 1.5rem;
}
.empty-state p {
font-size: 1rem;
}
.error-message {
padding: 12px 15px;
font-size: 0.95rem;
}
}
@media (max-width: 480px) {
.invoices-page {
padding: 15px 10px;
}
.invoices-page h1 {
font-size: 1.75rem;
margin-bottom: 20px;
}
.invoices-container {
padding: 15px 10px;
}
.invoice-item {
padding: 15px 12px;
}
.invoice-number {
font-size: 0.95rem;
}
.invoice-date {
font-size: 0.8rem;
}
.invoice-description {
font-size: 0.85rem;
}
.invoice-amount {
font-size: 1.3rem;
}
.invoice-status {
font-size: 0.8rem;
padding: 3px 10px;
}
.btn-download {
padding: 10px 16px;
font-size: 0.95rem;
}
.empty-state i {
font-size: 2.5rem;
}
.empty-state h3 {
font-size: 1.3rem;
}
.empty-state p {
font-size: 0.95rem;
}
}
</style>
<div class="invoices-page">
<h1><?= t('invoice.page_title') ?></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><?= t('invoice.no_invoices') ?></h3>
<p><?= t('invoice.no_invoices_desc') ?></p>
</div>
<?php elseif (!empty($invoices)): ?>
<?php foreach ($invoices as $invoice): ?>
<div class="invoice-item">
<div class="invoice-info">
<div class="invoice-number">
<?= t('invoice.invoice_number') ?> #<?= 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 t('invoice.subscription_payment');
} else {
echo t('invoice.payment');
}
?>
</div>
<?php endif; ?>
<span class="invoice-status status-<?= htmlspecialchars($invoice['status']) ?>">
<?php
$status_key = 'invoice.status_' . $invoice['status'];
$status_translation = t($status_key);
echo ($status_translation !== $status_key) ? $status_translation : 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>
<?= t('invoice.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>
<?= t('invoice.view_invoice') ?>
</a>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</div>
<?php include 'includes/footer.php'; ?>