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

contract

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: 19 Imported by: 0

Documentation

Overview

Package contract wires the subscription plugin's intent surface into the forge-dashboard contract registry. The `/plans` and `/plans/:id` pages stay declared on the auth contributor; only the intent handlers + their declarations move here.

handlers.go: subscription plugin intent handlers. Moved from the auth contributor's handlers_subscriptions.go. The plugin's Service arrives via Deps (set up in plugins/subscription/contract.go) so handlers skip the engine.Plugin("subscription") indirection.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(
	d *dispatcher.Dispatcher,
	reg contract.Registry,
	wreg contract.WardenRegistry,
	deps Deps,
) error

Types

type ActivatePlanInput

type ActivatePlanInput struct {
	ID string `json:"id"`
}

type ArchivePlanInput

type ArchivePlanInput struct {
	ID string `json:"id"`
}

type Deps

type Deps struct {
	Engine  *authsome.Engine
	Service SubscriptionService
	Usage   func(context.Context, string, string) ([]UsageSummary, error)
}

type GetPlanInput

type GetPlanInput struct {
	ID string `json:"id"`
}

type PlanDetail

type PlanDetail struct {
	PlanSummary
	Features []PlanFeature      `json:"features,omitempty"`
	Tiers    []PriceTierSummary `json:"tiers,omitempty"`
}

type PlanFeature

type PlanFeature struct {
	ID        string `json:"id,omitempty"`
	Key       string `json:"key"`
	Name      string `json:"name"`
	Type      string `json:"type"`
	Limit     int64  `json:"limit"`
	Period    string `json:"period"`
	SoftLimit bool   `json:"softLimit"`
	CatalogID string `json:"catalogId,omitempty"`
}

type PlanSummary

type PlanSummary struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	Slug          string `json:"slug"`
	Description   string `json:"description,omitempty"`
	Currency      string `json:"currency,omitempty"`
	Status        string `json:"status"`
	TrialDays     int    `json:"trialDays,omitempty"`
	BaseAmount    int64  `json:"baseAmount"`
	BillingPeriod string `json:"billingPeriod,omitempty"`
}

type PlansListResponse

type PlansListResponse struct {
	Plans []PlanSummary `json:"plans"`
}

type PriceTierSummary

type PriceTierSummary struct {
	FeatureKey string `json:"featureKey"`
	Type       string `json:"type"`
	UpTo       int64  `json:"upTo"`
	UnitAmount int64  `json:"unitAmount"`
	FlatAmount int64  `json:"flatAmount"`
}

type SubscriptionService

type SubscriptionService interface {
	ListPlans(ctx context.Context, appID string) ([]*plan.Plan, error)
	GetPlan(ctx context.Context, planID ledgerid.PlanID) (*plan.Plan, error)
	CreatePlan(ctx context.Context, p *plan.Plan) error
	UpdatePlan(ctx context.Context, p *plan.Plan) error
	ArchivePlan(ctx context.Context, planID ledgerid.PlanID) error
	ActivatePlan(ctx context.Context, planID ledgerid.PlanID) error
	ListSubscriptions(ctx context.Context, tenantID, appID string, opts subscription.ListOpts) ([]*subscription.Subscription, error)
	GetSubscription(ctx context.Context, subID ledgerid.SubscriptionID) (*subscription.Subscription, error)
	GetActiveSubscription(ctx context.Context, tenantID, appID string) (*subscription.Subscription, error)
	Subscribe(ctx context.Context, tenantID string, planID ledgerid.PlanID, appID string) (*subscription.Subscription, error)
	ChangePlan(ctx context.Context, subID ledgerid.SubscriptionID, newPlanID ledgerid.PlanID) error
	PauseSubscription(ctx context.Context, subID ledgerid.SubscriptionID) error
	ResumeSubscription(ctx context.Context, subID ledgerid.SubscriptionID) error
	CancelSubscription(ctx context.Context, subID ledgerid.SubscriptionID, immediately bool) error
	ListAllInvoices(ctx context.Context, appID string) ([]*invoice.Invoice, error)
	ListInvoices(ctx context.Context, tenantID, appID string) ([]*invoice.Invoice, error)
	GetInvoice(ctx context.Context, invID ledgerid.InvoiceID) (*invoice.Invoice, error)
	GenerateInvoice(ctx context.Context, subID ledgerid.SubscriptionID) (*invoice.Invoice, error)
	MarkInvoicePaid(ctx context.Context, invID ledgerid.InvoiceID, paymentRef string) error
	MarkInvoiceVoided(ctx context.Context, invID ledgerid.InvoiceID, reason string) error
	ListCoupons(ctx context.Context, appID string) ([]*coupon.Coupon, error)
	GetCoupon(ctx context.Context, code, appID string) (*coupon.Coupon, error)
	CreateCoupon(ctx context.Context, c *coupon.Coupon) error
	DeleteCoupon(ctx context.Context, couponID ledgerid.CouponID) error
	ListCatalogFeatures(ctx context.Context, appID string) ([]*feature.Feature, error)
	GetCatalogFeature(ctx context.Context, featureID ledgerid.FeatureID) (*feature.Feature, error)
	CreateCatalogFeature(ctx context.Context, f *feature.Feature) error
	UpdateCatalogFeature(ctx context.Context, f *feature.Feature) error
	ArchiveCatalogFeature(ctx context.Context, featureID ledgerid.FeatureID) error
}

SubscriptionService is the surface this package needs from the subscription plugin. Declared as an interface here so the contract subpackage doesn't import plugins/subscription directly (cycle avoidance). The parent contract.go satisfies it by passing the plugin's Service().

type SubscriptionSummary

type SubscriptionSummary struct {
	ID                 string `json:"id"`
	TenantID           string `json:"tenantId"`
	PlanID             string `json:"planId"`
	Status             string `json:"status"`
	CurrentPeriodStart string `json:"currentPeriodStart,omitempty"`
	CurrentPeriodEnd   string `json:"currentPeriodEnd,omitempty"`
	CancelAt           string `json:"cancelAt,omitempty"`
}

type SubscriptionsListInput

type SubscriptionsListInput struct {
	TenantID string `json:"tenantId"`
}

type SubscriptionsListResponse

type SubscriptionsListResponse struct {
	Subscriptions []SubscriptionSummary `json:"subscriptions"`
}

type UsageSummary

type UsageSummary struct {
	FeatureKey  string `json:"featureKey"`
	FeatureName string `json:"featureName"`
	FeatureType string `json:"featureType"`
	Used        int64  `json:"used"`
	Limit       int64  `json:"limit"`
	Remaining   int64  `json:"remaining"`
	Period      string `json:"period"`
}

Jump to

Keyboard shortcuts

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