Phase 14, part 1: plans, each team's account, and their limits

The multi-tenant edition's plans (Free and Paid as decided, or a plans
file) and each team's billing account, with a 14-day trial of Paid. A
team's plan caps what its people and agents may change: modules outside it
stay readable, a lapsed team changes nothing, and agents, Market entries,
crawls and background jobs keep to it. Without a Stripe key, no billing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 13:15:00 -07:00
co-authored by Claude Opus 5.5
parent e47764a78e
commit a47990f9bf
19 changed files with 848 additions and 7 deletions
+30
View File
@@ -98,6 +98,13 @@ type Config struct {
// PlatformAdmins are the email addresses of the people running the
// multi-tenant service (its /platform area).
PlatformAdmins []string
// Billing (multi-tenant): the platform's own Stripe account; empty, no
// billing (every team has everything).
StripeKey, StripeWebhookSecret string
StripePrice, StripePriceYear string // per person, a month and a year
StripePriceStorage string // an extra storage block, a month
PlansFile string // the plans, if not the defaults
}
// Environment variables.
@@ -121,6 +128,12 @@ const (
EnvMailFrom = "SUPERMARKET_MAIL_FROM"
EnvPGBackups = "SUPERMARKET_PG_BACKUPS"
EnvPlatform = "SUPERMARKET_PLATFORM_ADMINS"
EnvStripeKey = "SUPERMARKET_STRIPE_KEY"
EnvStripeHook = "SUPERMARKET_STRIPE_WEBHOOK_SECRET"
EnvStripePrice = "SUPERMARKET_STRIPE_PRICE"
EnvStripeYear = "SUPERMARKET_STRIPE_PRICE_YEAR"
EnvStripeStore = "SUPERMARKET_STRIPE_PRICE_STORAGE"
EnvPlans = "SUPERMARKET_PLANS"
)
// Load reads the settings through getenv (os.Getenv) and checks them. All
@@ -229,6 +242,23 @@ func Load(getenv func(string) string) (*Config, error) {
bad("%s is for the multi-tenant edition", EnvPlatform)
}
// Billing.
c.StripeKey, c.StripeWebhookSecret = get(EnvStripeKey, ""), get(EnvStripeHook, "")
c.StripePrice, c.StripePriceYear, c.StripePriceStorage = get(EnvStripePrice, ""), get(EnvStripeYear, ""), get(EnvStripeStore, "")
c.PlansFile = get(EnvPlans, "")
if c.StripeKey != "" {
switch {
case c.Edition != Multi:
bad("%s is for the multi-tenant edition: it bills its teams", EnvStripeKey)
case !strings.HasPrefix(c.StripeKey, "sk_") && !strings.HasPrefix(c.StripeKey, "rk_"):
bad("%s isn't a Stripe secret key (sk_…)", EnvStripeKey)
case c.StripeWebhookSecret == "":
bad("%s is needed with %s: the webhook's signing secret (whsec_…), from Stripe's dashboard", EnvStripeHook, EnvStripeKey)
case c.StripePrice == "" && c.PlansFile == "":
bad("%s is needed with %s: the paid plan's price per person a month (price_…)", EnvStripePrice, EnvStripeKey)
}
}
if len(problems) > 0 {
return c, errors.New(strings.Join(problems, "\n"))
}