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