diff options
Diffstat (limited to 'packages/console/core/src')
| -rw-r--r-- | packages/console/core/src/billing.ts | 21 | ||||
| -rw-r--r-- | packages/console/core/src/lite.ts | 3 | ||||
| -rw-r--r-- | packages/console/core/src/schema/billing.sql.ts | 2 |
3 files changed, 18 insertions, 8 deletions
diff --git a/packages/console/core/src/billing.ts b/packages/console/core/src/billing.ts index a3252f1d7..ca3a40878 100644 --- a/packages/console/core/src/billing.ts +++ b/packages/console/core/src/billing.ts @@ -176,13 +176,13 @@ export namespace Billing { ) } - export const hasCoupon = async (email: string, type: (typeof CouponType)[number]) => { + export const getCoupons = async (email: string) => { return await Database.use((tx) => tx - .select() + .select({ type: CouponTable.type, timeRedeemed: CouponTable.timeRedeemed }) .from(CouponTable) - .where(and(eq(CouponTable.email, email), eq(CouponTable.type, type), isNull(CouponTable.timeRedeemed))) - .then((rows) => rows.length > 0), + .where(and(eq(CouponTable.email, email), isNull(CouponTable.timeRedeemed))) + .then((rows) => rows.map((row) => row.type)), ) } @@ -290,9 +290,16 @@ export namespace Billing { 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 coupons = await Billing.getCoupons(email) + const coupon = coupons.includes("GO12MONTHS100") + ? LiteData.twelveMonths100Coupon + : coupons.includes("GO6MONTHS100") + ? LiteData.sixMonths100Coupon + : coupons.includes("GO3MONTHS100") + ? LiteData.threeMonths100Coupon + : coupons.includes("GOFREEMONTH") + ? LiteData.firstMonth100Coupon + : LiteData.firstMonth50Coupon const createSession = () => Billing.stripe().checkout.sessions.create({ mode: "subscription", diff --git a/packages/console/core/src/lite.ts b/packages/console/core/src/lite.ts index c04977664..717940ea6 100644 --- a/packages/console/core/src/lite.ts +++ b/packages/console/core/src/lite.ts @@ -13,5 +13,8 @@ export namespace LiteData { export const priceInr = fn(z.void(), () => Resource.ZEN_LITE_PRICE.priceInr) export const firstMonth100Coupon = Resource.ZEN_LITE_PRICE.firstMonth100Coupon export const firstMonth50Coupon = Resource.ZEN_LITE_PRICE.firstMonth50Coupon + export const threeMonths100Coupon = Resource.ZEN_LITE_PRICE.threeMonths100Coupon + export const sixMonths100Coupon = Resource.ZEN_LITE_PRICE.sixMonths100Coupon + export const twelveMonths100Coupon = Resource.ZEN_LITE_PRICE.twelveMonths100Coupon export const planName = fn(z.void(), () => "lite") } diff --git a/packages/console/core/src/schema/billing.sql.ts b/packages/console/core/src/schema/billing.sql.ts index f8dcbd2b1..12cdba258 100644 --- a/packages/console/core/src/schema/billing.sql.ts +++ b/packages/console/core/src/schema/billing.sql.ts @@ -133,7 +133,7 @@ export const UsageTable = mysqlTable( (table) => [...workspaceIndexes(table), index("usage_time_created").on(table.workspaceID, table.timeCreated)], ) -export const CouponType = ["BUILDATHON", "GOFREEMONTH"] as const +export const CouponType = ["BUILDATHON", "GOFREEMONTH", "GO3MONTHS100", "GO6MONTHS100", "GO12MONTHS100"] as const export const CouponTable = mysqlTable( "coupon", { |
