Documentation ¶
Index ¶
- Variables
- func TxUUID(tags ...string) string
- type Credit
- type Filter
- type Service
- func (s Service) Add(ctx context.Context, cred Credit) error
- func (s Service) Deduct(ctx context.Context, cred Credit) error
- func (s Service) GetBalance(ctx context.Context, accountID string) (int64, error)
- func (s Service) GetBalanceForRange(ctx context.Context, accountID string, start time.Time, end time.Time) (int64, error)
- func (s Service) GetByID(ctx context.Context, id string) (Transaction, error)
- func (s Service) List(ctx context.Context, flt Filter) ([]Transaction, error)
- type Transaction
- type TransactionRepository
- type TransactionType
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" SourceSystemOverdraftEvent = "system.overdraft" )
Functions ¶
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(repository TransactionRepository) *Service
func (Service) GetBalance ¶
func (Service) GetBalanceForRange ¶ added in v0.41.0
func (s Service) GetBalanceForRange(ctx context.Context, accountID string, start time.Time, end time.Time) (int64, error)
GetBalanceForRange returns the balance for the given accountID within the given time range start time is inclusive, end time is exclusive
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) GetBalanceForRange(ctx context.Context, accountID string, start time.Time, end time.Time) (int64, 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
Click to show internal directories.
Click to hide internal directories.