diff --git a/apps/dashboard/src/app/(app)/(stripe)/_components/StripeRedirectErrorPage.tsx b/apps/dashboard/src/app/(app)/(stripe)/_components/StripeRedirectErrorPage.tsx
index 57b43a46e71..a1d0a288767 100644
--- a/apps/dashboard/src/app/(app)/(stripe)/_components/StripeRedirectErrorPage.tsx
+++ b/apps/dashboard/src/app/(app)/(stripe)/_components/StripeRedirectErrorPage.tsx
@@ -1,8 +1,14 @@
+"use client";
+
+import { Button } from "@/components/ui/button";
+import { useDashboardRouter } from "@/lib/DashboardRouter";
import { AlertTriangleIcon } from "lucide-react";
export function StripeRedirectErrorPage(props: {
errorMessage: string;
}) {
+ const router = useDashboardRouter();
+
return (
@@ -10,6 +16,14 @@ export function StripeRedirectErrorPage(props: {
{props.errorMessage}
+
+
);
diff --git a/apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx b/apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx
index 45258c7c459..b154fcf05d2 100644
--- a/apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx
+++ b/apps/dashboard/src/app/(app)/(stripe)/checkout/[team_slug]/[sku]/page.tsx
@@ -58,18 +58,16 @@ export default async function CheckoutPage(props: {
break;
}
default: {
- const billingUrl = await getBillingCheckoutUrl({
+ const response = await getBillingCheckoutUrl({
teamSlug: params.team_slug,
sku: decodeURIComponent(params.sku) as Exclude,
});
- if (!billingUrl) {
- return (
-
- );
+ if (response.status === "error") {
+ return ;
}
- redirect(billingUrl);
+ redirect(response.data);
break;
}
}
diff --git a/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts b/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
index a3df8501353..dd93e0c1725 100644
--- a/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
+++ b/apps/dashboard/src/app/(app)/(stripe)/utils/billing.ts
@@ -7,11 +7,14 @@ import { getAuthToken } from "../../api/lib/getAuthToken";
export async function getBillingCheckoutUrl(options: {
teamSlug: string;
sku: Exclude;
-}): Promise {
+}) {
const token = await getAuthToken();
if (!token) {
- return undefined;
+ return {
+ status: "error",
+ error: "You are not logged in",
+ } as const;
}
const res = await fetch(
@@ -29,16 +32,43 @@ export async function getBillingCheckoutUrl(options: {
},
);
if (!res.ok) {
- console.error("Failed to create checkout link", await res.json());
- return undefined;
+ const text = await res.text();
+ console.error("Failed to create checkout link", text, res.status);
+ switch (res.status) {
+ case 402: {
+ return {
+ status: "error",
+ error:
+ "You have outstanding invoices, please pay these first before re-subscribing.",
+ } as const;
+ }
+ case 429: {
+ return {
+ status: "error",
+ error: "Too many requests, please try again later.",
+ } as const;
+ }
+ default: {
+ return {
+ status: "error",
+ error: "An unknown error occurred, please try again later.",
+ } as const;
+ }
+ }
}
const json = await res.json();
if (!json.result) {
- return undefined;
+ return {
+ status: "error",
+ error: "An unknown error occurred, please try again later.",
+ } as const;
}
- return json.result as string;
+ return {
+ status: "success",
+ data: json.result as string,
+ } as const;
}
export async function getPlanCancelUrl(options: {