- Analytics: <Analytics /> in root layout loads umami when NEXT_PUBLIC_UMAMI_* env are set - Subscription: free/pro tiers in Postgres, daily quotas (10msg/5tool free, 1000/500 pro) - Chat route: checkAndConsume(chat_message) gate before streamText, 429 when exhausted - Tool metering: getWeather wrapped with withLimit decorator that deducts tool_call quota - Pricing page at /pricing with upgrade button - /api/billing/checkout posts to EGBE payment gateway, /api/billing/webhook verifies HMAC and upgrades user on checkout.session.completed - UsageBadge in chat header polls /api/usage every 15s - Dropped now-unused entitlements.ts
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import { toast } from "sonner";
|
|
import { Button } from "@/components/ui/button";
|
|
import type { Tier } from "@/lib/subscription/config";
|
|
|
|
export function PricingClient({ currentTier }: { currentTier: Tier }) {
|
|
const [loading, setLoading] = useState(false);
|
|
|
|
if (currentTier === "pro") {
|
|
return (
|
|
<p className="text-muted-foreground text-sm">
|
|
You're on Pro. Manage your subscription through the receipt email link.
|
|
</p>
|
|
);
|
|
}
|
|
|
|
const upgrade = async () => {
|
|
setLoading(true);
|
|
try {
|
|
const response = await fetch("/api/billing/checkout", { method: "POST" });
|
|
const data = await response.json();
|
|
if (response.ok && data.url) {
|
|
window.location.href = data.url;
|
|
return;
|
|
}
|
|
toast.error(data.message ?? "Failed to start checkout");
|
|
} catch (error) {
|
|
toast.error(error instanceof Error ? error.message : "Checkout failed");
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<div className="flex justify-center">
|
|
<Button
|
|
className="px-6"
|
|
disabled={loading}
|
|
onClick={upgrade}
|
|
size="lg"
|
|
>
|
|
{loading ? "Opening checkout..." : "Upgrade to Pro"}
|
|
</Button>
|
|
</div>
|
|
);
|
|
}
|