Path: blob/master/src/packages/next/pages/api/v2/purchases/setup-automatic-billing.ts
1454 views
/*1Creates a stripe checkout session that sets up automatic billing via a stripe usage-based subscription.23This is mainly used to *increase* the user's balance periodically so that their subscriptions will4get automatically paid. Also, if they are allowed to let their balance go below 0, this periodically5tops it back up to 0.6*/78import getAccountId from "lib/account/get-account";9import { createStripeUsageBasedSubscription } from "@cocalc/server/purchases/stripe-usage-based-subscription";10import getParams from "lib/api/get-params";1112export default async function handle(req, res) {13try {14res.json(await get(req));15} catch (err) {16res.json({ error: `${err.message}` });17return;18}19}2021async function get(req) {22const account_id = await getAccountId(req);23if (account_id == null) {24throw Error("must be signed in");25}26const { success_url, cancel_url } = getParams(req);27return await createStripeUsageBasedSubscription({28account_id,29success_url,30cancel_url,31});32}333435