credit

package
v0.8.36 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("transaction not found")
	ErrInvalidUUID    = errors.New("invalid syntax of uuid")
	ErrInvalidID      = errors.New("invalid transaction id")
	ErrInvalidDetail  = errors.New("invalid transaction detail")
	ErrNotEnough      = errors.New("not enough credits")
	ErrAlreadyApplied = errors.New("credits already applied")

	// TxNamespaceUUID is the namespace for generating transaction UUIDs deterministically
	TxNamespaceUUID = uuid.MustParse("967416d0-716e-4308-b58f-2468ac14f20a")

	SourceSystemBuyEvent     = "system.buy"
	SourceSystemOnboardEvent = "system.starter"
)

Functions

This section is empty.

Types

type Credit

type Credit struct {
	ID          string
	AccountID   string
	Amount      int64
	UserID      string
	Source      string
	Description string

	Metadata metadata.Metadata
}

type Filter

type Filter struct {
	AccountID string
	Since     time.Time
}

type Service

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

func NewService

func NewService(repository TransactionRepository) *Service

func (Service) Add

func (s Service) Add(ctx context.Context, cred Credit) error

func (Service) Deduct

func (s Service) Deduct(ctx context.Context, u usage.Usage) error

func (Service) GetBalance

func (s Service) GetBalance(ctx context.Context, accountID string) (int64, error)

func (Service) GetByID added in v0.8.32

func (s Service) GetByID(ctx context.Context, id string) (Transaction, error)

func (Service) List

func (s Service) List(ctx context.Context, flt Filter) ([]Transaction, error)

type Transaction

type Transaction struct {
	ID        string
	AccountID string
	Amount    int64
	Type      TransactionType

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

	Metadata  metadata.Metadata
	CreatedAt time.Time
	UpdatedAt time.Time
}

type TransactionRepository

type TransactionRepository interface {
	CreateEntry(ctx context.Context, debit, credit Transaction) ([]Transaction, error)
	GetBalance(ctx context.Context, id string) (int64, error)
	List(ctx context.Context, flt Filter) ([]Transaction, error)
	GetByID(ctx context.Context, id string) (Transaction, error)
}

type TransactionType

type TransactionType string
const (
	TypeDebit  TransactionType = "debit"
	TypeCredit TransactionType = "credit"
)

Jump to

Keyboard shortcuts

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