GeezerVison is showing github.com — zen: redeem go · tbenton/opencode@54b3b3f
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: infra/console.ts -1Lines changed: 0 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -236,7 +236,6 @@ new sst.cloudflare.x.SolidStart("Console", { | 236 | 236 | SALESFORCE_INSTANCE_URL, | 237 | 237 | ZEN_BLACK_PRICE, | 238 | 238 | ZEN_LITE_PRICE, | 239 | | - new sst.Secret("ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES"), | 240 | 239 | new sst.Secret("ZEN_LIMITS"), | 241 | 240 | new sst.Secret("ZEN_SESSION_SECRET"), | 242 | 241 | ...ZEN_MODELS, | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/app/src/routes/stripe/webhook.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -9,6 +9,7 @@ import { Actor } from "@opencode-ai/console-core/actor.js" | 9 | 9 | import { Resource } from "@opencode-ai/console-resource" | 10 | 10 | import { LiteData } from "@opencode-ai/console-core/lite.js" | 11 | 11 | import { BlackData } from "@opencode-ai/console-core/black.js" | | 12 | +import { User } from "@opencode-ai/console-core/user.js" | 12 | 13 |
| 13 | 14 | export async function POST(input: APIEvent) { | 14 | 15 | const body = await Billing.stripe().webhooks.constructEventAsync( | @@ -109,6 +110,8 @@ export async function POST(input: APIEvent) { | 109 | 110 | if (type === "lite") { | 110 | 111 | const workspaceID = body.data.object.metadata?.workspaceID | 111 | 112 | const userID = body.data.object.metadata?.userID | | 113 | + const userEmail = body.data.object.metadata?.userEmail | | 114 | + const coupon = body.data.object.metadata?.coupon | 112 | 115 | const customerID = body.data.object.customer as string | 113 | 116 | const invoiceID = body.data.object.latest_invoice as string | 114 | 117 | const subscriptionID = body.data.object.id as string | @@ -156,6 +159,10 @@ export async function POST(input: APIEvent) { | 156 | 159 | id: Identifier.create("lite"), | 157 | 160 | userID: userID, | 158 | 161 | }) | | 162 | + | | 163 | + if (userEmail && coupon === LiteData.firstMonth100Coupon) { | | 164 | + await Billing.redeemCoupon(userEmail, "GOFREEMONTH") | | 165 | + } | 159 | 166 | }) | 160 | 167 | }) | 161 | 168 | } | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/app/src/routes/workspace/[id]/billing/index.tsx +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -25,9 +25,9 @@ export default function () { | 25 | 25 | <Show when={billingInfo()?.customerID}> | 26 | 26 | <ReloadSection /> | 27 | 27 | <MonthlyLimitSection /> | | 28 | + <RedeemSection /> | 28 | 29 | <PaymentSection /> | 29 | 30 | </Show> | 30 | | - <RedeemSection /> | 31 | 31 | </Show> | 32 | 32 | </div> | 33 | 33 | </div> | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/src/billing.ts +19-4Lines changed: 19 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { Stripe } from "stripe" | 2 | | -import { and, Database, eq, sql } from "./drizzle" | | 2 | +import { and, Database, eq, isNull, sql } from "./drizzle" | 3 | 3 | import { | 4 | 4 | BillingTable, | 5 | 5 | CouponTable, | @@ -176,6 +176,16 @@ export namespace Billing { | 176 | 176 | ) | 177 | 177 | } | 178 | 178 |
| | 179 | + export const hasCoupon = async (email: string, type: (typeof CouponType)[number]) => { | | 180 | + return await Database.use((tx) => | | 181 | + tx | | 182 | + .select() | | 183 | + .from(CouponTable) | | 184 | + .where(and(eq(CouponTable.email, email), eq(CouponTable.type, type), isNull(CouponTable.timeRedeemed))) | | 185 | + .then((rows) => rows.length > 0), | | 186 | + ) | | 187 | + } | | 188 | + | 179 | 189 | export const setMonthlyLimit = fn(z.number(), async (input) => { | 180 | 190 | return await Database.use((tx) => | 181 | 191 | tx | @@ -274,16 +284,19 @@ export namespace Billing { | 274 | 284 | const user = Actor.assert("user") | 275 | 285 | const { successUrl, cancelUrl, method } = input | 276 | 286 |
| 277 | | - const email = await User.getAuthEmail(user.properties.userID) | | 287 | + const email = (await User.getAuthEmail(user.properties.userID))! | 278 | 288 | const billing = await Billing.get() | 279 | 289 |
| 280 | 290 | if (billing.subscriptionID) throw new Error("Already subscribed to Black") | 281 | 291 | if (billing.liteSubscriptionID) throw new Error("Already subscribed to Lite") | 282 | 292 |
| | 293 | + const coupon = (await Billing.hasCoupon(email, "GOFREEMONTH")) | | 294 | + ? LiteData.firstMonth100Coupon | | 295 | + : LiteData.firstMonth50Coupon | 283 | 296 | const createSession = () => | 284 | 297 | Billing.stripe().checkout.sessions.create({ | 285 | 298 | mode: "subscription", | 286 | | - discounts: [{ coupon: LiteData.firstMonthCoupon(email!) }], | | 299 | + discounts: [{ coupon }], | 287 | 300 | ...(billing.customerID | 288 | 301 | ? { | 289 | 302 | customer: billing.customerID, | @@ -293,7 +306,7 @@ export namespace Billing { | 293 | 306 | }, | 294 | 307 | } | 295 | 308 | : { | 296 | | - customer_email: email!, | | 309 | + customer_email: email, | 297 | 310 | }), | 298 | 311 | ...(() => { | 299 | 312 | if (method === "alipay") { | @@ -341,6 +354,8 @@ export namespace Billing { | 341 | 354 | metadata: { | 342 | 355 | workspaceID: Actor.workspace(), | 343 | 356 | userID: user.properties.userID, | | 357 | + userEmail: email, | | 358 | + coupon, | 344 | 359 | type: "lite", | 345 | 360 | }, | 346 | 361 | }, | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/src/lite.ts +2-6Lines changed: 2 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,11 +11,7 @@ export namespace LiteData { | 11 | 11 | export const productID = fn(z.void(), () => Resource.ZEN_LITE_PRICE.product) | 12 | 12 | export const priceID = fn(z.void(), () => Resource.ZEN_LITE_PRICE.price) | 13 | 13 | export const priceInr = fn(z.void(), () => Resource.ZEN_LITE_PRICE.priceInr) | 14 | | - export const firstMonthCoupon = fn(z.string(), (email) => { | 15 | | - const invitees = Resource.ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES.value.split(",") | 16 | | - return invitees.includes(email) | 17 | | - ? Resource.ZEN_LITE_PRICE.firstMonth100Coupon | 18 | | - : Resource.ZEN_LITE_PRICE.firstMonth50Coupon | 19 | | - }) | | 14 | + export const firstMonth100Coupon = Resource.ZEN_LITE_PRICE.firstMonth100Coupon | | 15 | + export const firstMonth50Coupon = Resource.ZEN_LITE_PRICE.firstMonth50Coupon | 20 | 16 | export const planName = fn(z.void(), () => "lite") | 21 | 17 | } |
Collapse file Copy file name to clipboardExpand all lines: packages/console/core/sst-env.d.ts -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,10 +142,6 @@ declare module "sst" { | 142 | 142 | "type": "sst.sst.Secret" | 143 | 143 | "value": string | 144 | 144 | } | 145 | | - "ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES": { | 146 | | - "type": "sst.sst.Secret" | 147 | | - "value": string | 148 | | - } | 149 | 145 | "ZEN_LITE_PRICE": { | 150 | 146 | "firstMonth100Coupon": string | 151 | 147 | "firstMonth50Coupon": string | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/function/sst-env.d.ts -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,10 +142,6 @@ declare module "sst" { | 142 | 142 | "type": "sst.sst.Secret" | 143 | 143 | "value": string | 144 | 144 | } | 145 | | - "ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES": { | 146 | | - "type": "sst.sst.Secret" | 147 | | - "value": string | 148 | | - } | 149 | 145 | "ZEN_LITE_PRICE": { | 150 | 146 | "firstMonth100Coupon": string | 151 | 147 | "firstMonth50Coupon": string | |
Collapse file Copy file name to clipboardExpand all lines: packages/console/resource/sst-env.d.ts -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,10 +142,6 @@ declare module "sst" { | 142 | 142 | "type": "sst.sst.Secret" | 143 | 143 | "value": string | 144 | 144 | } | 145 | | - "ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES": { | 146 | | - "type": "sst.sst.Secret" | 147 | | - "value": string | 148 | | - } | 149 | 145 | "ZEN_LITE_PRICE": { | 150 | 146 | "firstMonth100Coupon": string | 151 | 147 | "firstMonth50Coupon": string | |
Collapse file Copy file name to clipboardExpand all lines: packages/enterprise/sst-env.d.ts -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,10 +142,6 @@ declare module "sst" { | 142 | 142 | "type": "sst.sst.Secret" | 143 | 143 | "value": string | 144 | 144 | } | 145 | | - "ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES": { | 146 | | - "type": "sst.sst.Secret" | 147 | | - "value": string | 148 | | - } | 149 | 145 | "ZEN_LITE_PRICE": { | 150 | 146 | "firstMonth100Coupon": string | 151 | 147 | "firstMonth50Coupon": string | |
Collapse file Copy file name to clipboardExpand all lines: packages/function/sst-env.d.ts -4Lines changed: 0 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -142,10 +142,6 @@ declare module "sst" { | 142 | 142 | "type": "sst.sst.Secret" | 143 | 143 | "value": string | 144 | 144 | } | 145 | | - "ZEN_LITE_COUPON_FIRST_MONTH_100_INVITEES": { | 146 | | - "type": "sst.sst.Secret" | 147 | | - "value": string | 148 | | - } | 149 | 145 | "ZEN_LITE_PRICE": { | 150 | 146 | "firstMonth100Coupon": string | 151 | 147 | "firstMonth50Coupon": string | |
|