CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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