Path: blob/master/src/packages/database/postgres/stripe/customer-id.ts
1503 views
import getPool from "@cocalc/database/pool";1import getLogger from "@cocalc/backend/logger";23const log = getLogger("database:stripe:customer-id");45// Set the stripe id in our database of this user. If there is no user with this6// account_id, then this is a NO-OP (not an error).7export async function setStripeCustomerId(8account_id: string,9customer_id: string10): Promise<void> {11log.debug("setting customer id of ", account_id, " to ", customer_id);12const pool = getPool();13await pool.query(14"UPDATE accounts SET stripe_customer_id=$1::TEXT WHERE account_id=$2",15[customer_id, account_id]16);17}1819// Get the stripe id in our database of this user (or undefined if no20// stripe_id or no such user).21export async function getStripeCustomerId(22account_id: string23): Promise<string | undefined> {24log.debug("getting customer id for ", account_id);25const pool = getPool();26const { rows } = await pool.query(27"SELECT stripe_customer_id FROM accounts WHERE account_id=$1",28[account_id]29);30return rows[0]?.stripe_customer_id;31}323334