Documentation
¶
Overview ¶
Package grant implements manual subscription grants — used for gifting Pro subscriptions, comp'ing beta users, and admin overrides.
A grant creates an active subscription directly, bypassing payment flow. The subscription is marked with ProviderType="manual_gift" and the supplied reason is stored in metadata.
This package deliberately has no HTTP surface — it is consumed by the cmd/grant CLI (and future admin tooling) and tested directly against an in-memory datastore.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrInvalidUser = errors.New("grant: invalid user id")
ErrInvalidUser is returned when the user identifier is missing or malformed.
var ErrPlanNotFound = errors.New("grant: plan not found")
ErrPlanNotFound is returned when the requested plan slug does not exist in the catalog or in the org's datastore.
Functions ¶
This section is empty.
Types ¶
type CatalogPlan ¶
type CatalogPlan struct {
Slug string
Name string
Description string
PriceCents int64
Currency string // e.g. "usd"
}
CatalogPlan is the catalog projection used by Grant for seeding missing plans into the org datastore.
type PlanCatalog ¶
type PlanCatalog interface {
Lookup(slug string) *CatalogPlan
}
PlanCatalog is the minimal interface into the static plan catalog. The CLI passes billing.LookupStaticPlan; tests pass a map-backed fake.
type Request ¶
type Request struct {
// UserId is the IAM subject — typically "owner/name" format.
UserId string
// PlanSlug is the plan slug (e.g. "world-pro").
PlanSlug string
// Duration specifies how long the subscription lasts. Defaults to 12 months
// when zero.
Duration time.Duration
// Reason is a short operator-supplied description (e.g. "beta gift").
// Stored in subscription.Metadata for audit.
Reason string
// GrantedBy is the operator identifier (email or name) for audit.
GrantedBy string
}
Request captures the parameters for a manual grant.
type Result ¶
type Result struct {
SubscriptionID string
PlanSlug string
UserId string
PeriodEnd time.Time
Reason string
GrantedBy string
}
Result describes what the grant produced.
func Grant ¶
func Grant(ctx context.Context, db *datastore.Datastore, catalog PlanCatalog, req Request) (*Result, error)
Grant creates a manual subscription for the given user on the given plan.
The operation is idempotent per (UserId, PlanSlug): if an active manual grant already exists, it is extended rather than duplicated.
The caller supplies an org-scoped datastore (db) and a catalog lookup. Plan records are seeded into the org's datastore on first use so the subscription can reference them by Id.