bank

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 7, 2023 License: Unlicense Imports: 5 Imported by: 0

Documentation

Overview

Package bank defines an interface for connecting and fetching data from online banks. This package is designed with the hope that many different bank back-ends can conform to the interface.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadPwd must be used when the password does not match the specifications or is incorrect.
	ErrBadPwd error = errors.New("invalid password")
	// ErrBadLoginPwd must be used when the login OR password does not match the
	// specifications or are incorrect.
	ErrBadLoginPwd error = errors.New("invalid login or password")
	// ErrNotLoggedIn is returned when the user is not authenticated.
	ErrNotLoggedIn error = errors.New("not logged in")
)

Functions

func Banks

func Banks() []string

Banks returns the sorted list of registered banking instancers.

func SetBank

func SetBank(name string, b NewBank)

SetBank registers a banking instancer.

Types

type Account

type Account struct {
	ID      string
	Name    string
	Type    AccountType
	Balance money.Money
}

An Account is a financial account maintained by a bank.

type AccountType

type AccountType int

AccountType is the type of an account. For instance, it can be a stock account.

const (
	AccountChecking AccountType = iota
	AccountSavings
	AccountStocks
)

type Bank

type Bank interface {
	// Login connects to the bank. Credentials may have been given when
	// instancing the bank. Questions like 2FA code may be asked through the
	// prompt channel (this method will block until it gets an answer).
	Login(username, pwd []byte, ctx context.Context, q chan<- string, a <-chan string) error
	// Logout disconnects from the bank. It may returns ErrNotLoggedIn if the
	// user is already disconnected.
	Logout() error

	// Accounts returns the user's accounts.
	Accounts() ([]*Account, error)
	// Transactions returns the list of transactions of a specified account that
	// occured after a defined time.
	Transactions(account *Account, debitUpTo time.Time) ([]*Transaction, error)
}

A Bank is the main interface or connecting and fetching data from online banks.

type NewBank

type NewBank func() Bank

NewBank is the function that returns an instance of a Bank. Multiple accounts in the same bank can thus be handled properly.

func GetBank

func GetBank(name string) (b NewBank, ok bool)

GetBank returns a specific bank instancer.

type Transaction

type Transaction struct {
	ID        string
	Pending   bool
	DateDebit time.Time
	DateDone  time.Time
	RawName   string
	Name      string
	Card      string
	Type      TransactionType
	Category  string
	Value     money.Money
}

A Transaction is a record of money that has moved in or out an account.

type TransactionType

type TransactionType int
const (
	TransactionNone TransactionType = iota
	TransactionCard
	TransactionTrsf
	TransactionTrsfSEPA
	TransactionDDebitSEPA
	TransactionTrsfINST
	TransactionCredit
)

type UnrecognizedError

type UnrecognizedError string

An UnrecognizedError is an unhandled error returned by the bank.

func (UnrecognizedError) Error

func (e UnrecognizedError) Error() string

Jump to

Keyboard shortcuts

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