Documentation ¶
Index ¶
- Constants
- Variables
- func Expand(fs []Feature, names ...string) ([]refs.FeaturePlan, error)
- func FeaturePlans(fs []Feature) []refs.FeaturePlan
- type Client
- func (c *Client) ListOrgs(ctx context.Context) ([]Org, error)
- func (c *Client) Live() bool
- func (c *Client) LookupLimits(ctx context.Context, org string) ([]Usage, error)
- func (c *Client) LookupPhases(ctx context.Context, org string) (ps []Phase, err error)
- func (c *Client) Pull(ctx context.Context, limit int) ([]Feature, error)
- func (c *Client) Push(ctx context.Context, fs []Feature, cb func(f Feature, err error)) error
- func (c *Client) ReportUsage(ctx context.Context, org string, feature refs.Name, use Report) error
- func (c *Client) Subscribe(ctx context.Context, org string, phases []Phase) (err error)
- func (c *Client) SubscribeNow(ctx context.Context, org string, phases []Phase) error
- func (c *Client) SubscribeTo(ctx context.Context, org string, fs []refs.FeaturePlan) error
- func (c *Client) SubscribeToPlan(ctx context.Context, org string, plan refs.Plan) error
- func (c *Client) SubscribeToRefs(ctx context.Context, org string, refs []string) error
- func (c *Client) WhoIs(ctx context.Context, org string) (id string, err error)
- type Feature
- type Org
- type Phase
- type Report
- type Tier
- type Usage
- type ValidationError
Constants ¶
const Inf = 1<<63 - 1
Variables ¶
var ( ErrFeatureExists = errors.New("feature already exists") ErrFeatureNotFound = errors.New("feature not found") ErrFeatureNotMetered = errors.New("feature is not metered") )
Errors
var (
ErrOrgNotFound = errors.New("org not found")
)
Errors
Functions ¶
func Expand ¶ added in v0.3.8
func Expand(fs []Feature, names ...string) ([]refs.FeaturePlan, error)
Expand parses each ref in refs and adds it to the result. If the ref is a plan ref, Expand will append all features in fs for that plan to the result. returns an error if any ref is invalid or not availabe in the
The parameter fs is assumed to have no two features with the same FeaturePlan.
It returns an error if any.
func FeaturePlans ¶ added in v0.3.8
func FeaturePlans(fs []Feature) []refs.FeaturePlan
Types ¶
type Client ¶
type Client struct { Logf func(format string, args ...any) Stripe *stripe.Client Clock string // contains filtered or unexported fields }
func (*Client) LookupLimits ¶ added in v0.3.1
func (*Client) LookupPhases ¶
func (*Client) Push ¶
Push pushes each feature in fs to Stripe as a product and price combination. A new price and product are created in Stripe if one does not already exist.
Each call to push is subject to rate limiting via the clients shared rate limit.
It returns the first error encountered if any.
func (*Client) ReportUsage ¶
func (*Client) SubscribeNow ¶ added in v0.3.8
SubscribeNow is like Subscribe but immediately starts the first phase as the current phase and cuts off any phases that have not yet been transitioned to.
The first phase must have a zero Effective time to indicate that it should start now.
func (*Client) SubscribeTo ¶
SubscribeTo subscribes org to the provided features. If a subscription has already begun, the current phase will be updated; otherwise a new subscription will be created and go into effect immediatly.
func (*Client) SubscribeToPlan ¶
func (*Client) SubscribeToRefs ¶ added in v0.3.8
type Feature ¶
type Feature struct { refs.FeaturePlan // the feature name prefixed with ("feature:") ProviderID string // identifier set by the billing engine provider PlanTitle string // a human readable title for the plan Title string // a human readable title for the feature // Interval specifies the billing interval for the feature. // // Known intervals are "@daily", "@weekly", "@monthly", and "@yearly". Interval string // Currency is the ISO 4217 currency code for the feature. // // Known currencies look like "usd", "eur", "gbp", "cad", "aud", "jpy", "chf", // etc. Please see your billing engine provider for a complete list. Currency string // Base is the base price for the feature. If Tiers is not empty, then Base // is ignored. Base int // Mode specifies the billing mode for use with Tiers. // // Known modes are "graduated" and "volume". Mode string // Aggregate specifies the usage aggregation method for use with Tiers. // // Known aggregates are "sum", "max", "last", and "perpetual". Aggregate string // Tiers optionally specifies the pricing tiers for this feature. If // empty, feature is billed at the beginning of each billing period at // the flat rate specified by Base. If non-empty, the feature is billed // at the end of each billing period based on usage, and at a price // determined by Tiers, Mode, and Aggregate. Tiers []Tier // ReportID is the ID for reporting usage to the billing provider. ReportID string }
type Phase ¶
type Phase struct { Org string // set on read Effective time.Time Features []refs.FeaturePlan Current bool // Plans is the set of plans that are currently active for the phase. A // plan is considered active in a phase if all of its features are // listed in the phase. If any features from a plan is in the phase // without the other features in the plan, this phase is considered // "fragmented". Plans []refs.Plan }
func (*Phase) Fragments ¶ added in v0.3.8
func (p *Phase) Fragments() []refs.FeaturePlan
type Tier ¶
type Tier struct { Upto int // the upper limit of the tier Price int // the price of the tier Base int // the base price of the tier }
Tier holds the pricing information for a single tier.
type ValidationError ¶ added in v0.3.8
type ValidationError struct {
Message string
}
func (*ValidationError) Error ¶ added in v0.3.8
func (e *ValidationError) Error() string