diff options
| author | Frank <[email protected]> | 2026-04-18 17:33:26 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2026-04-18 17:33:28 -0400 |
| commit | 54b3b3fe05fd66f8f3b479ec438b53d38dbc6d0d (patch) | |
| tree | bcdee7401ce0c10677e8c3fe6674bdc0263eb549 /packages/console/core | |
| parent | 9d012b062186ef9900cc2673b77c446d38ebd789 (diff) | |
| download | opencode-54b3b3fe05fd66f8f3b479ec438b53d38dbc6d0d.tar.gz opencode-54b3b3fe05fd66f8f3b479ec438b53d38dbc6d0d.zip | |
zen: redeem go
Diffstat (limited to 'packages/console/core')
| -rw-r--r-- | packages/console/core/src/billing.ts | 23 | ||||
| -rw-r--r-- | packages/console/core/src/lite.ts | 8 | ||||
| -rw-r--r-- | packages/console/core/sst-env.d.ts | 4 |
3 files changed, 21 insertions, 14 deletions
diff --git a/packages/console/core/src/billing.ts b/packages/console/core/src/billing.ts index d96b19ad7..a3252f1d7 100644 --- a/packages/console/core/src/billing.ts +++ b/packages/console/core/src/billing.ts @@ -1,5 +1,5 @@ import { Stripe } from "stripe" -import { and, Database, eq, sql } from "./drizzle" +import { and, Database, eq, isNull, sql } from "./drizzle" import { BillingTable, CouponTable, @@ -176,6 +176,16 @@ export namespace Billing { ) } + export const hasCoupon = async (email: string, type: (typeof CouponType)[number]) => { + return await Database.use((tx) => + tx + .select() + .from(CouponTable) + .where(and(eq(CouponTable.email, email), eq(CouponTable.type, type), isNull(CouponTable.timeRedeemed))) + .then((rows) => rows.length > 0), + ) + } + export const setMonthlyLimit = fn(z.number(), async (input) => { return await Database.use((tx) => tx @@ -274,16 +284,19 @@ export namespace Billing { const user = Actor.assert("user") const { successUrl, cancelUrl, method } = input - const email = await User.getAuthEmail(user.properties.userID) + const email = (await User.getAuthEmail(user.properties.userID))! const billing = await Billing.get() if (billing.subscriptionID) throw new Error("Already subscribed to Black") if (billing.liteSubscriptionID) throw new Error("Already subscribed to Lite") + const coupon = (await Billing.hasCoupon(email, "GOFREEMONTH")) + ? LiteData.firstMonth100Coupon + : LiteData.firstMonth50Coupon const createSession = () => Billing.stripe().checkout.sessions.create({ mode: "subscription", - discounts: [{ coupon: LiteData.firstMonthCoupon(email!) }], + discounts: [{ coupon }], ...(billing.customerID ? { customer: billing.customerID, @@ -293,7 +306,7 @@ export namespace Billing { }, } : { - customer_email: email!, + customer_email: email, }), ...(() => { if (method === "alipay") { @@ -341,6 +354,8 @@ export namespace Billing { metadata: { workspaceID: Actor.workspace(), userID: user.properties.userID, + userEmail: email, + coupon, type: "lite", }, }, diff --git a/packages/console/core/src/lite.ts b/packages/console/core/src/lite.ts index 3343192c1..c04977664 100644 --- a/packages/console/core/src/lite.ts +++ b/packages/console/core/src/lite.ts @@ -11,11 +11,7 @@ export namespace LiteData { export const productID = fn(z.void(), () => Resource.ZEN_LITE_PRICE.product) export const priceID = fn(z.void(), () => Resource.ZEN_LITE_PRICE.price) export const priceInr = fn(z.void(), () => Resource.ZEN_LITE_PRICE.priceInr) - export const firstMonthCoupon = fn(z.string(), (email) => { - const invitees = Resource.ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES.value.split(",") - return invitees.includes(email) - ? Resource.ZEN_LITE_PRICE.firstMonth100Coupon - : Resource.ZEN_LITE_PRICE.firstMonth50Coupon - }) + export const firstMonth100Coupon = Resource.ZEN_LITE_PRICE.firstMonth100Coupon + export const firstMonth50Coupon = Resource.ZEN_LITE_PRICE.firstMonth50Coupon export const planName = fn(z.void(), () => "lite") } diff --git a/packages/console/core/sst-env.d.ts b/packages/console/core/sst-env.d.ts index b77ee3c5b..bfba1b8f2 100644 --- a/packages/console/core/sst-env.d.ts +++ b/packages/console/core/sst-env.d.ts @@ -142,10 +142,6 @@ declare module "sst" { "type": "sst.sst.Secret" "value": string } - "ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES": { - "type": "sst.sst.Secret" - "value": string - } "ZEN_LITE_PRICE": { "firstMonth100Coupon": string "firstMonth50Coupon": string |
