Path: blob/master/src/packages/next/pages/api/v2/purchases/cancel-current-checkout-session.ts
1454 views
/*1Get the current stripe checkout session {session:{id:?, url:?}}, if there is one that is2currently open or {session:null} if not. Everytime this is called, it checks with3stripe for the status of the session, and if the session is no longer open (due to being4paid or expiring), removes the entry from the database.5*/67import getAccountId from "lib/account/get-account";8import { cancelCurrentSession } from "@cocalc/server/purchases/create-stripe-checkout-session";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}25await cancelCurrentSession(account_id);26return OkStatus;27}282930