calcom/packages/app-store/stripepayment/api/portal.ts
Omar López ec58a9dd70
The Dotenv Refactor (#2275)
* dotenv refactoring

* dotenv fixes

* Env variables cleanup

* Updates e2e variables

* Moves environment file to types

* Removes conflicting configs

* Readds missing variables

* Fixes

* More fixes

* Update .env.example

* Update yarn.lock

* Update turbo.json

* Fixes e2e

* Temp fix

* disables cache for lint

* Please work

* I'm getting desperate here.

* Matches node versions

* Take 2

* Revert "Take 2"

This reverts commit a735f47f2325c2040168e0cd99dea0fc357a791f.

* Update .env.example
2022-03-25 17:39:38 -07:00

23 lines
740 B
TypeScript

import type { NextApiRequest, NextApiResponse } from "next";
import { getStripeCustomerIdFromUserId } from "@calcom/stripe/customer";
import stripe from "@calcom/stripe/server";
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === "POST") {
const customerId = await getStripeCustomerIdFromUserId(req.session!.user.id);
if (!customerId) {
res.status(500).json({ message: "Missing customer id" });
return;
}
const return_url = `${process.env.NEXT_PUBLIC_WEBAPP_URL}/settings/billing`;
const stripeSession = await stripe.billingPortal.sessions.create({
customer: customerId,
return_url,
});
res.redirect(302, stripeSession.url);
}
}