summaryrefslogtreecommitdiffhomepage
path: root/packages/console/app/src/routes/stripe
diff options
context:
space:
mode:
authorFrank <[email protected]>2026-03-19 18:44:21 -0400
committerFrank <[email protected]>2026-03-19 18:44:24 -0400
commitbd44489ada70cf908b69466f623ca74e800b3fc7 (patch)
tree0819979511404c9aba7d1274da7aa83128a65139 /packages/console/app/src/routes/stripe
parenta6ef9e92065937dfeb9920abfd6e88bf95b1e572 (diff)
downloadopencode-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.ts23
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))
+ }
})
}
})()