Phase 5 billing: account-based annual sub + tag SKUs + SMS pool + tag lifecycle

- Schema: plans, orders subscription cols + plan_id + period_started_at,
  billing_events log, users.stripe_id + sms_credits, products.price_aud
  (db/schema.sql + Laravel migration, idempotent)
- Laravel/Cashier: Billable User, checkout (annual sub + one-off SKUs with
  Managed Payments tax_code), webhook controller (signature-verified,
  idempotent, BILLING_ENABLED kill-switch), account tag transitions,
  nightly reconcile, Stripe portal link, PlanResource + billing dashboard
- Go frontend: account-level gating (paid sub required), SMS pool
  (included 50/yr + credits, drawn after included), plan caps replace
  constants, 60s plan cache (credits fresh), 25-tag cap (plan max_tags)
- BillingSeeder: personal plan + 3 SKUs + dev paid orders
- Verified test-mode e2e: subscribe/paid/active/alerts, pool exhaust +
  credits resume, lapsed/suspended, cancelled/closed, recover/active,
  webhook idempotency, 25-cap, one-off SKUs, replacement, kill-switch,
  invalid signature 400
This commit is contained in:
2026-08-28 13:19:32 +10:00
parent 43ce4514c4
commit aabaa750f4
43 changed files with 2679 additions and 341 deletions

View File

@@ -8,14 +8,43 @@ import (
"github.com/jackc/pgx/v5/pgtype"
)
type BillingEvent struct {
ID int64 `json:"id"`
StripeEventID string `json:"stripe_event_id"`
EventType string `json:"event_type"`
OrderID pgtype.Int8 `json:"order_id"`
Payload []byte `json:"payload"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
}
type Order struct {
ID int64 `json:"id"`
AccountID pgtype.Int8 `json:"account_id"`
Status string `json:"status"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Amount pgtype.Numeric `json:"amount"`
RenewsAt pgtype.Timestamptz `json:"renews_at"`
ID int64 `json:"id"`
AccountID pgtype.Int8 `json:"account_id"`
Status string `json:"status"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
Amount pgtype.Numeric `json:"amount"`
RenewsAt pgtype.Timestamptz `json:"renews_at"`
StripeID pgtype.Text `json:"stripe_id"`
PmType pgtype.Text `json:"pm_type"`
PmLastFour pgtype.Text `json:"pm_last_four"`
TrialEndsAt pgtype.Timestamptz `json:"trial_ends_at"`
PlanID pgtype.Int8 `json:"plan_id"`
PeriodStartedAt pgtype.Timestamptz `json:"period_started_at"`
}
type Plan struct {
ID int64 `json:"id"`
PlanType string `json:"plan_type"`
Name string `json:"name"`
PriceAud pgtype.Numeric `json:"price_aud"`
BillingInterval string `json:"billing_interval"`
SmsIncluded int32 `json:"sms_included"`
MaxTags int32 `json:"max_tags"`
AlertsPerDay int32 `json:"alerts_per_day"`
AlertsPerHour int32 `json:"alerts_per_hour"`
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
}
type Product struct {
@@ -26,6 +55,7 @@ type Product struct {
CreatedAt pgtype.Timestamptz `json:"created_at"`
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
PhotoUrl pgtype.Text `json:"photo_url"`
PriceAud pgtype.Numeric `json:"price_aud"`
}
type Scan struct {
@@ -78,4 +108,6 @@ type User struct {
IsAdmin bool `json:"is_admin"`
RememberToken pgtype.Text `json:"remember_token"`
Paused bool `json:"paused"`
StripeID pgtype.Text `json:"stripe_id"`
SmsCredits int32 `json:"sms_credits"`
}