From 75aec8424f3380903d445c0479c5723997fdc218 Mon Sep 17 00:00:00 2001 From: Ben Senescu <44480372+bensenescu@users.noreply.github.com> Date: Wed, 12 Aug 2026 11:35:07 -0400 Subject: [PATCH] Detect paid plans from Autumn entitlement flags (#482) --- .../features/billing/plan-detection.test.ts | 22 +++++++++++++++++++ src/client/features/billing/plan-detection.ts | 14 +++--------- 2 files changed, 25 insertions(+), 11 deletions(-) create mode 100644 src/client/features/billing/plan-detection.test.ts diff --git a/src/client/features/billing/plan-detection.test.ts b/src/client/features/billing/plan-detection.test.ts new file mode 100644 index 0000000..d8bc9d3 --- /dev/null +++ b/src/client/features/billing/plan-detection.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from "vitest"; +import { AUTUMN_PAID_PLAN_FEATURE_ID } from "@/shared/billing"; +import { getCustomerPlanStatus } from "./plan-detection"; + +describe("getCustomerPlanStatus", () => { + it("treats a customer without the paid entitlement as free", () => { + expect(getCustomerPlanStatus(undefined)).toBe("free"); + expect(getCustomerPlanStatus({ flags: {} })).toBe("free"); + }); + + it("treats any plan granting the paid entitlement as paid", () => { + expect( + getCustomerPlanStatus({ + flags: { + [AUTUMN_PAID_PLAN_FEATURE_ID]: { + planId: "friends_and_family_2", + }, + }, + }), + ).toBe("paid"); + }); +}); diff --git a/src/client/features/billing/plan-detection.ts b/src/client/features/billing/plan-detection.ts index f0b3199..668e68e 100644 --- a/src/client/features/billing/plan-detection.ts +++ b/src/client/features/billing/plan-detection.ts @@ -1,17 +1,9 @@ -import { AUTUMN_PAID_PLAN_ID } from "@/shared/billing"; +import { AUTUMN_PAID_PLAN_FEATURE_ID } from "@/shared/billing"; export type PlanStatus = "free" | "paid"; export function getCustomerPlanStatus( - customer: - | { subscriptions?: Array<{ planId: string; status: string }> } - | undefined, + customer: { flags?: Record } | undefined, ): PlanStatus { - if (!customer?.subscriptions) return "free"; - - const hasActivePaid = customer.subscriptions.some( - (sub) => sub.planId === AUTUMN_PAID_PLAN_ID && sub.status === "active", - ); - - return hasActivePaid ? "paid" : "free"; + return customer?.flags?.[AUTUMN_PAID_PLAN_FEATURE_ID] ? "paid" : "free"; }