summaryrefslogtreecommitdiffhomepage
path: root/packages/console/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/console/core/src')
-rw-r--r--packages/console/core/src/billing.ts18
1 files changed, 18 insertions, 0 deletions
diff --git a/packages/console/core/src/billing.ts b/packages/console/core/src/billing.ts
index 049ee29bb..c14df11ae 100644
--- a/packages/console/core/src/billing.ts
+++ b/packages/console/core/src/billing.ts
@@ -157,6 +157,24 @@ export namespace Billing {
})
}
+ export const grantCredit = async (workspaceID: string, dollarAmount: number) => {
+ const amountInMicroCents = centsToMicroCents(dollarAmount * 100)
+ await Database.transaction(async (tx) => {
+ await tx
+ .update(BillingTable)
+ .set({
+ balance: sql`${BillingTable.balance} + ${amountInMicroCents}`,
+ })
+ .where(eq(BillingTable.workspaceID, workspaceID))
+ await tx.insert(PaymentTable).values({
+ workspaceID,
+ id: Identifier.create("payment"),
+ amount: amountInMicroCents,
+ })
+ })
+ return amountInMicroCents
+ }
+
export const setMonthlyLimit = fn(z.number(), async (input) => {
return await Database.use((tx) =>
tx