subscription

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package subscription registers the `safedep subscription` domain: the tenant's plan and access lifecycle - status, free trial, paid subscription, on-demand (overage) billing, and the billing portal. It is named for the user's intent (plan/access), not the billing mechanism; low-level billing detail (invoices, payment methods) is delegated to the provider portal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddOnTokens added in v0.5.0

func AddOnTokens() []string

AddOnTokens lists the selectable add-on tokens (every enum value except the unspecified zero), for command help and error messages.

func Register

func Register(root *cobra.Command, a *app.App)

Register wires the subscription command tree onto root.

Types

type AccountStatus

type AccountStatus struct {
	Status       string
	Tier         string
	Seats        int64      // effective seat count. Zero means no seat-based subscription.
	Interval     string     // tier billing cadence: "monthly" | "yearly" | ""
	ActiveAddOns []string   // purchased add-on tokens; entitlements cover manual grants separately
	Trial        *TrialInfo // set only when in an active trial
	Entitlements []string
	OnDemand     *OnDemandState // best-effort; nil if unavailable
	Endpoints    *EndpointUsage // best-effort; nil when the server omits it
}

type AddOnAttacher added in v0.5.0

type AddOnAttacher interface {
	// AttachAddOn purchases the add-on on the tenant's subscription and returns
	// the account's active add-on tokens after the change.
	AttachAddOn(ctx context.Context, addOn string, terms string) ([]string, error)
}

type AddOnDetacher added in v0.5.0

type AddOnDetacher interface {
	// DetachAddOn removes the add-on and returns the remaining active add-on
	// tokens.
	DetachAddOn(ctx context.Context, addOn string) ([]string, error)
}

type AssetClassUsage added in v0.6.0

type AssetClassUsage struct {
	DisplayName   string
	ActiveAssets  int64
	AssetsPerUnit int64
	Units         int64
}

AssetClassUsage is one asset class row of the endpoint usage breakdown. It is mandatory rendering data: the rows explain the units total.

type Catalog added in v0.6.0

type Catalog struct {
	Products []CatalogProduct
}

Catalog is the price catalog: list prices for every sellable product. The prices are the same for every tenant and carry no tenant-specific discount.

type CatalogGetter added in v0.6.0

type CatalogGetter interface {
	// Catalog returns the price catalog: list prices for sellable products.
	Catalog(ctx context.Context) (*Catalog, error)
}

type CatalogPrice added in v0.6.0

type CatalogPrice struct {
	UnitAmountMinor int64
	Currency        string
	Interval        string // "monthly" | "yearly" | ""
	Metered         bool
}

type CatalogProduct added in v0.6.0

type CatalogProduct struct {
	DisplayName string
	Kind        string // "subscription_tier" | "add_on" | "overage"
	AddOn       string // add-on token when Kind is "add_on", else ""
	PricingUnit string // selling unit ("seat", "scan"), empty for a flat product
	Prices      []CatalogPrice
}

type CheckoutInput

type CheckoutInput struct {
	Seats      uint32
	AddOns     []string // add-on tokens to buy alongside the seats
	SuccessURL string
	CancelURL  string
}

type CheckoutResult

type CheckoutResult struct {
	Outcome      string // checkoutSuccess | checkoutNeeded | checkoutError
	URL          string
	ErrorCode    string
	ErrorMessage string
}

type Customer

type Customer struct {
	ID      string
	Name    string
	Email   string
	Phone   string
	Country string
	State   string
	City    string
	Postal  string
	Line1   string
	Line2   string
	TaxID   string
}

type CustomerCreator

type CustomerCreator interface {
	CreateCustomer(ctx context.Context, in CustomerInput) (*Customer, []ProviderError, error)
}

type CustomerGetter

type CustomerGetter interface {
	// GetCustomer returns the billing customer and whether one exists. A
	// missing customer is (nil, false, nil), not an error.
	GetCustomer(ctx context.Context) (*Customer, bool, error)
}

type CustomerInput

type CustomerInput struct {
	Name    string
	Phone   string
	Country string
	State   string
	City    string
	Postal  string
	Line1   string
	Line2   string
	TaxID   string
}

type EndpointUsage added in v0.6.0

type EndpointUsage struct {
	UnitsUsed     int64
	UnitsIncluded int64 // meaningful only when HasIncluded
	HasIncluded   bool  // false when the account has no defined allotment
	Breakdown     []AssetClassUsage
	PeriodEnd     time.Time // reset instant; zero when the server omits it
}

EndpointUsage is the account's SDLC Endpoint consumption for the current billing period. Numbers come from the server as-is: the CLI performs no billing math.

type FeatureOverage added in v0.4.0

type FeatureOverage struct {
	CapKind        string // "units" | "monetary"
	CapUnits       int64
	UnitPriceMinor int64
	CapAmountMinor int64
	Currency       string
}

type FeatureUsage added in v0.4.0

type FeatureUsage struct {
	FeatureKey        string
	DisplayName       string
	UnitLabel         string
	IncludedLimit     int64 // -1 unlimited, 0 not-available, >0 finite
	Consumed          int64
	Seats             int64
	Tier              string
	PeriodEnd         time.Time
	Provisional       bool // enforcement == PROVISIONAL
	Overage           *FeatureOverage
	OverageUsed       int64
	OverageUsedMinor  int64
	SettlementPending bool // settlement_status == PENDING
}

FeatureUsage is the CLI-side view of one metered feature's usage. Numbers are copied from the API as-is; the CLI performs no billing math.

type OnDemandDisabler

type OnDemandDisabler interface {
	DisableOnDemand(ctx context.Context) (*OnDemandState, error)
}

type OnDemandEnabler

type OnDemandEnabler interface {
	EnableOnDemand(ctx context.Context, terms string) (*OnDemandState, error)
}

type OnDemandState

type OnDemandState struct {
	Enabled             bool
	PaymentMethodOnFile bool
	Posture             string
	Usage               []FeatureUsage
}

type OnDemandStateGetter

type OnDemandStateGetter interface {
	OnDemandState(ctx context.Context) (*OnDemandState, error)
}

type PortalOpener

type PortalOpener interface {
	Portal(ctx context.Context, returnURL string) (string, error)
}

type ProviderError

type ProviderError struct {
	Type    string
	Param   string
	Message string
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(conn *grpc.ClientConn) *Service

func (*Service) ActivateTrial

func (s *Service) ActivateTrial(ctx context.Context) error

func (*Service) AttachAddOn added in v0.5.0

func (s *Service) AttachAddOn(ctx context.Context, addOn string, terms string) ([]string, error)

func (*Service) Catalog added in v0.6.0

func (s *Service) Catalog(ctx context.Context) (*Catalog, error)

func (*Service) Checkout

func (s *Service) Checkout(ctx context.Context, in CheckoutInput) (*CheckoutResult, error)

func (*Service) CreateCustomer

func (s *Service) CreateCustomer(ctx context.Context, in CustomerInput) (*Customer, []ProviderError, error)

func (*Service) DetachAddOn added in v0.5.0

func (s *Service) DetachAddOn(ctx context.Context, addOn string) ([]string, error)

func (*Service) DisableOnDemand

func (s *Service) DisableOnDemand(ctx context.Context) (*OnDemandState, error)

func (*Service) EnableOnDemand

func (s *Service) EnableOnDemand(ctx context.Context, terms string) (*OnDemandState, error)

func (*Service) GetCustomer

func (s *Service) GetCustomer(ctx context.Context) (*Customer, bool, error)

func (*Service) OnDemandState

func (s *Service) OnDemandState(ctx context.Context) (*OnDemandState, error)

func (*Service) Portal

func (s *Service) Portal(ctx context.Context, returnURL string) (string, error)

func (*Service) Status

func (s *Service) Status(ctx context.Context) (*AccountStatus, error)

type StatusGetter

type StatusGetter interface {
	Status(ctx context.Context) (*AccountStatus, error)
}

type Subscriber

type Subscriber interface {
	Checkout(ctx context.Context, in CheckoutInput) (*CheckoutResult, error)
}

type TrialActivator

type TrialActivator interface {
	ActivateTrial(ctx context.Context) error
}

type TrialInfo

type TrialInfo struct {
	DaysRemaining int32
	ExpiresAt     time.Time
}

Jump to

Keyboard shortcuts

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