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/create-credit.ts
Views: 687
1
/*
2
Creates a stripe checkout session that when paid, credits the user's account.
3
4
This is used to *increase* the user's balance so they are allowed to make purchases.
5
*/
6
7
import getAccountId from "lib/account/get-account";
8
import createStripeCheckoutSession from "@cocalc/server/purchases/create-stripe-checkout-session";
9
import getParams from "lib/api/get-params";
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
const {
26
amount,
27
description = "Credit Your Account",
28
success_url,
29
cancel_url,
30
} = getParams(req);
31
return await createStripeCheckoutSession({
32
account_id,
33
line_items: [{
34
amount,
35
description,
36
}],
37
success_url,
38
cancel_url,
39
});
40
}
41
42