52 lines
1.7 KiB
PHP
52 lines
1.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;
|
|
}
|
|
|
|
if (!isset($_GET['sub_id'])) {
|
|
header('Location: manage-subscription.php?status=error');
|
|
exit;
|
|
}
|
|
|
|
$subscription_id = $_GET['sub_id'];
|
|
|
|
try {
|
|
$stripe->subscriptions->cancel($subscription_id, []);
|
|
|
|
$stmt = db()->prepare("UPDATE client_subscriptions SET status = 'cancelled' WHERE stripe_subscription_id = ?");
|
|
$stmt->execute([$subscription_id]);
|
|
|
|
header('Location: manage-subscription.php?status=cancelled');
|
|
exit;
|
|
} catch (\Stripe\Exception\ApiErrorException $e) {
|
|
// Display error message
|
|
$error = $e->getMessage();
|
|
}
|
|
?>
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Subscription Cancellation Error</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
|
|
</head>
|
|
<body class="bg-gray-100">
|
|
<div 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-2xl font-bold text-red-600 mb-4">Cancellation Error</h1>
|
|
<p class="text-gray-700">There was an error cancelling your subscription:</p>
|
|
<p class="text-red-500 mt-2"><strong><?php echo htmlspecialchars($error); ?></strong></p>
|
|
<div class="mt-6">
|
|
<a href="manage-subscription.php" class="inline-block bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">Go Back to Subscription Management</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|