diff --git a/server/src/internal/orgs/handlers/handleConnectStripe.ts b/server/src/internal/orgs/handlers/handleConnectStripe.ts index e7029af44..71d317f3c 100644 --- a/server/src/internal/orgs/handlers/handleConnectStripe.ts +++ b/server/src/internal/orgs/handlers/handleConnectStripe.ts @@ -2,13 +2,12 @@ import { AppEnv, ErrCode } from "@autumn/shared"; import Stripe from "stripe"; import { z } from "zod"; import { ensureStripeProductsWithEnv } from "@/external/stripe/stripeEnsureUtils.js"; - import { - checkKeyValid, - createWebhookEndpoint, + checkKeyValid, createWebhookEndpoint, } from "@/external/stripe/stripeOnboardingUtils.js"; +import { createStripeCli } from "@/external/stripe/utils.js"; import { encryptData } from "@/utils/encryptUtils.js"; -import RecaseError from "@/utils/errorUtils.js"; +import RecaseError, { handleRequestError } from "@/utils/errorUtils.js"; import { nullish } from "@/utils/genUtils.js"; import { routeHandler } from "@/utils/routerUtils.js"; import { OrgService } from "../OrgService.js"; @@ -287,3 +286,17 @@ export const handleConnectStripe = async (req: any, res: any) => }); }, }); + +export const handleGetStripe = async (req: any, res: any) => { + try { + const org = await OrgService.getFromReq(req); + + const stripeCli = createStripeCli({ org, env: req.env }); + + const account_details = await stripeCli.accounts.retrieve(); + + res.status(200).json(account_details); + } catch (error) { + handleRequestError({ req, error, res, action: "Get invoice" }); + } +}; diff --git a/server/src/internal/orgs/orgRouter.ts b/server/src/internal/orgs/orgRouter.ts index d662f7573..052bc2e9e 100644 --- a/server/src/internal/orgs/orgRouter.ts +++ b/server/src/internal/orgs/orgRouter.ts @@ -10,7 +10,10 @@ import { createOrgResponse } from "./orgUtils.js"; import { handleGetUploadUrl } from "./handlers/handleGetUploadUrl.js"; import { handleDeleteOrg } from "./handlers/handleDeleteOrg.js"; import { handleGetInvites } from "./handlers/handleGetInvites.js"; -import { handleConnectStripe } from "./handlers/handleConnectStripe.js"; +import { + handleConnectStripe, + handleGetStripe, +} from "./handlers/handleConnectStripe.js"; import { handleDeleteStripe } from "./handlers/handleDeleteStripe.js"; import { handleGetOrg } from "./handlers/handleGetOrg.js"; @@ -29,6 +32,8 @@ orgRouter.delete("/delete-user", async (req: any, res) => { orgRouter.get("", handleGetOrg); +orgRouter.get("/stripe", handleGetStripe); + orgRouter.post("/stripe", handleConnectStripe); orgRouter.delete("/stripe", handleDeleteStripe); diff --git a/vite/src/utils/linkUtils.ts b/vite/src/utils/linkUtils.ts index a3b9b4694..577e87310 100644 --- a/vite/src/utils/linkUtils.ts +++ b/vite/src/utils/linkUtils.ts @@ -1,24 +1,36 @@ import { AppEnv } from "@autumn/shared"; -export const getStripeCusLink = (customerId: string, env: AppEnv) => { - return `https://dashboard.stripe.com${ - env == AppEnv.Live ? "" : "/test" - }/customers/${customerId}`; +export const getStripeCusLink = ( + customerId: string, + env: AppEnv, + accountId?: string +) => { + return `https://dashboard.stripe.com${ + env == AppEnv.Live ? "" : "/test" + }/${accountId}/customers/${customerId}`; }; -export const getStripeSubLink = (subscriptionId: string, env: AppEnv) => { - return `https://dashboard.stripe.com${ - env == AppEnv.Live ? "" : "/test" - }/subscriptions/${subscriptionId}`; +export const getStripeSubLink = ( + subscriptionId: string, + env: AppEnv, + accountId?: string +) => { + return `https://dashboard.stripe.com${ + env == AppEnv.Live ? "" : "/test" + }/${accountId}/subscriptions/${subscriptionId}`; }; -export const getStripeSubScheduleLink = (scheduledId: string, env: AppEnv) => { - return `https://dashboard.stripe.com${ - env == AppEnv.Live ? "" : "/test" - }/subscription_schedules/${scheduledId}`; +export const getStripeSubScheduleLink = ( + scheduledId: string, + env: AppEnv, + accountId?: string +) => { + return `https://dashboard.stripe.com${ + env == AppEnv.Live ? "" : "/test" + }/${accountId}/subscription_schedules/${scheduledId}`; }; export const getStripeInvoiceLink = (stripeInvoice: any) => { - return `https://dashboard.stripe.com${ - stripeInvoice.livemode ? "" : "/test" - }/invoices/${stripeInvoice.id || stripeInvoice.stripe_id}`; + return `https://dashboard.stripe.com${ + stripeInvoice.livemode ? "" : "/test" + }/invoices/${stripeInvoice.id || stripeInvoice.stripe_id}`; }; diff --git a/vite/src/views/customers/customer/components/customer-sidebar/CustomerDetails.tsx b/vite/src/views/customers/customer/components/customer-sidebar/CustomerDetails.tsx index f9cf78b4e..df1cca754 100644 --- a/vite/src/views/customers/customer/components/customer-sidebar/CustomerDetails.tsx +++ b/vite/src/views/customers/customer/components/customer-sidebar/CustomerDetails.tsx @@ -10,119 +10,158 @@ import { Link } from "react-router"; import { useEnv } from "@/utils/envUtils"; import { SidebarLabel } from "@/components/general/sidebar/sidebar-label"; import { useCusQuery } from "../../hooks/useCusQuery"; +import { useOrg } from "@/hooks/common/useOrg"; +import Stripe from "stripe"; +import { useAxiosInstance } from "@/services/useAxiosInstance"; +import { toast } from "sonner"; export const CustomerDetails = ({ - setIsModalOpen, - setModalType, + setIsModalOpen, + setModalType, }: { - setIsModalOpen: (isModalOpen: boolean) => void; - setModalType: (modalType: string) => void; + setIsModalOpen: (isModalOpen: boolean) => void; + setModalType: (modalType: string) => void; }) => { - const { customer } = useCusQuery(); - const env = useEnv(); + const { customer } = useCusQuery(); + const env = useEnv(); + const { org } = useOrg(); - return ( -