payment

package
v0.0.0-...-b1e0156 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package payment provides handlers for work with payments in the system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MakeHandler

func MakeHandler(s Service, logger kitlog.Logger) http.Handler

MakeHandler returns a handler for the payment service.

Types

type Direction

type Direction string

Direction of payment regarding account.

const (
	Incoming Direction = "incoming"
	Outgoing Direction = "outgoing"
)

type Payment

type Payment struct {
	ID          uuid.UUID       `json:"-" sql:"id,pk,type:varchar(36)"`
	Account     account.ID      `json:"account" sql:"type:varchar(255)" pg:"fk:base_account_id"`
	Amount      decimal.Decimal `json:"amount" sql:"amount,notnull,type:'decimal(16,4)'"`
	ToAccount   account.ID      `json:"to_account,omitempty" sql:"to_account,type:varchar(255)" pg:"fk:to_account_id"`
	FromAccount account.ID      `json:"from_account,omitempty" sql:"from_account,type:varchar(255)" pg:"fk:from_account_id"`
	Direction   Direction       `json:"direction" sql:"direction,notnull,type:varchar(16)"`
	Deleted     bool            `json:"-" sql:"deleted,notnull"`
}

Payment holding a money transfer between two accounts in the system.

type Repository

type Repository interface {
	// Store payments in the repository.
	Store(payment ...*Payment) error

	// Find payments list for an account.
	Find(id account.ID) []*Payment

	// FindAll returns all payments, registered in the system.
	FindAll() []*Payment

	// MarkDeleted is mark as deleted specified payment in the system
	MarkDeleted(id uuid.UUID) error
}

Repository interface for payment storing and operations.

type Service

type Service interface {
	// New registers a new payment in the system.
	New(fromAccountID account.ID, amount decimal.Decimal, toAccountID account.ID) error

	// Load returns payments list for an account.
	Load(accountID account.ID) []*Payment

	// LoadAll returns all payments, registered in the system.
	LoadAll() []*Payment
}

Service is the interface that provides payment methods.

func NewLoggingService

func NewLoggingService(logger log.Logger, s Service) Service

NewLoggingService returns a new instance of a logging Service.

func NewMetricsService

func NewMetricsService(counter metrics.Counter, latency metrics.Histogram, s Service) Service

NewMetricsService returns an instance of a metrics Service.

func NewService

func NewService(payments Repository, accounts account.Repository) Service

NewService creates a payment service with necessary dependencies.

Jump to

Keyboard shortcuts

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