pricingrule

package
v1.33.0 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Query

Types

type PricingModel

type PricingModel string

PricingModel defines how usage is converted to cost.

const (
	PerUnit PricingModel = "per_unit"
	Tiered  PricingModel = "tiered"
	Volume  PricingModel = "volume"
)

type PricingRule

type PricingRule struct {
	mixin.Model

	MeterId     string        `json:"meterId"`
	PlanId      string        `json:"planId,omitempty"`
	PricingType PricingModel  `json:"model"`
	Currency    currency.Type `json:"currency"`
	UnitPrice   int64         `json:"unitPrice"` // cents, for per_unit model

	Tiers  []Tier `json:"tiers,omitempty" datastore:"-"`
	Tiers_ string `json:"-" datastore:",noindex"`

	Metadata  Map    `json:"metadata,omitempty" datastore:"-"`
	Metadata_ string `json:"-" datastore:",noindex"`
}

PricingRule maps a meter to a cost model. For per-unit pricing, UnitPrice is used directly. For tiered/volume pricing, the Tiers array defines the pricing bands.

func New

func (*PricingRule) CalculateCost

func (p *PricingRule) CalculateCost(quantity int64) int64

CalculateCost computes the total cost in cents for a given usage quantity.

func (*PricingRule) Defaults

func (p *PricingRule) Defaults()

func (*PricingRule) Init

func (p *PricingRule) Init(db *datastore.Datastore)

func (PricingRule) Kind

func (p PricingRule) Kind() string

func (*PricingRule) Load

func (p *PricingRule) Load(ps []datastore.Property) (err error)

func (*PricingRule) Save

func (p *PricingRule) Save() (ps []datastore.Property, err error)

func (*PricingRule) Validator

func (p *PricingRule) Validator() *val.Validator

type Tier

type Tier struct {
	UpTo  int64 `json:"upTo"`  // 0 = infinity (final tier)
	Price int64 `json:"price"` // cents per unit in this tier
	Flat  int64 `json:"flat"`  // flat fee for entering this tier
}

Tier represents a single pricing tier for tiered/volume pricing.

Jump to

Keyboard shortcuts

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