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/renew-subscription.ts
Views: 687
1
/*
2
Renew one of your subscriptions. Returns {purchase_id:number|nill} for the purchase of the next interval of the subscription.
3
Null if nothing needed to be done.
4
*/
5
6
import getAccountId from "lib/account/get-account";
7
import getParams from "lib/api/get-params";
8
import renewSubscription from "@cocalc/server/purchases/renew-subscription";
9
10
export default async function handle(req, res) {
11
try {
12
res.json(await get(req));
13
} catch (err) {
14
res.json({ error: `${err.message}` });
15
return;
16
}
17
}
18
19
async function get(req) {
20
const account_id = await getAccountId(req);
21
if (account_id == null) {
22
throw Error("must be signed in");
23
}
24
const { subscription_id } = getParams(req);
25
return {
26
purchase_id: await renewSubscription({
27
account_id,
28
subscription_id,
29
}),
30
};
31
}
32
33