Documentation
¶
Index ¶
- Constants
- Variables
- type FeatureRepository
- type File
- type Filter
- type Plan
- type PriceRepository
- type ProductService
- type Repository
- type Service
- func (s Service) Create(ctx context.Context, p Plan) (Plan, error)
- func (s Service) GetByID(ctx context.Context, id string) (Plan, error)
- func (s Service) List(ctx context.Context, filter Filter) ([]Plan, error)
- func (s Service) UpdatePlan(ctx context.Context, p Plan) (Plan, error)
- func (s Service) UpsertPlans(ctx context.Context, planFile File) error
Constants ¶
View Source
const ( StateActive = "active" StateInactive = "inactive" )
Variables ¶
View Source
var ( ErrNotFound = errors.New("plan not found") ErrInvalidUUID = errors.New("invalid syntax of uuid") ErrInvalidName = errors.New("plan name is invalid") ErrInvalidDetail = errors.New("invalid plan detail") // ErrPlanInactive is the single sentinel for "a retired plan cannot take a new // subscription". checkout and subscription both surface it, so a handler maps // one error to one client code. ErrPlanInactive = errors.New("plan is inactive and cannot be subscribed to") )
Functions ¶
This section is empty.
Types ¶
type FeatureRepository ¶ added in v0.33.0
type Plan ¶
type Plan struct {
ID string `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name"` // a machine friendly name for the feature
Title string `json:"title" yaml:"title"` // a human friendly title
Description string `json:"description" yaml:"description"`
Metadata metadata.Metadata `json:"metadata" yaml:"metadata"`
// Interval is the interval at which the plan is billed
// e.g. day, week, month, year
// This is just used to group related product prices and has no
// immediate effect on the billing engine
Interval string `json:"interval" yaml:"interval"`
// OnStartCredits is the number of credits that are awarded when a subscription is started
OnStartCredits int64 `json:"on_start_credits" yaml:"on_start_credits"`
// Products for the plan, return only, should not be set when creating a plan
Products []product.Product `json:"products" yaml:"products"`
// TrialDays is the number of days a subscription is in trial
TrialDays int64 `json:"trial_days" yaml:"trial_days"`
State string
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time
}
Plan is a collection of products it is a logical grouping of products and doesn't have a corresponding billing engine entity
func (Plan) GetUserSeatProduct ¶ added in v0.8.19
func (Plan) IsInactive ¶ added in v0.114.0
IsInactive reports whether the plan is retired: hidden from ListPlans and closed to new subscriptions. Existing subscriptions on it keep working.
type PriceRepository ¶ added in v0.33.2
type ProductService ¶ added in v0.8.14
type ProductService interface {
Create(ctx context.Context, p product.Product) (product.Product, error)
GetByID(ctx context.Context, id string) (product.Product, error)
Update(ctx context.Context, p product.Product) (product.Product, error)
AddPlan(ctx context.Context, p product.Product, planID string) error
CreatePrice(ctx context.Context, price product.Price) (product.Price, error)
UpdatePrice(ctx context.Context, price product.Price) (product.Price, error)
GetPriceByID(ctx context.Context, id string) (product.Price, error)
GetPriceByProductID(ctx context.Context, id string) ([]product.Price, error)
List(ctx context.Context, flt product.Filter) ([]product.Product, error)
UpsertFeature(ctx context.Context, f product.Feature) (product.Feature, error)
GetFeatureByID(ctx context.Context, id string) (product.Feature, error)
GetFeatureByProductID(ctx context.Context, id string) ([]product.Feature, error)
}
type Repository ¶
type Repository interface {
GetByID(ctx context.Context, id string) (Plan, error)
GetByName(ctx context.Context, name string) (Plan, error)
Create(ctx context.Context, plan Plan) (Plan, error)
UpdateByName(ctx context.Context, plan Plan) (Plan, error)
List(ctx context.Context, filter Filter) ([]Plan, error)
ListWithProducts(ctx context.Context, filter Filter) ([]Plan, error)
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(stripeClient *client.API, planRepository Repository, productService ProductService, featureRepository FeatureRepository, priceRepository PriceRepository) *Service
func (Service) UpdatePlan ¶ added in v0.114.0
UpdatePlan updates a plan's own fields: title, description, credits, trial days, state, and metadata. A plan's products are managed through UpsertPlans, so they are left untouched here. The plan is looked up by id or name.
Click to show internal directories.
Click to hide internal directories.