credit

package
v0.8.18 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2024 License: Apache-2.0 Imports: 7 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")
)

Functions

This section is empty.

Types

type Credit

type Credit struct {
	ID          string
	AccountID   string
	Amount      int64
	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) 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      string
	Description 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