Documentation
¶
Index ¶
- Variables
- func IsFeatureAllowed(plan types.OrgPlan, feature string) bool
- type BillingProvider
- type CheckoutProvider
- type NoopBillingProvider
- type NoopCheckoutProvider
- func (n *NoopCheckoutProvider) ConstructWebhookEvent(_ []byte, _ string) (stripe.Event, error)
- func (n *NoopCheckoutProvider) CreateCheckoutSession(_ context.Context, _, planID, _, _ string) (string, error)
- func (n *NoopCheckoutProvider) CreateCustomer(_ context.Context, _, name string) (string, error)
- func (n *NoopCheckoutProvider) CreatePortalSession(_ context.Context, _, _ string) (string, error)
- type PlanFeatures
- type StripeConfig
- type StripeProvider
- func (s *StripeProvider) ConstructWebhookEvent(payload []byte, signature string) (stripe.Event, error)
- func (s *StripeProvider) CreateCheckoutSession(ctx context.Context, customerID, planID, successURL, cancelURL string) (string, error)
- func (s *StripeProvider) CreateCustomer(_ context.Context, email, name string) (string, error)
- func (s *StripeProvider) CreatePortalSession(ctx context.Context, customerID, returnURL string) (string, error)
- func (s *StripeProvider) ReportUsage(ctx context.Context, events []UsageExportEvent) ([]int64, error)
- func (s *StripeProvider) SuspendCustomer(_ context.Context, externalID string) error
- type TrialConfig
- type UsageExportEvent
Constants ¶
This section is empty.
Variables ¶
var DefaultTrialConfig = TrialConfig{ Enabled: false, DurationDays: 3, MaxMembers: 3, MaxWorkspaces: 1, }
DefaultTrialConfig is the default trial configuration (D13: off by default).
var PlanTiers = map[types.OrgPlan]PlanFeatures{ types.PlanFree: { MaxWorkspaces: 1, MaxMembers: 1, CustomCredentials: true, MaxPersonalMcpServers: 5, }, types.PlanTeam: { MaxWorkspaces: 10, MaxMembers: 25, CustomCredentials: true, MaxPersonalMcpServers: -1, }, types.PlanBusiness: { MaxWorkspaces: 50, MaxMembers: 100, PoliciesEnabled: true, AuditLogEnabled: true, CustomCredentials: true, MaxPersonalMcpServers: -1, }, types.PlanEnterprise: { MaxWorkspaces: -1, MaxMembers: -1, SSOEnabled: true, PoliciesEnabled: true, AuditLogEnabled: true, CustomCredentials: true, MaxPersonalMcpServers: -1, }, }
PlanTiers maps each internal plan ID to its feature set. Hardcoded — extend this map when adding a new plan tier.
Functions ¶
Types ¶
type BillingProvider ¶
type CheckoutProvider ¶
type CheckoutProvider interface {
CreateCustomer(ctx context.Context, email, name string) (string, error)
CreateCheckoutSession(ctx context.Context, customerID, planID, successURL, cancelURL string) (string, error)
CreatePortalSession(ctx context.Context, customerID, returnURL string) (string, error)
ConstructWebhookEvent(payload []byte, signature string) (stripe.Event, error)
}
CheckoutProvider creates Stripe Checkout and Customer Portal sessions and verifies webhook signatures. It is intentionally separate from BillingProvider (usage reporting) so callers depend only on what they need.
type NoopBillingProvider ¶
type NoopBillingProvider struct{}
func (*NoopBillingProvider) CreateCustomer ¶
func (*NoopBillingProvider) ReportUsage ¶
func (n *NoopBillingProvider) ReportUsage(_ context.Context, events []UsageExportEvent) ([]int64, error)
func (*NoopBillingProvider) SuspendCustomer ¶
func (n *NoopBillingProvider) SuspendCustomer(_ context.Context, _ string) error
type NoopCheckoutProvider ¶
type NoopCheckoutProvider struct{}
NoopCheckoutProvider is the dev/test CheckoutProvider. It never calls Stripe and returns deterministic placeholder values so the request path can be exercised without network access.
func (*NoopCheckoutProvider) ConstructWebhookEvent ¶
func (*NoopCheckoutProvider) CreateCheckoutSession ¶
func (*NoopCheckoutProvider) CreateCustomer ¶
func (*NoopCheckoutProvider) CreatePortalSession ¶
type PlanFeatures ¶
type PlanFeatures struct {
MaxWorkspaces int `json:"maxWorkspaces"`
MaxMembers int `json:"maxMembers"`
SSOEnabled bool `json:"ssoEnabled"`
PoliciesEnabled bool `json:"policiesEnabled"`
AuditLogEnabled bool `json:"auditLogEnabled"`
CustomCredentials bool `json:"customCredentials"`
MaxPersonalMcpServers int `json:"maxPersonalMcpServers"` // 0=disabled, -1=unlimited, N=cap (Epic 53 D12)
}
PlanFeatures defines what a plan tier allows. Used for feature gating.
func GetPlanFeatures ¶
func GetPlanFeatures(plan types.OrgPlan) PlanFeatures
GetPlanFeatures returns the feature set for a plan, defaulting to Free.
type StripeConfig ¶
type StripeConfig struct {
SecretKey string
WebhookSecret string
// PlanPrices maps an internal plan id (e.g. "team") to a Stripe Price id.
PlanPrices map[string]string
// Meters maps a usage event type (e.g. "llm_tokens", "compute_seconds")
// to a Stripe subscription item id for Metered Billing.
Meters map[string]string
}
StripeConfig holds the credentials and price mapping for StripeProvider.
type StripeProvider ¶
type StripeProvider struct {
// contains filtered or unexported fields
}
StripeProvider implements CheckoutProvider and BillingProvider against the live Stripe API.
func NewStripeProvider ¶
func NewStripeProvider(cfg StripeConfig) (*StripeProvider, error)
NewStripeProvider sets the package-level stripe.Key and returns a provider. Returns an error if SecretKey is empty — callers should use NoopCheckoutProvider in that case.
func (*StripeProvider) ConstructWebhookEvent ¶
func (*StripeProvider) CreateCheckoutSession ¶
func (*StripeProvider) CreateCustomer ¶
func (*StripeProvider) CreatePortalSession ¶
func (*StripeProvider) ReportUsage ¶
func (s *StripeProvider) ReportUsage(ctx context.Context, events []UsageExportEvent) ([]int64, error)
ReportUsage reports usage events to Stripe Metered Billing. Each event maps to a Stripe usage record on the subscription item for the corresponding meter (llm_tokens or compute_seconds).
func (*StripeProvider) SuspendCustomer ¶
func (s *StripeProvider) SuspendCustomer(_ context.Context, externalID string) error
SuspendCustomer marks the Stripe customer as suspended (preserves data).