Path: blob/master/src/packages/next/pages/api/v2/purchases/stripe/set-default-payment-method.ts
1456 views
/*1Set default payment method for signed in customer.2*/34import setDefaultPaymentMethod from "@cocalc/server/purchases/stripe/set-default-payment-method";5import getAccountId from "lib/account/get-account";6import getParams from "lib/api/get-params";7import throttle from "@cocalc/util/api/throttle";89export default async function handle(req, res) {10try {11res.json(await set(req));12} catch (err) {13res.json({ error: `${err.message}` });14return;15}16}1718async function set(req): Promise<{ success: true }> {19const account_id = await getAccountId(req);20if (account_id == null) {21throw Error("must be signed in to set stripe default payment method");22}23throttle({ account_id, endpoint: "purchases/stripe/set-default-payment-method" });24const { default_payment_method } = getParams(req);25if (!default_payment_method) {26throw Error("must specify the default source");27}28await setDefaultPaymentMethod({ account_id, default_payment_method });29return { success: true };30}313233