bank

package module
v0.0.0-...-fded77c Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 9 Imported by: 0

README

Bank

A Go program to look up Australian BSB numbers. The data is downloaded from AusPayNet, and statically stored in the app.

Usage

CLI

Install the bsblookup cli, to use it as a command.

$ go install github.com/lfsgroup/bank/cmd/bsblookup@latest

Then run from the command line prompt:

$ bsblookup 012-023
BSB_NUMBER="012-023"
BANK_CODE="ANZ"
BANK_NAME="Australia & New Zealand Banking Group Limited"
BRANCH_NAME="ANZ Wealth Australia Limited"
BRANCH_ADDRESS="347 Kent Street Sydney NSW 2000"
BRANCH_PAYMENTS_FLAGS="PEH"
Go package

You can import bank as a Go package, and use in an existing Go project.

$ go get -u github.com/lfsgroup/bank

Then just import ...

import "github.com/lfsgroup/bank"

and call the bank.LookupBSB function ...

branch, err := bank.LookupBSB("012-023")
if err != nil {
   log.Fatalln("Lookup BSB error:", err)
}
fmt.Println("Bank name for 012-023 is", branch.Bank.Name)
HTTP Service

bankd is a standalone webserver that can be used to request a bank's BSB number over HTTP.

Build the app ...

$ go build ./cmd/bankd

Run the app ...

$ PORT=4000 ./bankd
2022/05/11 12:40:50 Server starting on port 4000
$ curl http://localhost:4000/bsb/012-023
{"bsb":"012-023","name":"ANZ Wealth Australia Limited","bank":{"code":"ANZ","name":"Australia \u0026 New Zealand Banking Group Limited","bsb_numbers":"1"},"bank_code":"ANZ","address":"347 Kent Street","suburb":"Sydney","state":"NSW","postcode":"2000","payments_flags":"PEH"}
AWS Lambda

You can also deploy the bank as a standalone AWS Lambda service.

Build the lambda

$ make build

This will build a file call build/bsblookup.zip. You can either upload this file directly in the AWS Lambda console or run the following command using aws cli:

$ aws lambda update-function-code --function-name bsblookup --zip-file fileb://$PWD/build/bsblookup.zip

This assumed you created a Lambda function called bsblookup.

Bugs / Issues

  • Write tests
    • Need to write some tests for the loading and parsing of the data.

Documentation

Overview

bank performs BSB Number lookups to find bank and branch details

Data Source: https://bsb.auspaynet.com.au/

Index

Constants

View Source
const (
	PaperClearing      = 1 << iota // P=Paper (APCS)
	ElectronicClearing             // E=Electronic (IAC)
	HighValueClearing              // H=High Value (HVCS)
)
View Source
const MaxBSB = 999999

MaxBSB is the maximum number a BSB can hold, as it's only 6 digits.

Variables

View Source
var ErrBranchNotFound = errors.New("branch not found")
View Source
var ErrInvalidBSB = errors.New("invalid BSB number")

Functions

This section is empty.

Types

type BSB

type BSB uint32

BSB is an Australian Bank State Branch number. It is a code used for domestic payments within Australia.

func MustBSB

func MustBSB(bsb string) BSB

MustBSB return a new BSB type. Will panic if invalid.

func NewBSB

func NewBSB(bsb string) (BSB, error)

NewBSB parses a string of the BSB number and returns a valid BSB type. If the string is not a valid BSB number an error is returned.

Valid formats:

	nnn-nnn		example "123-456" will be 123-456

	nnnnnn 		will convert to nnn-nnn, example "123456" will be 123-456

	nnnnn 		will convert to 0nn-nnn, example "12345" will be 012-345

Where n is an ascii digit

func (BSB) MarshalJSON

func (b BSB) MarshalJSON() ([]byte, error)

MarshalJSON marshals the BSB number into JSON format.

func (BSB) String

func (b BSB) String() string

String return the BSB number in the format nnn-nnn, where n is a digit. Example:

"123-456"

func (*BSB) UnmarshalJSON

func (b *BSB) UnmarshalJSON(data []byte) error

MarshalJSON unmarshal's JSON into a BSB number.

type Branch

type Branch struct {
	BSB           BSB             `json:"bsb,omitempty"`
	Name          string          `json:"name,omitempty"`
	Bank          Institution     `json:"bank,omitempty"`
	BankCode      string          `json:"bank_code,omitempty"`
	Address       string          `json:"address,omitempty"`
	Suburb        string          `json:"suburb,omitempty"`
	State         string          `json:"state,omitempty"`
	Postcode      string          `json:"postcode,omitempty"`
	PaymentsFlags ClearingSystems `json:"payments_flags,omitempty"`
}

func LookupBSB

func LookupBSB(bsb string) (Branch, error)

type ClearingSystems

type ClearingSystems byte

The payments flags refer to the clearing systems (frameworks) with P=Paper (APCS), E=Electronic (IAC) and H=High Value (HVCS).

const ClosedClearingSystem ClearingSystems = 0

ClosedClearingSystem is closed

func NewClearingSystems

func NewClearingSystems(flags string) ClearingSystems

NewClearingSystems parses the list of flags into a ClearingSystems type. The ClearingsSystem contains all the avaliable clearing systems. If no flags are provided a Closed clearing system is returned.

func (ClearingSystems) Closed

func (cs ClearingSystems) Closed() bool

Closed returns true is the clearing system is closed

func (ClearingSystems) Electronic

func (cs ClearingSystems) Electronic() bool

Electronic returns true if Electronic clearing system (IAC) is avaliable

func (ClearingSystems) HighValue

func (cs ClearingSystems) HighValue() bool

HighValue returns true if HighValue clearing system (HVCS) is avaliable

func (ClearingSystems) MarshalJSON

func (cs ClearingSystems) MarshalJSON() ([]byte, error)

MarshalJSON marshals the ClearingSystems into JSON format.

func (ClearingSystems) Paper

func (cs ClearingSystems) Paper() bool

Paper returns true if Paper clearing system (APCS) is avaliable

func (ClearingSystems) String

func (cs ClearingSystems) String() string

String returns a list of the avaliable clearing systems. P=Paper (APCS), E=Electronic (IAC) and H=High Value (HVCS). An empty string is returned if closed.

func (*ClearingSystems) UnmarshalJSON

func (cs *ClearingSystems) UnmarshalJSON(data []byte) error

MarshalJSON unmarshal's JSON into a ClearingSystems type.

type Institution

type Institution struct {
	Code       string `json:"code,omitempty"`
	Name       string `json:"name,omitempty"`
	BSBNumbers string `json:"bsb_numbers,omitempty"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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