diff options
| author | Frank <[email protected]> | 2026-03-19 18:44:21 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2026-03-19 18:44:24 -0400 |
| commit | bd44489ada70cf908b69466f623ca74e800b3fc7 (patch) | |
| tree | 0819979511404c9aba7d1274da7aa83128a65139 /packages/console/app/src/routes/stripe | |
| parent | a6ef9e92065937dfeb9920abfd6e88bf95b1e572 (diff) | |
| download | opencode-bd44489ada70cf908b69466f623ca74e800b3fc7.tar.gz opencode-bd44489ada70cf908b69466f623ca74e800b3fc7.zip | |
go: upi payment
Diffstat (limited to 'packages/console/app/src/routes/stripe')
| -rw-r--r-- | packages/console/app/src/routes/stripe/webhook.ts | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/packages/console/app/src/routes/stripe/webhook.ts b/packages/console/app/src/routes/stripe/webhook.ts index 95cd9da21..47fee05cf 100644 --- a/packages/console/app/src/routes/stripe/webhook.ts +++ b/packages/console/app/src/routes/stripe/webhook.ts @@ -244,6 +244,7 @@ export async function POST(input: APIEvent) { customerID, enrichment: { type: productID === LiteData.productID() ? "lite" : "subscription", + currency: body.data.object.currency === "inr" ? "inr" : undefined, couponID, }, }), @@ -331,16 +332,17 @@ export async function POST(input: APIEvent) { ) if (!workspaceID) throw new Error("Workspace ID not found") - const amount = await Database.use((tx) => + const payment = await Database.use((tx) => tx .select({ amount: PaymentTable.amount, + enrichment: PaymentTable.enrichment, }) .from(PaymentTable) .where(and(eq(PaymentTable.paymentID, paymentIntentID), eq(PaymentTable.workspaceID, workspaceID))) - .then((rows) => rows[0]?.amount), + .then((rows) => rows[0]), ) - if (!amount) throw new Error("Payment not found") + if (!payment) throw new Error("Payment not found") await Database.transaction(async (tx) => { await tx @@ -350,12 +352,15 @@ export async function POST(input: APIEvent) { }) .where(and(eq(PaymentTable.paymentID, paymentIntentID), eq(PaymentTable.workspaceID, workspaceID))) - await tx - .update(BillingTable) - .set({ - balance: sql`${BillingTable.balance} - ${amount}`, - }) - .where(eq(BillingTable.workspaceID, workspaceID)) + // deduct balance only for top up + if (!payment.enrichment?.type) { + await tx + .update(BillingTable) + .set({ + balance: sql`${BillingTable.balance} - ${payment.amount}`, + }) + .where(eq(BillingTable.workspaceID, workspaceID)) + } }) } })() |
