Skip to content

An open-source, faster Devin alternative

TypeScript

billing: no trial warning until Autumn has a trial plan; clear the wrong ones

Mohamed Habib via Computera6a05e138249
diff --git a/cloudflare-workers/api-edge/migrations/0018_orgs_clear_trial_minutes_warning.sql b/cloudflare-workers/api-edge/migrations/0018_orgs_clear_trial_minutes_warning.sql
new file mode 100644
index 00000000..e456fde4
--- /dev/null
+++ b/cloudflare-workers/api-edge/migrations/0018_orgs_clear_trial_minutes_warning.sql
@@ -0,0 +1,6 @@
+-- orgs.billing_warning (serverless-agents-ws 086): until Autumn has a trial
+-- plan, a new signup has no work-minutes balance, and billingWarning read that
+-- as 0 minutes left, so new orgs were told their trial had 0 min of work left.
+-- No org can have a real trial_minutes warning before the trial plan exists, so
+-- clear them all; the next projection sets the right warning, if any.
+UPDATE orgs SET billing_warning = NULL, billing_warning_at = NULL WHERE billing_warning = 'trial_minutes';
diff --git a/cloudflare-workers/api-edge/src/autumn_webhook.test.ts b/cloudflare-workers/api-edge/src/autumn_webhook.test.ts
index f9dabbc6..1186d683 100644
--- a/cloudflare-workers/api-edge/src/autumn_webhook.test.ts
+++ b/cloudflare-workers/api-edge/src/autumn_webhook.test.ts
@@ -565,6 +565,11 @@ describe("warnings before the stop", () => {
});
const fresh = { trialStartedAt: now - day, paymentPastDueAt: null };
+ it("does not warn a new signup until Autumn has a trial plan", () => {
+ expect(billingWarning(customer(["base"], { credits: 10 }), fresh, now)).toBeNull();
+ expect(billingWarning(customer(["base"], { credits: 10 }), { ...fresh, trialStartedAt: now - 6 * day }, now)).toBeNull();
+ });
+
it("warns a trial at 480 minutes, 2 days left or $8 spent", () => {
expect(billingWarning(customer(["trial"], { minutes: 121, credits: 2.5 }), fresh, now)).toBeNull();
expect(billingWarning(customer(["trial"], { minutes: 120, credits: 5 }), fresh, now)).toBe("trial_minutes");
diff --git a/cloudflare-workers/api-edge/src/autumn_webhook.ts b/cloudflare-workers/api-edge/src/autumn_webhook.ts
index a03d73e4..814cd4e9 100644
--- a/cloudflare-workers/api-edge/src/autumn_webhook.ts
+++ b/cloudflare-workers/api-edge/src/autumn_webhook.ts
@@ -740,8 +740,10 @@ export function billingWarning(
if (plan !== "base" && org.paymentPastDueAt != null) return "payment_failed";
const credits = customer.balances?.[CREDITS_FEATURE_ID]?.remaining ?? 0;
const minutesBalance = customer.balances?.[WORK_MINUTES_FEATURE_ID];
- if (minutesBalance === undefined && org.trialStartedAt == null) return null;
- const minutes = minutesBalance?.remaining ?? 0;
+ // No minutes balance means Autumn has no trial plan for the org yet, so it is
+ // on the credit rule like haltReason says, whatever trial_started_at holds.
+ if (minutesBalance === undefined) return null;
+ const minutes = minutesBalance.remaining ?? 0;
if (plan !== "base") {
const allowance = PLAN_WORK_MINUTES[plan];