An open-source, faster Devin alternative
TypeScript
billing: don't halt new signups before the trial plan is in Autumn
Mohamed Habib via Computerca295cff3fbe
diff --git a/cloudflare-workers/api-edge/src/autumn_webhook.test.ts b/cloudflare-workers/api-edge/src/autumn_webhook.test.tsindex a806d832..d5ed9496 100644--- a/cloudflare-workers/api-edge/src/autumn_webhook.test.ts+++ b/cloudflare-workers/api-edge/src/autumn_webhook.test.ts@@ -461,6 +461,11 @@ describe("halt rules", () => {expect(haltReason(customer(["max"], { credits: 0 }), org, now)).toBe("credits_exhausted");});+ it("keeps a new signup on the credit rule until Autumn has a trial plan", () => {+ expect(haltReason(customer(["base"], { credits: 10 }), fresh, now)).toBeNull();+ expect(haltReason(customer(["base"], { credits: 0 }), fresh, now)).toBe("credits_exhausted");+ });+it("ends the trial at day 7, 600 minutes or the token credit", () => {expect(haltReason(customer(["trial"], { minutes: 100, credits: 5 }), fresh, now)).toBeNull();expect(diff --git a/cloudflare-workers/api-edge/src/autumn_webhook.ts b/cloudflare-workers/api-edge/src/autumn_webhook.tsindex 7c865cd2..93aa703d 100644--- a/cloudflare-workers/api-edge/src/autumn_webhook.ts+++ b/cloudflare-workers/api-edge/src/autumn_webhook.ts@@ -656,8 +656,9 @@ function hasActiveSubscription(customer: AutumnCustomer, planID: string): boolea}// haltReason decides whether an org is halted, and why. An org is on work-// minutes once Autumn shows a work_minutes balance or the edge recorded its-// trial; every other org keeps the credit rule until it is migrated (step 8).+// minutes once Autumn shows a work_minutes balance; every other org keeps the+// credit rule until it is migrated (step 8). trial_started_at alone is not+// enough: signup stamps it even when the Autumn catalog has no trial plan yet.export function haltReason(customer: AutumnCustomer,org: { trialStartedAt: number | null; paymentPastDueAt: number | null },@@ -665,7 +666,7 @@ export function haltReason(): HaltReason | null {const credits = customer.balances?.[CREDITS_FEATURE_ID]?.remaining ?? 0;const minutesBalance = customer.balances?.[WORK_MINUTES_FEATURE_ID];- if (minutesBalance === undefined && org.trialStartedAt == null) {+ if (minutesBalance === undefined) {return credits <= 0 ? "credits_exhausted" : null;}const minutes = minutesBalance?.remaining ?? 0;