prepare("SELECT stripe_customer_id FROM clients WHERE id = ?"); $stmt->execute([$user_id]); $client = $stmt->fetch(); if (!$client || !$client['stripe_customer_id']) { // This should not happen if the user has a subscription header('Location: subscribe.php'); exit; } $return_url = 'http://' . $_SERVER['HTTP_HOST'] . '/manage-subscription.php'; $portalSession = \Stripe\BillingPortal\Session::create([ 'customer' => $client['stripe_customer_id'], 'return_url' => $return_url, ]); header("Location: " . $portalSession->url); exit();