credit

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 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")
	ErrInsufficientCredits = errors.New("insufficient 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"
	SourceSystemAwardedEvent = "system.awarded"
	SourceSystemOnboardEvent = "system.starter"
	SourceSystemRevertEvent  = "system.revert"
)

Functions

This section is empty.

Types

type Credit

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

	Metadata metadata.Metadata
}

type Filter

type Filter struct {
	CustomerID string
	StartRange time.Time
	EndRange   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, cred Credit) 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
	CustomerID 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 (
	DebitType  TransactionType = "debit"
	CreditType TransactionType = "credit"
)

func (TransactionType) String added in v0.8.37

func (t TransactionType) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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