lineservice

package
v1.0.0-beta.189 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

lineservice package contains the implementation of the LineAdapter interface which acts as a adapter between the specific line types and the billing service.

This package allows us to not to have line type specific implementation details in the billing service. (Which is already quite complex)

Index

Constants

View Source
const (
	FlatPriceChildUniqueReferenceID         = "flat-price"
	UnitPriceUsageChildUniqueReferenceID    = "unit-price-usage"
	UnitPriceMinSpendChildUniqueReferenceID = "unit-price-min-spend"
	UnitPriceMaxSpendChildUniqueReferenceID = "unit-price-max-spend"

	VolumeFlatPriceChildUniqueReferenceID = "volume-flat-price"
	VolumeUnitPriceChildUniqueReferenceID = "volume-tiered-price"
	VolumeMinSpendChildUniqueReferenceID  = "volume-min-spend"

	GraduatedTieredPriceUsageChildUniqueReferenceID = "graduated-tiered-%d-price-usage"
	GraduatedTieredFlatPriceChildUniqueReferenceID  = "graduated-tiered-%d-flat-price"
	GraduatedMinSpendChildUniqueReferenceID         = "graduated-tiered-min-spend"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CanBeInvoicedAsOfInput

type CanBeInvoicedAsOfInput = InvoicingCapabilityQueryInput

type Config

type Config struct {
	BillingAdapter     billing.Adapter
	FeatureService     feature.FeatureConnector
	MeterRepo          meter.Repository
	StreamingConnector streaming.Connector
}

func (Config) Validate

func (c Config) Validate() error

type InvoicingCapabilityQueryInput

type InvoicingCapabilityQueryInput struct {
	AsOf               time.Time
	ProgressiveBilling bool
}

type Line

type Line interface {
	LineBase

	Service() *Service

	Validate(context.Context, *billing.Invoice) error
	CanBeInvoicedAsOf(context.Context, CanBeInvoicedAsOfInput) (*billing.Period, error)
	SnapshotQuantity(context.Context, *billing.Invoice) error
	CalculateDetailedLines() error
	PrepareForCreate(context.Context) (Line, error)
	UpdateTotals() error
}

type LineBase

type LineBase interface {
	ToEntity() *billing.Line
	ID() string
	InvoiceID() string
	Currency() currencyx.Code
	Period() billing.Period
	Status() billing.InvoiceLineStatus
	HasParent() bool
	// IsLastInPeriod returns true if the line is the last line in the period that is going to be invoiced.
	IsLastInPeriod() bool
	IsDeleted() bool
	IsSplit() bool

	CloneForCreate(in UpdateInput) Line
	Update(in UpdateInput) Line
	Save(context.Context) (Line, error)

	// Split splits a line into two lines at the given time.
	// The strategy is that we will have a line with status InvoiceLineStatusSplit and two child
	// lines with status InvoiceLineStatusValid.
	//
	// To make algorithms easier, upon next split, we will not create an imbalanced tree, but rather attach
	// the new split line to the existing parent line.
	Split(ctx context.Context, at time.Time) (SplitResult, error)

	Service() *Service
	ResetTotals()
}

type LineWithBillablePeriod

type LineWithBillablePeriod struct {
	Line
	BillablePeriod billing.Period
}

type Lines

type Lines []Line

func (Lines) ResolveBillablePeriod

func (s Lines) ResolveBillablePeriod(ctx context.Context, in ResolveBillablePeriodInput) ([]LineWithBillablePeriod, error)

func (Lines) ToEntities

func (s Lines) ToEntities() []*billing.Line

type ResolveBillablePeriodInput

type ResolveBillablePeriodInput = InvoicingCapabilityQueryInput

type Service

type Service struct {
	Config
	// contains filtered or unexported fields
}

func New

func New(in Config) (*Service, error)

func (*Service) AssociateLinesToInvoice

func (s *Service) AssociateLinesToInvoice(ctx context.Context, invoice *billing.Invoice, lines Lines) (Lines, error)

func (*Service) FromEntities

func (s *Service) FromEntities(line []*billing.Line) (Lines, error)

func (*Service) FromEntity

func (s *Service) FromEntity(line *billing.Line) (Line, error)

func (*Service) UpsertLines

func (s *Service) UpsertLines(ctx context.Context, ns string, lines ...Line) (Lines, error)

type SplitResult

type SplitResult struct {
	PreSplitAtLine  Line
	PostSplitAtLine Line
}

type UpdateInput

type UpdateInput struct {
	ParentLine  mo.Option[*billing.Line]
	PeriodStart time.Time
	PeriodEnd   time.Time
	InvoiceAt   time.Time
	Status      billing.InvoiceLineStatus

	// PreventChildChanges is used to prevent any child changes to the line by the adapter.
	PreventChildChanges bool

	ResetChildUniqueReferenceID bool
}

Jump to

Keyboard shortcuts

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