Skip to content

Commit

Permalink
Early adopter coupon (#2704)
Browse files Browse the repository at this point in the history
* Early adopter coupon

* fix coupon viz
  • Loading branch information
chitalian authored Oct 1, 2024
1 parent a0c9d15 commit c9c4ebd
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 25 deletions.
6 changes: 6 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -12032,6 +12032,11 @@
"properties": {
"coupon": {
"properties": {
"amount_off": {
"type": "number",
"format": "double",
"nullable": true
},
"percent_off": {
"type": "number",
"format": "double",
Expand All @@ -12043,6 +12048,7 @@
}
},
"required": [
"amount_off",
"percent_off",
"name"
],
Expand Down
2 changes: 2 additions & 0 deletions helicone-node/api/generatedTypes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4344,6 +4344,8 @@ export interface operations {
subtotal: number;
discount: ({
coupon: {
/** Format: double */
amount_off: number | null;
/** Format: double */
percent_off: number | null;
name: string | null;
Expand Down
19 changes: 9 additions & 10 deletions valhalla/jawn/src/controllers/public/stripeController.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import {
Controller,
Route,
Tags,
Security,
Post,
Body,
Request,
Get,
Controller,
Delete,
Get,
Path,
Post,
Request,
Route,
Security,
Tags,
} from "tsoa";
import Stripe from "stripe";
import { JawnAuthenticatedRequest } from "../../types/request";
import { StripeManager } from "../../managers/stripe/StripeManager";
import { Result } from "../../lib/shared/result";
import { JawnAuthenticatedRequest } from "../../types/request";

export interface UpgradeToProRequest {
addons?: {
Expand Down Expand Up @@ -163,6 +161,7 @@ export class StripeController extends Controller {
coupon: {
name: string | null;
percent_off: number | null;
amount_off: number | null;
};
} | null;
subtotal: number;
Expand Down
15 changes: 9 additions & 6 deletions valhalla/jawn/src/managers/organization/OrganizationManager.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ENVIRONMENT } from "../..";
import { Database } from "../../lib/db/database.types";
import { AuthParams, supabaseServer } from "../../lib/db/supabase";
import { ok, err, Result } from "../../lib/shared/result";
Expand Down Expand Up @@ -369,12 +370,14 @@ export class OrganizationManager extends BaseManager {
if (membersError !== null) {
return err(membersError);
}
return ok(
members.filter(
(member) =>
!filterHeliconeEmails || !member.email.endsWith("@helicone.ai")
).length
);
if (filterHeliconeEmails && ENVIRONMENT === "production") {
return ok(
members.filter((member) => !member.email.endsWith("@helicone.ai"))
.length
);
} else {
return ok(members.length);
}
}

async getOrganizationMembers(
Expand Down
7 changes: 1 addition & 6 deletions valhalla/jawn/src/managers/stripe/StripeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,9 @@ WHERE (${builtFilter.filter})`,
tier: "pro-20240913",
},
},
allow_promotion_codes: true,
};

if (this.shouldApplyCoupon()) {
sessionParams.discounts = [{ coupon: EARLY_ADOPTER_COUPON }];
} else {
sessionParams.allow_promotion_codes = true;
}

const session = await this.stripe.checkout.sessions.create(sessionParams);

return ok(session.url!);
Expand Down
6 changes: 6 additions & 0 deletions valhalla/jawn/src/tsoa-build/private/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -11468,6 +11468,11 @@
"properties": {
"coupon": {
"properties": {
"amount_off": {
"type": "number",
"format": "double",
"nullable": true
},
"percent_off": {
"type": "number",
"format": "double",
Expand All @@ -11479,6 +11484,7 @@
}
},
"required": [
"amount_off",
"percent_off",
"name"
],
Expand Down
6 changes: 6 additions & 0 deletions valhalla/jawn/src/tsoa-build/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -12032,6 +12032,11 @@
"properties": {
"coupon": {
"properties": {
"amount_off": {
"type": "number",
"format": "double",
"nullable": true
},
"percent_off": {
"type": "number",
"format": "double",
Expand All @@ -12043,6 +12048,7 @@
}
},
"required": [
"amount_off",
"percent_off",
"name"
],
Expand Down
15 changes: 12 additions & 3 deletions web/components/templates/organization/plan/InvoiceSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,18 @@ export const InvoiceSheet: React.FC = () => {
{upcomingInvoice.data.data.discount && (
<div className="border-t pt-4">
<h3 className="font-semibold mb-2">Discount:</h3>
<div className="text-sm">
{upcomingInvoice.data.data.discount.coupon.name} -
{upcomingInvoice.data.data.discount.coupon.percent_off}% off
<div className="text-sm flex items-center gap-2 justify-between">
<span className="">
{upcomingInvoice.data.data.discount.coupon.name}
</span>
<span>
{upcomingInvoice.data.data.discount.coupon.amount_off
? `$${
upcomingInvoice.data.data.discount.coupon
.amount_off / 100
} off`
: `${upcomingInvoice.data.data.discount.coupon.percent_off}% off`}
</span>
</div>
</div>
)}
Expand Down
2 changes: 2 additions & 0 deletions web/lib/clients/jawnTypes/private.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4115,6 +4115,8 @@ export interface operations {
subtotal: number;
discount: ({
coupon: {
/** Format: double */
amount_off: number | null;
/** Format: double */
percent_off: number | null;
name: string | null;
Expand Down
2 changes: 2 additions & 0 deletions web/lib/clients/jawnTypes/public.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4344,6 +4344,8 @@ export interface operations {
subtotal: number;
discount: ({
coupon: {
/** Format: double */
amount_off: number | null;
/** Format: double */
percent_off: number | null;
name: string | null;
Expand Down

0 comments on commit c9c4ebd

Please sign in to comment.