Help us shape the future of Go! Take the 2026 Go Developer Survey

subscription

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 33 Imported by: 0

README

subscription

Billing: plans, subscriptions, invoices, coupons, usage and feature entitlements.

None of the money logic lives here. It delegates to the ledger engine (github.com/xraph/ledger) and spends its own effort on the part that touches auth: hooking lifecycle events so a new organisation gets a trial without anyone clicking anything, and answering the entitlement question your feature flags need.

You choose whether a tenant is an organisation or a user, which decides who the invoice belongs to.

Use it when

  • You are charging for the product and want subscription state next to identity, not in a separate system
  • Feature gating depends on plan, so your code needs to ask "is this tenant entitled to X"
  • New signups should land on a trial automatically

Skip it when

  • You are not charging yet. This is a lot of surface area to carry for revenue you do not have
  • Your billing already lives in Stripe and you are happy querying it there
  • You have not wired the ledger engine. The plugin has nothing to delegate to without it

Wiring

authsome.WithPlugin(subscription.New(subscription.Config{
    DefaultPlanSlug:    "starter",
    AutoSubscribeOnOrg: true,
    TrialDays:          14,
})),

Config

Field Type Default What it does
PathPrefix string /v1/billing Where billing routes are mounted
DefaultPlanSlug string empty Plan auto-assigned to a new tenant
AutoSubscribeOnOrg bool false Subscribe on org creation, in organisation mode
AutoSubscribeOnUser bool false Subscribe on signup, in user mode
TrialDays int 0 Default trial length. 0 means no trial
AllowSelfService bool false Let tenants change their own plan

Settings

Key Default
subscription.default_plan empty
subscription.tenant_mode organization
subscription.auto_subscribe_org true
subscription.auto_subscribe_user false
subscription.trial_days 14
subscription.self_service_upgrade true
subscription.grace_period_days 3

Endpoints

Mounted under PathPrefix, /v1/billing by default.

Method Path Purpose
GET /plans List plans
POST /plans Create a plan
GET /plans/:planId Read a plan
POST /plans/:planId/activate Activate a plan
POST /plans/:planId/archive Archive a plan
GET /subscriptions List subscriptions
POST /subscriptions Create a subscription
GET /subscriptions/active Read the active subscription
POST /subscriptions/:subId/change-plan Move to another plan
POST /subscriptions/:subId/pause Pause
POST /subscriptions/:subId/resume Resume
POST /subscriptions/:subId/cancel Cancel
GET /invoices List invoices
GET /invoices/:invoiceId Read an invoice
POST /invoices/:invoiceId/pay Mark paid
POST /invoices/:invoiceId/void Void
GET /entitlements/:featureKey Check a feature entitlement
GET /usage Usage summary
GET /coupons List coupons
POST /coupons Create a coupon
DELETE /coupons/:couponId Delete a coupon

Lifecycle hooks

Hook What happens
AfterOrgCreate Auto-subscribes the new organisation, in organisation mode
AfterSignUp Auto-subscribes the new user, in user mode
AfterMemberAdd Records seat usage against the ledger, as authsome.orgs.members

organization supplies the tenant in organisation mode. Entitlement checks pair well with whatever feature flagging you already run.

Documentation

Overview

contract.go: Wires the subscription plugin into the forge-dashboard contract surface via plugin.ContractContributor.

Package subscription provides a billing/subscription management plugin for authsome.

It delegates all billing logic to the ledger engine (github.com/xraph/ledger) and hooks into authsome lifecycle events (org creation, user signup, member changes) to automate subscription workflows. The plugin provides:

  • Dynamic settings for configurable tenant mode, trial periods, and auto-subscription
  • REST API routes for plan, subscription, invoice, and entitlement management
  • A rich dashboard UI for administrators to manage billing
  • User and organization detail section contributions

Index

Constants

This section is empty.

Variables

View Source
var (
	// SettingDefaultPlan is the plan slug to auto-assign to new tenants.
	SettingDefaultPlan = settings.Define("subscription.default_plan", "",
		settings.WithDisplayName("Default Plan"),
		settings.WithDescription("Plan slug to auto-assign to new tenants"),
		settings.WithCategory("Subscription"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithInputType(formconfig.FieldText),
		settings.WithPlaceholder("e.g. free, starter"),
		settings.WithHelpText("Leave empty to disable auto-subscription"),
		settings.WithOrder(10),
	)

	// SettingTenantMode controls whether subscriptions are org-level or user-level.
	SettingTenantMode = settings.Define("subscription.tenant_mode", "organization",
		settings.WithDisplayName("Tenant Mode"),
		settings.WithDescription("Whether subscriptions are scoped to organizations or individual users"),
		settings.WithCategory("Subscription"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithInputType(formconfig.FieldSelect),
		settings.WithOptions(
			formconfig.SelectOption{Label: "Organization", Value: "organization"},
			formconfig.SelectOption{Label: "User", Value: "user"},
		),
		settings.WithHelpText("Determines whether billing is org-level or user-level"),
		settings.WithOrder(15),
	)

	// SettingAutoSubscribeOrg controls auto-subscription for new organizations.
	SettingAutoSubscribeOrg = settings.Define("subscription.auto_subscribe_org", true,
		settings.WithDisplayName("Auto-Subscribe Organizations"),
		settings.WithDescription("Automatically create a subscription when an organization is created"),
		settings.WithCategory("Subscription"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithVisibleWhen("subscription.tenant_mode", "organization", "eq"),
		settings.WithOrder(20),
	)

	// SettingAutoSubscribeUser controls auto-subscription for new users.
	SettingAutoSubscribeUser = settings.Define("subscription.auto_subscribe_user", false,
		settings.WithDisplayName("Auto-Subscribe Users"),
		settings.WithDescription("Automatically create a subscription when a user signs up"),
		settings.WithCategory("Subscription"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithVisibleWhen("subscription.tenant_mode", "user", "eq"),
		settings.WithOrder(30),
	)

	// SettingTrialDays controls the default trial period for new subscriptions.
	SettingTrialDays = settings.Define("subscription.trial_days", 14,
		settings.WithDisplayName("Trial Period (days)"),
		settings.WithDescription("Number of trial days for new subscriptions (0 = no trial)"),
		settings.WithCategory("Subscription"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithEnforceable(),
		settings.WithInputType(formconfig.FieldNumber),
		settings.WithUIValidation(formconfig.Validation{Min: intPtr(0), Max: intPtr(365)}),
		settings.WithHelpText("Set to 0 to disable trials. Default: 14"),
		settings.WithOrder(40),
	)

	// SettingSelfServiceUpgrade controls whether tenants can change their own plan.
	SettingSelfServiceUpgrade = settings.Define("subscription.self_service_upgrade", true,
		settings.WithDisplayName("Allow Self-Service Plan Changes"),
		settings.WithDescription("Allow users/orgs to upgrade or downgrade their own plan"),
		settings.WithCategory("Subscription"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithOrder(50),
	)

	// SettingGracePeriodDays controls the grace period after billing failure.
	SettingGracePeriodDays = settings.Define("subscription.grace_period_days", 3,
		settings.WithDisplayName("Grace Period (days)"),
		settings.WithDescription("Days after billing failure before restricting access"),
		settings.WithCategory("Subscription"),
		settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp),
		settings.WithInputType(formconfig.FieldNumber),
		settings.WithUIValidation(formconfig.Validation{Min: intPtr(0), Max: intPtr(30)}),
		settings.WithHelpText("Set to 0 for immediate restriction. Default: 3"),
		settings.WithOrder(60),
	)
)

Functions

This section is empty.

Types

type CancelSubscriptionRequest added in v1.9.0

type CancelSubscriptionRequest struct {
	SubID       string `path:"subId"`
	Immediately bool   `json:"immediately"`
}

type ChangePlanRequest added in v1.9.0

type ChangePlanRequest struct {
	SubID     string `path:"subId"`
	NewPlanID string `json:"new_plan_id"`
}

type CheckEntitlementRequest added in v1.9.0

type CheckEntitlementRequest struct {
	FeatureKey string `path:"featureKey"`
}

type Config

type Config struct {
	// PathPrefix is the HTTP path prefix for billing routes.
	// Defaults to "/v1/billing".
	PathPrefix string

	// DefaultPlanSlug is the plan slug to auto-assign to new tenants.
	// If empty, no auto-subscription occurs unless overridden by settings.
	DefaultPlanSlug string

	// AutoSubscribeOnOrg creates a subscription when an organization is created.
	// Only applies when tenant mode is "organization".
	AutoSubscribeOnOrg bool

	// AutoSubscribeOnUser creates a subscription when a user signs up.
	// Only applies when tenant mode is "user".
	AutoSubscribeOnUser bool

	// TrialDays is the default trial period for new subscriptions.
	// 0 means no trial. Can be overridden by settings.
	TrialDays int

	// AllowSelfService lets users/orgs change their own plan.
	AllowSelfService bool
}

Config configures the subscription plugin.

type CouponResponse added in v1.9.0

type CouponResponse struct {
	ID             string  `json:"id"`
	Code           string  `json:"code"`
	Name           string  `json:"name"`
	Type           string  `json:"type"`
	Amount         string  `json:"amount,omitempty"`
	Percentage     int     `json:"percentage,omitempty"`
	Currency       string  `json:"currency"`
	MaxRedemptions int     `json:"max_redemptions"`
	TimesRedeemed  int     `json:"times_redeemed"`
	ValidFrom      *string `json:"valid_from,omitempty"`
	ValidUntil     *string `json:"valid_until,omitempty"`
	AppID          string  `json:"app_id"`
}

type CreateCouponRequest added in v1.9.0

type CreateCouponRequest struct {
	Code           string  `json:"code"`
	Name           string  `json:"name"`
	Type           string  `json:"type"`
	Amount         int64   `json:"amount"`
	Percentage     int     `json:"percentage"`
	Currency       string  `json:"currency"`
	MaxRedemptions int     `json:"max_redemptions"`
	ValidFrom      *string `json:"valid_from,omitempty"`
	ValidUntil     *string `json:"valid_until,omitempty"`
	AppID          string  `json:"app_id"`
}

type CreatePlanRequest added in v1.9.0

type CreatePlanRequest struct {
	Name        string            `json:"name"`
	Slug        string            `json:"slug"`
	Description string            `json:"description"`
	Currency    string            `json:"currency"`
	TrialDays   int               `json:"trial_days"`
	BaseAmount  int64             `json:"base_amount"`
	Period      string            `json:"period"`
	AppID       string            `json:"app_id"`
	IsAddon     bool              `json:"is_addon"`
	Features    []FeatureInput    `json:"features,omitempty"`
	Metadata    map[string]string `json:"metadata,omitempty"`
}

type CreateSubscriptionRequest added in v1.9.0

type CreateSubscriptionRequest struct {
	TenantID string `json:"tenant_id"`
	PlanID   string `json:"plan_id"`
	AppID    string `json:"app_id"`
}

type DeleteCouponRequest added in v1.9.0

type DeleteCouponRequest struct {
	CouponID string `path:"couponId"`
}

type EntitlementResponse added in v1.9.0

type EntitlementResponse struct {
	Allowed   bool   `json:"allowed"`
	Feature   string `json:"feature"`
	Used      int64  `json:"used"`
	Limit     int64  `json:"limit"`
	Remaining int64  `json:"remaining"`
	Reason    string `json:"reason,omitempty"`
}

type FeatureInput added in v1.9.0

type FeatureInput struct {
	Key       string `json:"key"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	Limit     int64  `json:"limit"`
	Period    string `json:"period"`
	SoftLimit bool   `json:"soft_limit"`
}

type GetActiveSubRequest added in v1.9.0

type GetActiveSubRequest struct {
	AppID    string `query:"app_id"`
	TenantID string `query:"tenant_id"`
}

type GetInvoiceRequest added in v1.9.0

type GetInvoiceRequest struct {
	InvoiceID string `path:"invoiceId"`
}

type GetPlanRequest added in v1.9.0

type GetPlanRequest struct {
	PlanID string `path:"planId"`
}

type InvoiceIDRequest added in v1.9.0

type InvoiceIDRequest struct {
	InvoiceID string `path:"invoiceId"`
}

type InvoiceResponse added in v1.9.0

type InvoiceResponse struct {
	ID             string `json:"id"`
	TenantID       string `json:"tenant_id"`
	SubscriptionID string `json:"subscription_id"`
	Status         string `json:"status"`
	Currency       string `json:"currency"`
	Total          string `json:"total"`
	PeriodStart    string `json:"period_start"`
	PeriodEnd      string `json:"period_end"`
}

type ListCouponsRequest added in v1.9.0

type ListCouponsRequest struct {
	AppID string `query:"app_id"`
}

type ListCouponsResponse added in v1.9.0

type ListCouponsResponse struct {
	Coupons []CouponResponse `json:"coupons"`
	Total   int              `json:"total"`
}

type ListInvoicesRequest added in v1.9.0

type ListInvoicesRequest struct {
	AppID    string `query:"app_id"`
	TenantID string `query:"tenant_id"`
}

type ListInvoicesResponse added in v1.9.0

type ListInvoicesResponse struct {
	Invoices []InvoiceResponse `json:"invoices"`
	Total    int               `json:"total"`
}

type ListPlansRequest added in v1.9.0

type ListPlansRequest struct {
	AppID string `query:"app_id"`
}

type ListPlansResponse added in v1.9.0

type ListPlansResponse struct {
	Plans []PlanResponse `json:"plans"`
	Total int            `json:"total"`
}

type ListSubscriptionsRequest added in v1.9.0

type ListSubscriptionsRequest struct {
	AppID    string `query:"app_id"`
	TenantID string `query:"tenant_id"`
	Status   string `query:"status,omitempty"`
}

type ListSubscriptionsResponse added in v1.9.0

type ListSubscriptionsResponse struct {
	Subscriptions []Response `json:"subscriptions"`
	Total         int        `json:"total"`
}

type MarkInvoicePaidRequest added in v1.9.0

type MarkInvoicePaidRequest struct {
	InvoiceID  string `path:"invoiceId"`
	PaymentRef string `json:"payment_ref"`
}

type PlanIDRequest added in v1.9.0

type PlanIDRequest struct {
	PlanID string `path:"planId"`
}

type PlanResponse added in v1.9.0

type PlanResponse struct {
	ID            string            `json:"id"`
	Name          string            `json:"name"`
	Slug          string            `json:"slug"`
	Description   string            `json:"description"`
	Currency      string            `json:"currency"`
	Status        string            `json:"status"`
	TrialDays     int               `json:"trial_days"`
	BaseAmount    string            `json:"base_amount,omitempty"`
	BillingPeriod string            `json:"billing_period,omitempty"`
	FeaturesCount int               `json:"features_count"`
	IsAddon       bool              `json:"is_addon"`
	AppID         string            `json:"app_id"`
	Metadata      map[string]string `json:"metadata,omitempty"`
}

type Plugin

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

Plugin is the subscription management plugin for authsome.

func New added in v1.9.0

func New(cfg ...Config) *Plugin

New creates a new subscription plugin with the given configuration.

func (*Plugin) DeclareSettings added in v1.9.0

func (p *Plugin) DeclareSettings(m *settings.Manager) error

DeclareSettings implements plugin.SettingsProvider.

func (*Plugin) Name added in v1.9.0

func (p *Plugin) Name() string

Name returns the plugin name.

func (*Plugin) OnAfterMemberAdd added in v1.9.0

func (p *Plugin) OnAfterMemberAdd(ctx context.Context, _ *organization.Member) error

OnAfterMemberAdd records seat usage when a member is added to an organization.

func (*Plugin) OnAfterOrgCreate added in v1.9.0

func (p *Plugin) OnAfterOrgCreate(ctx context.Context, o *organization.Organization) error

OnAfterOrgCreate auto-creates a subscription for new organizations when tenant mode is "organization" and auto-subscribe is enabled.

func (*Plugin) OnAfterOrgDelete added in v1.9.0

func (p *Plugin) OnAfterOrgDelete(ctx context.Context, orgID id.OrgID) error

OnAfterOrgDelete cancels every subscription whose tenant is the deleted org so the ledger doesn't keep billing a tenant that no longer exists. Cancellation is best-effort: failures are logged and the hook always returns nil so the org-delete pipeline keeps draining other plugins.

func (*Plugin) OnAfterSignUp added in v1.9.0

func (p *Plugin) OnAfterSignUp(ctx context.Context, u *user.User, _ *session.Session) error

OnAfterSignUp auto-creates a subscription for new users when tenant mode is "user" and auto-subscribe is enabled.

func (*Plugin) OnInit added in v1.9.0

func (p *Plugin) OnInit(_ context.Context, engine plugin.Engine) error

OnInit captures bridge and engine references.

func (*Plugin) RegisterContract added in v1.9.0

func (p *Plugin) RegisterContract(
	d *dispatcher.Dispatcher,
	reg contract.Registry,
	wreg contract.WardenRegistry,
	engine plugin.Engine,
) error

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(router forge.Router) error

RegisterRoutes registers billing API routes on a forge.Router.

func (*Plugin) Service added in v1.9.0

func (p *Plugin) Service() *Service

Service returns the subscription service (nil until OnInit completes).

func (*Plugin) SetLedger added in v1.9.0

func (p *Plugin) SetLedger(l *ledger.Ledger)

SetLedger sets the ledger engine directly, bypassing duck-type discovery.

func (*Plugin) SetLedgerStore added in v1.9.0

func (p *Plugin) SetLedgerStore(st ledgerstore.Store)

SetLedgerStore sets the ledger store directly, bypassing duck-type discovery.

type Response added in v1.9.0

type Response struct {
	ID                 string  `json:"id"`
	TenantID           string  `json:"tenant_id"`
	PlanID             string  `json:"plan_id"`
	Status             string  `json:"status"`
	CurrentPeriodStart string  `json:"current_period_start"`
	CurrentPeriodEnd   string  `json:"current_period_end"`
	TrialStart         *string `json:"trial_start,omitempty"`
	TrialEnd           *string `json:"trial_end,omitempty"`
	CanceledAt         *string `json:"canceled_at,omitempty"`
	AppID              string  `json:"app_id"`
}

type Service added in v1.9.0

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

Service wraps ledger operations with AuthSome context.

func (*Service) ActivatePlan added in v1.9.0

func (s *Service) ActivatePlan(ctx context.Context, planID ledgerid.PlanID) error

ActivatePlan transitions a draft plan to active status.

func (*Service) ArchiveCatalogFeature added in v1.9.0

func (s *Service) ArchiveCatalogFeature(ctx context.Context, featureID ledgerid.FeatureID) error

ArchiveCatalogFeature archives a catalog feature.

func (*Service) ArchivePlan added in v1.9.0

func (s *Service) ArchivePlan(ctx context.Context, planID ledgerid.PlanID) error

ArchivePlan archives a plan by ID.

func (*Service) CalculateMRR added in v1.9.0

func (s *Service) CalculateMRR(ctx context.Context, appID string) string

CalculateMRR estimates monthly recurring revenue across all active subscriptions.

func (*Service) CancelSubscription added in v1.9.0

func (s *Service) CancelSubscription(ctx context.Context, subID ledgerid.SubscriptionID, immediately bool) error

CancelSubscription cancels a subscription.

func (*Service) ChangePlan added in v1.9.0

func (s *Service) ChangePlan(ctx context.Context, subID ledgerid.SubscriptionID, newPlanID ledgerid.PlanID) error

ChangePlan changes a subscription to a different plan.

func (*Service) CheckEntitlement added in v1.9.0

func (s *Service) CheckEntitlement(ctx context.Context, featureKey string) (*entitlement.Result, error)

CheckEntitlement checks whether a tenant can use a feature.

func (*Service) CountSubscribers added in v1.9.0

func (s *Service) CountSubscribers(ctx context.Context, planID ledgerid.PlanID, appID string) int

CountSubscribers counts active subscriptions for a plan.

func (*Service) CreateCatalogFeature added in v1.9.0

func (s *Service) CreateCatalogFeature(ctx context.Context, f *feature.Feature) error

CreateCatalogFeature creates a new catalog feature.

func (*Service) CreateCoupon added in v1.9.0

func (s *Service) CreateCoupon(ctx context.Context, c *coupon.Coupon) error

CreateCoupon creates a new coupon.

func (*Service) CreatePlan added in v1.9.0

func (s *Service) CreatePlan(ctx context.Context, p *plan.Plan) error

CreatePlan creates a new billing plan.

func (*Service) DeleteCatalogFeature added in v1.9.0

func (s *Service) DeleteCatalogFeature(ctx context.Context, featureID ledgerid.FeatureID) error

DeleteCatalogFeature deletes a catalog feature.

func (*Service) DeleteCoupon added in v1.9.0

func (s *Service) DeleteCoupon(ctx context.Context, couponID ledgerid.CouponID) error

DeleteCoupon deletes a coupon.

func (*Service) GenerateInvoice added in v1.9.0

func (s *Service) GenerateInvoice(ctx context.Context, subID ledgerid.SubscriptionID) (*invoice.Invoice, error)

GenerateInvoice generates an invoice for the current billing period.

func (*Service) GetActiveSubscription added in v1.9.0

func (s *Service) GetActiveSubscription(ctx context.Context, tenantID, appID string) (*subscription.Subscription, error)

GetActiveSubscription retrieves the active subscription for a tenant.

func (*Service) GetCatalogFeature added in v1.9.0

func (s *Service) GetCatalogFeature(ctx context.Context, featureID ledgerid.FeatureID) (*feature.Feature, error)

GetCatalogFeature retrieves a catalog feature by ID.

func (*Service) GetCatalogFeatureByKey added in v1.9.0

func (s *Service) GetCatalogFeatureByKey(ctx context.Context, key, appID string) (*feature.Feature, error)

GetCatalogFeatureByKey retrieves a catalog feature by key.

func (*Service) GetCoupon added in v1.9.0

func (s *Service) GetCoupon(ctx context.Context, code, appID string) (*coupon.Coupon, error)

GetCoupon retrieves a coupon by code.

func (*Service) GetInvoice added in v1.9.0

func (s *Service) GetInvoice(ctx context.Context, invID ledgerid.InvoiceID) (*invoice.Invoice, error)

GetInvoice retrieves an invoice by ID.

func (*Service) GetPlan added in v1.9.0

func (s *Service) GetPlan(ctx context.Context, planID ledgerid.PlanID) (*plan.Plan, error)

GetPlan retrieves a plan by ID.

func (*Service) GetSubscription added in v1.9.0

func (s *Service) GetSubscription(ctx context.Context, subID ledgerid.SubscriptionID) (*subscription.Subscription, error)

GetSubscription retrieves a subscription by ID.

func (*Service) GetUsageSummary added in v1.9.0

func (s *Service) GetUsageSummary(ctx context.Context, tenantID, appID string) ([]UsageSummary, error)

GetUsageSummary returns usage breakdown for the active subscription.

func (*Service) ListAllInvoices added in v1.9.0

func (s *Service) ListAllInvoices(ctx context.Context, appID string) ([]*invoice.Invoice, error)

ListAllInvoices lists all invoices for an app.

func (*Service) ListCatalogFeatures added in v1.9.0

func (s *Service) ListCatalogFeatures(ctx context.Context, appID string) ([]*feature.Feature, error)

ListCatalogFeatures lists all catalog features for an app.

func (*Service) ListCoupons added in v1.9.0

func (s *Service) ListCoupons(ctx context.Context, appID string) ([]*coupon.Coupon, error)

ListCoupons lists all coupons for an app.

func (*Service) ListInvoices added in v1.9.0

func (s *Service) ListInvoices(ctx context.Context, tenantID, appID string) ([]*invoice.Invoice, error)

ListInvoices lists invoices for a tenant.

func (*Service) ListPlans added in v1.9.0

func (s *Service) ListPlans(ctx context.Context, appID string) ([]*plan.Plan, error)

ListPlans returns all plans for the given app.

func (*Service) ListSubscriptions added in v1.9.0

func (s *Service) ListSubscriptions(ctx context.Context, tenantID, appID string, opts subscription.ListOpts) ([]*subscription.Subscription, error)

ListSubscriptions lists subscriptions for a tenant.

func (*Service) MarkInvoicePaid added in v1.9.0

func (s *Service) MarkInvoicePaid(ctx context.Context, invID ledgerid.InvoiceID, paymentRef string) error

MarkInvoicePaid marks an invoice as paid.

func (*Service) MarkInvoiceVoided added in v1.9.0

func (s *Service) MarkInvoiceVoided(ctx context.Context, invID ledgerid.InvoiceID, reason string) error

MarkInvoiceVoided voids an invoice.

func (*Service) PauseSubscription added in v1.9.0

func (s *Service) PauseSubscription(ctx context.Context, subID ledgerid.SubscriptionID) error

PauseSubscription pauses a subscription.

func (*Service) ResumeSubscription added in v1.9.0

func (s *Service) ResumeSubscription(ctx context.Context, subID ledgerid.SubscriptionID) error

ResumeSubscription resumes a paused subscription.

func (*Service) SetLedgerStore added in v1.9.0

func (s *Service) SetLedgerStore(st ledgerstore.Store)

SetLedgerStore sets the ledger store directly, bypassing duck-type discovery.

func (*Service) Subscribe added in v1.9.0

func (s *Service) Subscribe(ctx context.Context, tenantID string, planID ledgerid.PlanID, appID string) (*subscription.Subscription, error)

Subscribe creates a new subscription for a tenant on a plan.

func (*Service) UpdateCatalogFeature added in v1.9.0

func (s *Service) UpdateCatalogFeature(ctx context.Context, f *feature.Feature) error

UpdateCatalogFeature updates a catalog feature.

func (*Service) UpdatePlan added in v1.9.0

func (s *Service) UpdatePlan(ctx context.Context, p *plan.Plan) error

UpdatePlan updates an existing plan.

type SubIDRequest added in v1.9.0

type SubIDRequest struct {
	SubID string `path:"subId"`
}

type UsageItemResponse added in v1.9.0

type UsageItemResponse struct {
	FeatureKey  string `json:"feature_key"`
	FeatureName string `json:"feature_name"`
	FeatureType string `json:"feature_type"`
	Used        int64  `json:"used"`
	Limit       int64  `json:"limit"`
	Remaining   int64  `json:"remaining"`
	Period      string `json:"period"`
}

type UsageSummary added in v1.9.0

type UsageSummary struct {
	FeatureKey  string
	FeatureName string
	FeatureType string
	Used        int64
	Limit       int64
	Remaining   int64
	Period      string
}

UsageSummary holds feature usage data for display.

type UsageSummaryRequest added in v1.9.0

type UsageSummaryRequest struct {
	AppID    string `query:"app_id"`
	TenantID string `query:"tenant_id"`
}

type UsageSummaryResponse added in v1.9.0

type UsageSummaryResponse struct {
	Usage []UsageItemResponse `json:"usage"`
}

type VoidInvoiceRequest added in v1.9.0

type VoidInvoiceRequest struct {
	InvoiceID string `path:"invoiceId"`
	Reason    string `json:"reason"`
}

Directories

Path Synopsis
Package contract wires the subscription plugin's intent surface into the forge-dashboard contract registry.
Package contract wires the subscription plugin's intent surface into the forge-dashboard contract registry.

Jump to

Keyboard shortcuts

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