Path: blob/master/src/packages/next/pages/api/v2/purchases/stripe/get-payment-method.ts
1456 views
import getAccountId from "lib/account/get-account";1import { getPaymentMethod } 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-method" });2122const { user_account_id, id } = getParams(req);23if (user_account_id) {24// This user MUST be an admin:25if (!(await userIsInGroup(account_id, "admin"))) {26throw Error("only admins can get other user's payment methods");27}28return await getPaymentMethod({29account_id: user_account_id,30id,31});32}3334return await getPaymentMethod({35account_id,36id,37});38}394041