billing

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2026 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultTrialConfig = TrialConfig{
	Enabled:       false,
	DurationDays:  3,
	MaxMembers:    3,
	MaxWorkspaces: 1,
}

DefaultTrialConfig is the default trial configuration (D13: off by default).

View Source
var PlanTiers = map[types.OrgPlan]PlanFeatures{
	types.PlanFree: {
		MaxWorkspaces:     1,
		MaxMembers:        1,
		CustomCredentials: true,
	},
	types.PlanTeam: {
		MaxWorkspaces:     10,
		MaxMembers:        25,
		CustomCredentials: true,
	},
	types.PlanBusiness: {
		MaxWorkspaces:     50,
		MaxMembers:        100,
		PoliciesEnabled:   true,
		AuditLogEnabled:   true,
		CustomCredentials: true,
	},
	types.PlanEnterprise: {
		MaxWorkspaces:     -1,
		MaxMembers:        -1,
		SSOEnabled:        true,
		PoliciesEnabled:   true,
		AuditLogEnabled:   true,
		CustomCredentials: true,
	},
}

PlanTiers maps each internal plan ID to its feature set. Hardcoded — extend this map when adding a new plan tier.

Functions

func IsFeatureAllowed

func IsFeatureAllowed(plan types.OrgPlan, feature string) bool

IsFeatureAllowed checks whether a plan tier permits a specific feature.

Types

type BillingProvider

type BillingProvider interface {
	ReportUsage(ctx context.Context, events []UsageExportEvent) (reportedIDs []int64, err error)
	CreateCustomer(ctx context.Context, ownerID, ownerType, email string) (externalID string, err error)
	SuspendCustomer(ctx context.Context, externalID string) error
}

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 (n *NoopBillingProvider) CreateCustomer(_ context.Context, ownerID, _, _ string) (string, error)

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 (n *NoopCheckoutProvider) ConstructWebhookEvent(_ []byte, _ string) (stripe.Event, error)

func (*NoopCheckoutProvider) CreateCheckoutSession

func (n *NoopCheckoutProvider) CreateCheckoutSession(_ context.Context, _, planID, _, _ string) (string, error)

func (*NoopCheckoutProvider) CreateCustomer

func (n *NoopCheckoutProvider) CreateCustomer(_ context.Context, _, name string) (string, error)

func (*NoopCheckoutProvider) CreatePortalSession

func (n *NoopCheckoutProvider) CreatePortalSession(_ context.Context, _, _ string) (string, error)

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"`
}

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 (s *StripeProvider) ConstructWebhookEvent(payload []byte, signature string) (stripe.Event, error)

func (*StripeProvider) CreateCheckoutSession

func (s *StripeProvider) CreateCheckoutSession(ctx context.Context, customerID, planID, successURL, cancelURL string) (string, error)

func (*StripeProvider) CreateCustomer

func (s *StripeProvider) CreateCustomer(_ context.Context, email, name string) (string, error)

func (*StripeProvider) CreatePortalSession

func (s *StripeProvider) CreatePortalSession(ctx context.Context, customerID, returnURL string) (string, error)

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).

type TrialConfig

type TrialConfig struct {
	Enabled       bool `json:"enabled"`
	DurationDays  int  `json:"durationDays"`
	MaxMembers    int  `json:"maxMembers"`
	MaxWorkspaces int  `json:"maxWorkspaces"`
}

TrialConfig holds configurable trial parameters per D13.

type UsageExportEvent

type UsageExportEvent struct {
	ExternalCustomerID string
	EventType          string
	Quantity           int64
	Timestamp          string
	IdempotencyKey     string
	Properties         map[string]string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL