Path: blob/master/src/packages/next/pages/api/v2/purchases/cancel-subscription.ts
1454 views
/*1Cancel a subscription.23- now: if true, cancels license now and provides a refund. Otherwise, cancels at period end.4*/56import getAccountId from "lib/account/get-account";7import cancelSubscription from "@cocalc/server/purchases/cancel-subscription";8import getParams from "lib/api/get-params";9import { OkStatus } from "lib/api/status";1011export default async function handle(req, res) {12try {13res.json(await get(req));14} catch (err) {15res.json({ error: `${err.message}` });16return;17}18}1920async function get(req) {21const account_id = await getAccountId(req);22if (account_id == null) {23throw Error("must be signed in");24}25const { subscription_id, reason } = getParams(req);26await cancelSubscription({27account_id,28subscription_id,29reason,30});31return OkStatus;32}333435