CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/purchases/get-current-checkout-session.ts
Views: 687
1
/*
2
Get the current stripe checkout session {session:{id:?, url:?}}, if there is one that is
3
currently open or {session:null} if not. Everytime this is called, it checks with
4
stripe for the status of the session, and if the session is no longer open (due to being
5
paid or expiring), removes the entry from the database.
6
*/
7
8
import getAccountId from "lib/account/get-account";
9
import { getCurrentSession } from "@cocalc/server/purchases/create-stripe-checkout-session";
10
11
export default async function handle(req, res) {
12
try {
13
res.json(await get(req));
14
} catch (err) {
15
res.json({ error: `${err.message}` });
16
return;
17
}
18
}
19
20
async function get(req) {
21
const account_id = await getAccountId(req);
22
if (account_id == null) {
23
throw Error("must be signed in");
24
}
25
return { session: (await getCurrentSession(account_id)) ?? null };
26
}
27
28