The Invoice and Manage card details links are working
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { BillingClient } from "@trigger.dev/billing";
|
||||
import { PrismaClient, prisma } from "~/db.server";
|
||||
import { env } from "~/env.server";
|
||||
import { logger } from "~/services/logger.server";
|
||||
import { organizationBillingPath } from "~/utils/pathBuilder";
|
||||
|
||||
export class BillingPresenter {
|
||||
#billingClient: BillingClient | undefined;
|
||||
@@ -68,4 +70,16 @@ export class BillingPresenter {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
async customerPortalUrl(orgId: string, orgSlug: string) {
|
||||
if (!this.#billingClient) return undefined;
|
||||
try {
|
||||
return this.#billingClient.createPortalSession(orgId, {
|
||||
returnUrl: `${env.APP_ORIGIN}${organizationBillingPath({ slug: orgSlug })}`,
|
||||
});
|
||||
} catch (e) {
|
||||
logger.error("Error getting customer portal Url", { orgId, error: e });
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@ import { useCurrentPlan } from "../_app.orgs.$organizationSlug/route";
|
||||
import { useFeatures } from "~/hooks/useFeatures";
|
||||
import { DateTime } from "~/components/primitives/DateTime";
|
||||
import { formatDuration, formatDurationMilliseconds } from "~/utils";
|
||||
import { featuresForRequest } from "~/features.server";
|
||||
import { BillingPresenter } from "~/presenters/BillingPresenter.server";
|
||||
|
||||
export async function loader({ params, request }: LoaderFunctionArgs) {
|
||||
const userId = await requireUserId(request);
|
||||
@@ -37,9 +39,12 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
|
||||
throw new Response(null, { status: 404 });
|
||||
}
|
||||
|
||||
//todo generate a Stripe customer portal link, if managed cloud
|
||||
const { isManagedCloud } = featuresForRequest(request);
|
||||
const billingPresenter = new BillingPresenter(isManagedCloud);
|
||||
const portal = await billingPresenter.customerPortalUrl(data.id, organizationSlug);
|
||||
const stripePortalLink = portal?.success ? portal?.customerPortalUrl : undefined;
|
||||
|
||||
return typedjson({ ...data, stripePortalLink: undefined });
|
||||
return typedjson({ ...data, stripePortalLink });
|
||||
}
|
||||
|
||||
export const handle: Handle = {
|
||||
@@ -62,10 +67,10 @@ export default function Page() {
|
||||
<>
|
||||
{stripePortalLink && (
|
||||
<>
|
||||
<LinkButton to={""} variant="secondary/small">
|
||||
<LinkButton to={stripePortalLink} variant="secondary/small">
|
||||
Invoices
|
||||
</LinkButton>
|
||||
<LinkButton to={""} variant="secondary/small">
|
||||
<LinkButton to={stripePortalLink} variant="secondary/small">
|
||||
Manage card details
|
||||
</LinkButton>
|
||||
</>
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
"@tabler/icons-react": "^2.39.0",
|
||||
"@tailwindcss/container-queries": "^0.1.1",
|
||||
"@team-plain/typescript-sdk": "^3.5.0",
|
||||
"@trigger.dev/billing": "^1.0.5",
|
||||
"@trigger.dev/billing": "^1.0.7",
|
||||
"@trigger.dev/companyicons": "^1.5.32",
|
||||
"@trigger.dev/core": "workspace:*",
|
||||
"@trigger.dev/core-backend": "workspace:*",
|
||||
|
||||
Generated
+4
-4
@@ -130,7 +130,7 @@ importers:
|
||||
'@tailwindcss/typography': ^0.5.9
|
||||
'@team-plain/typescript-sdk': ^3.5.0
|
||||
'@total-typescript/ts-reset': ^0.4.2
|
||||
'@trigger.dev/billing': ^1.0.5
|
||||
'@trigger.dev/billing': ^1.0.7
|
||||
'@trigger.dev/companyicons': ^1.5.32
|
||||
'@trigger.dev/core': workspace:*
|
||||
'@trigger.dev/core-backend': workspace:*
|
||||
@@ -268,7 +268,7 @@ importers:
|
||||
'@tabler/icons-react': 2.40.0_react@18.2.0
|
||||
'@tailwindcss/container-queries': 0.1.1_tailwindcss@3.3.2
|
||||
'@team-plain/typescript-sdk': 3.5.0
|
||||
'@trigger.dev/billing': 1.0.5
|
||||
'@trigger.dev/billing': 1.0.7
|
||||
'@trigger.dev/companyicons': 1.5.32_biqbaboplfbrettd7655fr4n2y
|
||||
'@trigger.dev/core': link:../../packages/core
|
||||
'@trigger.dev/core-backend': link:../../packages/core-backend
|
||||
@@ -14333,8 +14333,8 @@ packages:
|
||||
resolution: {integrity: sha512-vqd7ZUDSrXFVT1n8b2kc3LnklncDQFPvR58yUS1kEP23/nHPAO9l1lMjUfnPrXYYk4Hj54rrLKMW5ipwk7k09A==}
|
||||
dev: true
|
||||
|
||||
/@trigger.dev/billing/1.0.5:
|
||||
resolution: {integrity: sha512-mx5yr73OeJc7FXw//RNEXA9nZKkR15fK1hPFxlZjrJtYZX9znr7KrFd9ny0zL8bhZGWDqQwXtRYUdKsVVEqSow==}
|
||||
/@trigger.dev/billing/1.0.7:
|
||||
resolution: {integrity: sha512-ys1yQjIuJZ7chGS3wsVLzjsHif4bN5c2u/GG4PYGOECjIFXEifZsmIqAFWIEIh4Kxh7uYR3qMh/noTREv4SUxA==}
|
||||
dependencies:
|
||||
zod: 3.22.3
|
||||
dev: false
|
||||
|
||||
Reference in New Issue
Block a user