Detect paid plans from Autumn entitlement flags (#482)

This commit is contained in:
Ben Senescu 2026-08-12 11:35:07 -04:00 committed by GitHub
parent a1ed6ece4b
commit 75aec8424f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 11 deletions

View File

@ -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");
});
});

View File

@ -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<string, unknown> } | 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";
}