Files
commerce/models/fixtures/subscription.go
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

43 lines
1.4 KiB
Go

package fixtures
import (
"time"
"github.com/hanzoai/commerce/billing/trial"
"github.com/hanzoai/commerce/models/subscription"
"github.com/zap-proto/zip"
)
// ProSubscription gives the fixture org a current pro subscription, so the
// billing paywall admits it.
//
// billing/paywall gates the admin APIs behind one of three unlocks — a pro
// subscription, a live trial credit, or a redeemed invite — and correctly
// offers no test bypass. Without one of them every API suite gets 402
// subscription_required, which is the paywall working, not a bug in the suite.
//
// A subscription is the unlock chosen here because it is the state a paying
// customer is actually in: trial credit expires and an invite is a one-off, so
// either would make the suites model an edge case while claiming to exercise
// the ordinary path.
//
// Status Active with PeriodEnd in the future is what paywall.hasSubscription
// looks for, and PlanId must be trial.PlanSlug — the gate matches on the plan
// slug, so a subscription to any other plan does not unlock anything.
var ProSubscription = New("pro-subscription", func(c *zip.Ctx) *subscription.Subscription {
db := getNamespaceDb(c)
now := time.Now()
sub := subscription.New(db)
sub.GetOrCreate("PlanId=", trial.PlanSlug)
sub.PlanId = trial.PlanSlug
sub.Status = subscription.Active
sub.PeriodStart = now.Add(-Month)
sub.PeriodEnd = now.Add(Month)
sub.MustPut()
return sub
})