bmlgo

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2020 License: MPL-2.0 Imports: 9 Imported by: 0

README

BMLGo

Go bindings for the BML internet banking API

Getting Started

Install the package using the following command

go get -u github.com/umran/bmlgo

Usage

Instantiating a Client

Before interacting with the API a Client must be instantiated

import "github.com/umran/bmlgo"

func main() {
    client, err := bmlgo.NewClient("username", "password")
    if err != nil {
        panic("failed to create client", err)
    }
}
Getting New Statement Items

New items posted to an account's statement can be retrieved by calling the client's GetNewStatementItems method. This method returns either all items posted to the account within the past year (up to the current date) or all items posted after a specified item. This method also returns a cursor, which is the ID of the most recently posted item.

To get all items posted after a specified item, we must provide the item's ID as the cursor

items, nextCursor, err := client.GetNewStatementItems("accountID", "cursor")
if err != nil {
    panic("failed to get new statement items", err)
}

for _, item := range items {
    fmt.Println(item.Amount)
}

To get all items posted within the past year (up to the current date), we must leave the cursor blank

client.GetNewStatementItems("accountID", "")
Making Money Transfers

Money transfers can be initiated by calling the client's InitiateTransfer method. The amount of the transfer must be provided in Laari as an integer. The debit account and credit accounts must also be provided.

To complete a transfer we must call the client's CompleteTransfer method with the transfer form returned by InitiateTransfer and the OTP received via email or SMS.

Here's an example where we transfer 1 Rufiyaa (100 Laari) from "AccountA" to "AccountB"

transferForm, err := client.InitiateTransfer(100, "AccountA", "AccountB")
if err != nil {
    panic("couldn't initiate transfer", err)
}

// then when the OTP is available
transferRecord, err := client.CompleteTransfer(transferForm, "OTP")
if err != nil {
    panic("couldn't complete transfer", err)
}

fmt.Println(transferRecord.Reference)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorAuthenticationFailed ...
	ErrorAuthenticationFailed = errors.New("Authentication Failed")
	// ErrorNotAuthenticated ...
	ErrorNotAuthenticated = errors.New("Not Authenticated")
	// ErrorUnexpectedCode ...
	ErrorUnexpectedCode = errors.New("Unexpected Code")
	// ErrorUnexpectedStatusCode ...
	ErrorUnexpectedStatusCode = errors.New("Unexpected Status Code")
	// ErrorCursorUnreachable ...
	ErrorCursorUnreachable = errors.New("Cursor Unreachable")
)

Functions

This section is empty.

Types

type ActivityContent

type ActivityContent struct {
	Data         []*ActivityData `json:"data"`
	From         int             `json:"from"`
	To           int             `json:"to"`
	PerPage      int             `json:"per_page"`
	Total        int             `json:"total"`
	CurrentPage  int             `json:"current_page"`
	LastPage     int             `json:"last_page"`
	FirstPageURL string          `json:"first_page_url"`
	LastPageURL  string          `json:"last_page_url"`
	NextPageURL  string          `json:"next_page_url"`
	PrevPageURL  string          `json:"prev_page_url"`
	Path         string          `json:"path"`
}

ActivityContent ...

type ActivityData

type ActivityData struct {
	Content         []*ActivityDataContent
	CreditName      string `json:"creditName"`
	DateTime        string `json:"dateTime"`
	FormattedAmount string `json:"formattedAmount"`
	Message         string `json:"message"`
	Status          string `json:"status"`
	Type            string `json:"type"`
}

ActivityData ...

type ActivityDataContent

type ActivityDataContent struct {
	Name  string `json:"name"`
	Type  string `json:"type"`
	Value string `json:"value"`
}

ActivityDataContent ...

type ActivityPayload

type ActivityPayload struct {
	Content *ActivityContent `json:"content"`
}

ActivityPayload ...

type AuthPayload

type AuthPayload int

AuthPayload ...

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client ...

func NewClient

func NewClient(username, password string) (*Client, error)

NewClient ...

func (*Client) CompleteTransfer

func (c *Client) CompleteTransfer(request url.Values, otp string) (*TransferCompletionPayload, error)

CompleteTransfer ...

func (*Client) GetNewStatementItems

func (c *Client) GetNewStatementItems(accountID, cursor string) ([]*HistoryItem, string, error)

GetNewStatementItems ...

func (*Client) InitiateTransfer

func (c *Client) InitiateTransfer(amount int, debitAccount, creditAccount string) (url.Values, error)

InitiateTransfer ...

type HistoryItem

type HistoryItem struct {
	ID          string  `json:"id"`
	Reference   string  `json:"reference"`
	Amount      float64 `json:"amount"`
	Currency    string  `json:"currency"`
	Minus       bool    `json:"minus"`
	BookingDate string  `json:"bookingDate"`
	ValueDate   string  `json:"valueDate"`
	Narrative1  string  `json:"narrative1"`
	Narrative2  string  `json:"narrative2"`
	Narrative3  string  `json:"narrative3"`
	Narrative4  string  `json:"narrative4"`
	Description string  `json:"description"`
}

HistoryItem ...

type HistoryPayload

type HistoryPayload struct {
	CurrentPage int            `json:"currentPage"`
	TotalPages  int            `json:"totalPages"`
	History     []*HistoryItem `json:"history"`
}

HistoryPayload ...

type Response

type Response struct {
	Success bool        `json:"success"`
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Payload interface{} `json:"payload"`
}

Response ...

type TransferCompletionPayload

type TransferCompletionPayload struct {
	Reference string `json:"reference"`
	Timestamp string `json:"timestamp"`
}

TransferCompletionPayload ...

Jump to

Keyboard shortcuts

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