pricingrule

package
v1.42.4 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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[PricingRule]

	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) 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