add stripe payment to cloud

This commit is contained in:
Matthias Nannt
2023-04-08 16:53:42 +02:00
parent 01a637d0f6
commit a934fa3897
15 changed files with 303 additions and 96 deletions
@@ -0,0 +1 @@
export { default } from "@formbricks/ee/billing/api/create-customer-portal-session";
@@ -0,0 +1 @@
export { config, default } from "@formbricks/ee/billing/api/stripe-webhook";
@@ -0,0 +1,49 @@
import { hasEnvironmentAccess } from "@/lib/api/apiHelper";
import { prisma } from "@formbricks/database";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handle(req: NextApiRequest, res: NextApiResponse) {
const environmentId = req.query?.environmentId?.toString();
const hasAccess = await hasEnvironmentAccess(req, res, environmentId);
if (!hasAccess) {
return res.status(403).json({ message: "Not authorized" });
}
// GET
if (req.method === "GET") {
const environment = await prisma.environment.findUnique({
where: {
id: environmentId,
},
select: {
product: {
select: {
teamId: true,
},
},
},
});
if (environment === null) {
return res.status(404).json({ message: "This environment doesn't exist" });
}
const team = await prisma.team.findUnique({
where: {
id: environment.product.teamId,
},
select: {
id: true,
name: true,
stripeCustomerId: true,
},
});
if (team === null) {
return res.status(404).json({ message: "This product doesn't exist" });
}
return res.json(team);
}
// Unknown HTTP Method
else {
throw new Error(`The HTTP ${req.method} method is not supported by this route.`);
}
}