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. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/purchases/stripe/delete-payment-method.ts
Views: 791
1
import deletePaymentMethod from "@cocalc/server/purchases/stripe/delete-payment-method";
2
import getAccountId from "lib/account/get-account";
3
import getParams from "lib/api/get-params";
4
import throttle from "@cocalc/util/api/throttle";
5
6
export default async function handle(req, res) {
7
try {
8
res.json(await set(req));
9
} catch (err) {
10
res.json({ error: `${err.message}` });
11
return;
12
}
13
}
14
15
async function set(req): Promise<{ success: true }> {
16
const account_id = await getAccountId(req);
17
if (account_id == null) {
18
throw Error("must be signed in to delete payment method");
19
}
20
throttle({ account_id, endpoint: "purchases/stripe/delete-payment-method" });
21
const { payment_method } = getParams(req);
22
if (!payment_method) {
23
throw Error("must specify the payment method to delete");
24
}
25
await deletePaymentMethod({ payment_method });
26
return { success: true };
27
}
28
29