Path: blob/master/src/packages/next/pages/api/v2/purchases/stripe/get-payment-methods.ts
1456 views
import getAccountId from "lib/account/get-account";1import getPaymentMethods from "@cocalc/server/purchases/stripe/get-payment-methods";2import throttle from "@cocalc/util/api/throttle";3import getParams from "lib/api/get-params";4import userIsInGroup from "@cocalc/server/accounts/is-in-group";56export default async function handle(req, res) {7try {8res.json(await get(req));9} catch (err) {10res.json({ error: `${err.message}` });11return;12}13}1415async function get(req) {16const account_id = await getAccountId(req);17if (account_id == null) {18throw Error("must be signed in");19}20throttle({ account_id, endpoint: "purchases/stripe/get-payment-methods" });2122const { user_account_id, ending_before, starting_after, limit } =23getParams(req);24if (user_account_id) {25// This user MUST be an admin:26if (!(await userIsInGroup(account_id, "admin"))) {27throw Error("only admins can get other user's payment methods");28}29return await getPaymentMethods({30account_id: user_account_id,31ending_before,32starting_after,33limit,34});35}3637return await getPaymentMethods({38account_id,39ending_before,40starting_after,41limit,42});43}444546