Path: blob/master/src/packages/next/pages/api/v2/purchases/stripe/get-payments.ts
1456 views
import getAccountId from "lib/account/get-account";1import getPayments from "@cocalc/server/purchases/stripe/get-payments";2import throttle from "@cocalc/util/api/throttle";3import getParams from "lib/api/get-params";4import userIsInGroup from "@cocalc/server/accounts/is-in-group";56// See https://docs.stripe.com/api/payment_intents/list for definition of7// all parameters, which are passed in exactly to stripe's api. In particular,8// time is in seconds and is either or string or number depending on how given,9// and ending_before, starting_after are NOT times but object id's.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}25throttle({ account_id, endpoint: "purchases/stripe/get-payments" });2627const {28user_account_id,29created,30ending_before,31starting_after,32limit,33unfinished,34canceled,35} = getParams(req);36if (user_account_id) {37// This user MUST be an admin:38if (!(await userIsInGroup(account_id, "admin"))) {39throw Error("only admins can get other user's open payments");40}41return await getPayments({42account_id: user_account_id,43created,44ending_before,45starting_after,46limit,47unfinished,48canceled,49});50}5152return await getPayments({53account_id,54created,55ending_before,56starting_after,57limit,58unfinished,59canceled,60});61}626364