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/billing/get-invoice-url.ts
Views: 687
1
/*
2
Get specific invoice's hosted URL, given that you know the invoice id.
3
4
LEGACY: Also works for receipt of payment intent.
5
*/
6
import { getInvoiceUrl } from "@cocalc/server/billing/get-invoices-and-receipts";
7
import getAccountId from "lib/account/get-account";
8
import getParams from "lib/api/get-params";
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): Promise<object> {
20
const account_id = await getAccountId(req);
21
if (account_id == null) {
22
// doesn't matter what id is -- just that signed in...
23
throw Error("must be signed in");
24
}
25
const { invoice_id } = getParams(req);
26
return { url: await getInvoiceUrl(invoice_id) };
27
}
28
29