requireLogin(); // Prüfe ob Billing aktiviert if (!$settingsManager->isBillingEnabled()) { header('Location: /dashboard/'); exit; } $user = $auth->getUser(); $tenantId = $user['tenant_id'] ?? 0; $flashMessage = null; $flashType = 'info'; $stripe = new StripeService(); $subscriptions = new SubscriptionManager(); // Aktuelle Subscription $currentSub = null; $plans = []; $invoices = []; $trialDays = 0; try { $currentSub = $subscriptions->getSubscription($tenantId); $plans = $subscriptions->getPlans(); $invoices = $subscriptions->getInvoices($tenantId, 5); $trialDays = $subscriptions->getTrialDaysRemaining($tenantId); } catch (\Exception $e) { $flashMessage = 'Fehler beim Laden der Abrechnungsdaten'; $flashType = 'error'; } // Checkout starten if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['plan_id'])) { $planId = (int)$_POST['plan_id']; $plan = $subscriptions->getPlan($planId); if ($plan && !empty($plan['stripe_price_id'])) { $baseUrl = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; $session = $stripe->createCheckoutSession( $tenantId, $plan['stripe_price_id'], $baseUrl . '/dashboard/billing.php?success=1', $baseUrl . '/dashboard/billing.php?canceled=1' ); if ($session && isset($session['url'])) { header('Location: ' . $session['url']); exit; } else { $flashMessage = 'Fehler beim Erstellen der Checkout-Session'; $flashType = 'error'; } } } // Billing Portal öffnen if (isset($_GET['portal'])) { $baseUrl = (isset($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST']; $session = $stripe->createPortalSession($tenantId, $baseUrl . '/dashboard/billing.php'); if ($session && isset($session['url'])) { header('Location: ' . $session['url']); exit; } } // Success/Cancel Messages if (isset($_GET['success'])) { $flashMessage = 'Zahlung erfolgreich! Ihr Abo ist jetzt aktiv.'; $flashType = 'success'; } if (isset($_GET['canceled'])) { $flashMessage = 'Checkout abgebrochen.'; $flashType = 'warning'; } $pageTitle = 'Abrechnung'; $currentPage = 'billing'; ob_start(); ?>
Trial endet in Tag
Nächste Abrechnung:
Kein aktives Abo
| Datum | Betrag | Status | |
|---|---|---|---|
| Download |