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/cancel-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 { cancelCurrentSession } from "@cocalc/server/purchases/create-stripe-checkout-session";
10
import { OkStatus } from "lib/api/status";
11
12
export default async function handle(req, res) {
13
try {
14
res.json(await get(req));
15
} catch (err) {
16
res.json({ error: `${err.message}` });
17
return;
18
}
19
}
20
21
async function get(req) {
22
const account_id = await getAccountId(req);
23
if (account_id == null) {
24
throw Error("must be signed in");
25
}
26
await cancelCurrentSession(account_id);
27
return OkStatus;
28
}
29
30