usage

package
v0.32.3 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExistingRevertedUsage = fmt.Errorf("a reverted usage cannot be reverted again")
	ErrRevertAmountExceeds   = fmt.Errorf("revert amount is greater than the usage amount")
)

Functions

This section is empty.

Types

type CreditService

type CreditService interface {
	Add(ctx context.Context, cred credit.Credit) error
	Deduct(ctx context.Context, cred credit.Credit) error
	GetByID(ctx context.Context, id string) (credit.Transaction, error)
}

type Service

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

func NewService

func NewService(transactionService CreditService) *Service

func (Service) Report

func (s Service) Report(ctx context.Context, usages []Usage) error

func (Service) Revert added in v0.8.37

func (s Service) Revert(ctx context.Context, customerID, usageID string, amount int64) error

type Type

type Type string
const (
	CreditType  Type = "credit"
	FeatureType Type = "feature"
)

func (Type) String added in v0.8.37

func (t Type) String() string

type Usage

type Usage struct {
	ID         string
	CustomerID string

	// Source is the source app or event that caused the transaction
	Source      string
	Description string
	// UserID is the user who initiated the transaction
	UserID string

	// Type is the type of usage, it can be credit or feature
	// if credit, the amount is the amount of credits that were consumed
	// if feature, the amount is the amount of features that were used
	Type   Type
	Amount int64

	CreatedAt time.Time
	Metadata  metadata.Metadata
}

Jump to

Keyboard shortcuts

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