36716-vm/manage-subscription.php
2025-12-07 05:00:42 +00:00

76 lines
3.7 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
require_once 'stripe/init.php';
if (!isset($_SESSION['user_id']) || $_SESSION['user_role'] !== 'client') {
header('Location: login.php');
exit;
}
$user_id = $_SESSION['user_id'];
$sub_stmt = db()->prepare("SELECT * FROM client_subscriptions WHERE client_id = ? AND (status = 'active' OR status = 'trialing') ORDER BY created_at DESC LIMIT 1");
$sub_stmt->execute([$user_id]);
$subscription = $sub_stmt->fetch();
if (!$subscription) {
header('Location: subscribe.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Manage Subscription - CoachConnect</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
</head>
<body class="bg-gray-100">
<header class="bg-white shadow-md">
<nav class="container mx-auto px-6 py-4 flex justify-between items-center">
<a href="index.php" class="text-2xl font-bold text-gray-800">CoachConnect</a>
<div>
<a href="dashboard.php" class="text-gray-600 hover:text-blue-500">Dashboard</a>
<a href="logout.php" class="text-gray-600 hover:text-blue-500 ml-4">Logout</a>
</div>
</nav>
</header>
<main class="container mx-auto px-6 py-12">
<div class="bg-white shadow-md rounded-lg p-8 max-w-lg mx-auto">
<h1 class="text-3xl font-bold text-gray-800 mb-6">Manage Your Subscription</h1>
<?php if (isset($_GET['status']) && $_GET['status'] === 'cancelled'): ?>
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded relative mb-4" role="alert">
<strong class="font-bold">Success!</strong>
<span class="block sm:inline">Your subscription has been cancelled.</span>
</div>
<?php endif; ?>
<div class="mb-6">
<h2 class="text-xl font-semibold text-gray-700">Subscription Details</h2>
<p class="text-gray-600 mt-2">Status: <span class="font-medium text-green-600"><?php echo htmlspecialchars(ucfirst($subscription['status'])); ?></span></p>
<p class="text-gray-600">Plan: <span class="font-medium"><?php echo htmlspecialchars(ucfirst(str_replace('_', ' ', $subscription['stripe_plan_id']))); ?></span></p>
</div>
<div class="border-t pt-6">
<h2 class="text-xl font-semibold text-gray-700">Billing Management</h2>
<p class="text-gray-600 mt-2 mb-4">Update your payment method and view your billing history.</p>
<a href="create-portal-session.php" class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blue-600 hover:bg-blue-700">Manage Billing</a>
</div>
<div class="border-t pt-6 mt-6">
<h2 class="text-xl font-semibold text-gray-700">Cancel Subscription</h2>
<p class="text-gray-600 mt-2 mb-4">If you cancel, you will lose access to subscription benefits at the end of your current billing period. This action cannot be undone.</p>
<a href="subscription-cancel.php?sub_id=<?php echo htmlspecialchars($subscription['stripe_subscription_id']); ?>" class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-red-600 hover:bg-red-700" onclick="return confirm('Are you sure you want to cancel your subscription?');">Cancel Subscription</a>
</div>
</div>
</main>
</body>
</html>