mono

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2019 License: MIT Imports: 24 Imported by: 0

README

MonoBank SDK

Circle CI Docs Go Report Version

🏦 Golang client for Mono API.

Monobank API

You can find documentation for all types of API here.

  1. Introduction
  2. Documentation
  3. Using library
  4. Example
  5. Contributions

Introduction

Read access APIs for monobank app.

Please, use personal API only in non-commersial services.

If you have a service or application and you want to centrally join the API for customer service, you need to connect to a corporate API that has more features.

This will allow monobank clients to log in to your service (for example, in a financial manager) to provide information about the status of an account or statements.

Documentation

PUBLIC API

Find dedicated doc for usage of personal API here

PERSONAL API

Find dedicated doc for usage of personal API here

CORPORATE API

Find dedicated doc for usage of corporate API here

Use

This package has no dependencies, install it with command below

go get github.com/shal/mono

You can take a look and inspire by following examples

Example

package main

import (
    "fmt"
    "os"
    "time"

    "github.com/shal/mono"
)

func main() {
    personal := mono.NewPersonal("token ")

    user, err := personal.User()
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }

    from := time.Now().Add(-730 * time.Hour)
    to := time.Now()

    var account mono.Account

    for _, acc := range user.Accounts {
        ccy, _ := mono.CurrencyFromISO4217(acc.CurrencyCode)
        if ccy.Code == "UAH" {
            account = acc
        }
    }

    transactions, err := personal.Transactions(account.ID, from, to)
    if err != nil {
        fmt.Println(err.Error())
        os.Exit(1)
    }

    fmt.Printf("Account: %s\n", account.ID)

    fmt.Println("Transactions:")
    for _, transaction := range transactions {
        fmt.Printf("%d\t%s\n", transaction.Amount, transaction.Description)
    }
}

More about this example here.

Example

Contributions

You can send me some tips to MonoBank, if this package was useful.

License

Project released under the terms of the MIT license.

Documentation

Overview

Package mono implements bindings to MonoBank Developer API.

This package support 3 types of authentication:

  • Public API provides access to public endpoints with rate limitations.
  • Personal API provides access by token to your own monobank account.
  • Corporate API provides access for enterprise partners of Monobank.

The name mono stands for "MonoBank". It is short and clear.

Index

Constants

View Source
const (
	// StatementPermission provides access to balance and statement itself.
	StatementPermission byte = 's'
	// PersonalPermission provides access to client's name and surname.
	PersonalPermission byte = 'p'
)
View Source
const (
	// None is cash-back type for foreign currencies accounts.
	None = "None"
	// UAH is default cash-back type for almost all accounts.
	UAH = "UAH"
	// Miles available only on Iron Card.
	Miles = "Miles"
)
View Source
const DefaultBaseURL = "https://api.monobank.ua"

DefaultBaseURL is production URL of Monobank API.

Variables

View Source
var BaseURL = DefaultBaseURL

BaseURL is a customizable URL of API.

Functions

func ParseCustomECPrivateKey added in v0.0.14

func ParseCustomECPrivateKey(der []byte) (key *ecdsa.PrivateKey, err error)

ParseCustomECPrivateKey returns Elliptic Curve Digital Signature Algorithm private key from file content.

Types

type Account

type Account struct {
	ID           string       `json:"id"`           // Account identifier.
	Balance      int          `json:"balance"`      // Balance is minimal units (cents).
	CreditLimit  int          `json:"creditLimit"`  // Credit limit.
	CurrencyCode int32        `json:"currencyCode"` // Currency code in ISO4217.
	CashBackType CashBackType `json:"cashbackType"` // Type of cash-back.
}

Account is simple representation of bank account.

type Authorizer added in v0.0.3

type Authorizer interface {
	Auth(request *http.Request) error
}

Authorizer is an interface for different types of MonoBank API authorization.

type CashBackType added in v0.0.14

type CashBackType string

CashBackType is type of cash-back that credits to the account.

type Corporate added in v0.0.14

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

Corporate gives access to corporate methods.

func NewCorporate added in v0.0.14

func NewCorporate(keyData []byte) (*Corporate, error)

NewCorporate returns new client of MonoBank Corporate API.

func (*Corporate) Auth added in v0.0.14

func (c *Corporate) Auth(callback string, permissions ...byte) (*TokenRequest, error)

Auth initializes access.

func (*Corporate) CheckAuth added in v0.0.14

func (c *Corporate) CheckAuth(reqID string) (bool, error)

CheckAuth checks status of request for client's personal data.

func (*Corporate) GetJSON added in v0.0.14

func (c *Corporate) GetJSON(endpoint string, headers map[string]string) ([]byte, int, error)

GetJSON builds the full endpoint path and gets the raw JSON.

func (*Corporate) PostJSON added in v0.0.14

func (c *Corporate) PostJSON(endpoint string, headers map[string]string, payload io.Reader) ([]byte, int, error)

PostJSON builds the full endpoint path and gets the raw JSON.

func (*Corporate) Rates added in v0.0.14

func (c *Corporate) Rates() ([]Exchange, error)

Rates returns list of currencies rates from MonoBank API. See https://api.monobank.ua/docs/#/definitions/CurrencyInfo for details.

func (*Corporate) Transactions added in v0.0.14

func (c *Corporate) Transactions(reqID string, account string, from, to time.Time) ([]Transaction, error)

Transactions returns list of transactions from {from} till {to} time. See https://api.monobank.ua/docs/#/definitions/StatementItems for details.

func (*Corporate) User added in v0.0.14

func (c *Corporate) User(reqID string) (*UserInfo, error)

User returns user personal information from MonoBank API. See https://api.monobank.ua/docs/#/definitions/UserInfo for details.

type Currency

type Currency struct {
	Name   string
	Code   string
	Symbol string
}

Currency is internal representation of fiat currencies.

func CurrencyFromISO4217

func CurrencyFromISO4217(code int32) (Currency, error)

CurrencyFromISO4217 converts ISO4217 to matching currency.

type CurveParams added in v0.0.14

type CurveParams struct {
	elliptic.CurveParams
}

CurveParams contains the parameters of an elliptic curve and also provides a generic, non-constant time implementation of Curve.

func (*CurveParams) IsOnCurve added in v0.0.14

func (curve *CurveParams) IsOnCurve(x, y *big.Int) bool

IsOnCurve returns boolean if the point (x,y) is on the curve. Part of the elliptic.Curve interface.

func (*CurveParams) ScalarBaseMult added in v0.0.14

func (curve *CurveParams) ScalarBaseMult(k []byte) (*big.Int, *big.Int)

ScalarBaseMult returns k*G where G is the base point of the group and k is a big endian integer. Part of the elliptic.Curve interface.

func (*CurveParams) ScalarMult added in v0.0.14

func (curve *CurveParams) ScalarMult(Bx, By *big.Int, k []byte) (*big.Int, *big.Int)

ScalarMult returns k*(Bx, By) where k is a big endian integer. Part of the elliptic.Curve interface.

type Error added in v0.0.4

type Error struct {
	ErrorDescription string `json:"errorDescription"`
}

Error is a simple representation of MonoBank API error.

func (Error) Error added in v0.0.4

func (e Error) Error() string

type Exchange

type Exchange struct {
	CodeA     int32   `json:"CurrencyCodeA"`
	CodeB     int32   `json:"CurrencyCodeB"`
	Date      int32   `json:"Date"`
	RateSell  float64 `json:"RateSell"`
	RateBuy   float64 `json:"RateBuy"`
	RateCross float64 `json:"RateCross"`
}

Exchange contains market buy/sell rates. See https://api.monobank.ua/docs/#/definitions/CurrencyInfo for details.

func (*Exchange) Base

func (ex *Exchange) Base() (Currency, error)

Base returns normal representation of CurrencyCodeA.

func (*Exchange) Quote

func (ex *Exchange) Quote() (Currency, error)

Quote returns normal representation of CurrencyCodeB.

type Personal added in v0.0.14

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

Personal gives access to personal methods.

func NewPersonal added in v0.0.14

func NewPersonal(token string) *Personal

NewPersonal returns new client of MonoBank Personal API.

func (*Personal) GetJSON added in v0.0.14

func (ac *Personal) GetJSON(endpoint string, headers map[string]string) ([]byte, int, error)

GetJSON builds the full endpoint path and gets the raw JSON.

func (*Personal) PostJSON added in v0.0.14

func (ac *Personal) PostJSON(
	endpoint string,
	headers map[string]string,
	payload io.Reader,
) ([]byte, int, error)

PostJSON builds the full endpoint path and gets the raw JSON.

func (*Personal) Rates added in v0.0.14

func (p *Personal) Rates() ([]Exchange, error)

Rates returns list of currencies rates from MonoBank API. See https://api.monobank.ua/docs/#/definitions/CurrencyInfo for details.

func (*Personal) SetWebHook added in v0.0.14

func (p *Personal) SetWebHook(url string) ([]byte, error)

SetWebHook sets WebHook URL for authorized user. See https://api.monobank.ua/docs#operation--personal-webhook-post for details.

func (*Personal) Transactions added in v0.0.14

func (p *Personal) Transactions(account string, from, to time.Time) ([]Transaction, error)

Transactions returns list of transactions from {from} till {to} time. See https://api.monobank.ua/docs/#/definitions/StatementItems for details.

func (*Personal) User added in v0.0.14

func (p *Personal) User() (*UserInfo, error)

User returns user personal information from MonoBank API. See https://api.monobank.ua/docs/#operation--personal-client-info-get for details.

type Public added in v0.0.14

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

Public gives access to public methods.

func NewPublic added in v0.0.14

func NewPublic() *Public

NewPublic returns new client of MonoBank Public API.

func (*Public) GetJSON added in v0.0.14

func (c *Public) GetJSON(endpoint string, headers map[string]string) ([]byte, int, error)

GetJSON builds the full endpoint path and gets the raw JSON.

func (*Public) PostJSON added in v0.0.14

func (c *Public) PostJSON(
	endpoint string,
	headers map[string]string,
	payload io.Reader,
) ([]byte, int, error)

PostJSON builds the full endpoint path and gets the raw JSON.

func (*Public) Rates added in v0.0.14

func (c *Public) Rates() ([]Exchange, error)

Rates returns list of currencies rates from MonoBank API. See https://api.monobank.ua/docs/#/definitions/CurrencyInfo for details.

type SignTool added in v0.0.14

type SignTool struct {
	B2A func([]byte) string
	A2B func(string) ([]byte, error)
}

SignTool it utility, which helps to sign message.

func DefaultSignTool added in v0.0.14

func DefaultSignTool() *SignTool

DefaultSignTool returns new instance of SignTool SignTool with default encoding parameters.

func (*SignTool) DecodePrivateKey added in v0.0.14

func (t *SignTool) DecodePrivateKey(b []byte) (*ecdsa.PrivateKey, error)

DecodePrivateKey decodes privage key into Elliptic Curve Digital Signature Algorithm private key.

func (*SignTool) Sign added in v0.0.14

func (t *SignTool) Sign(key *ecdsa.PrivateKey, str string) (string, error)

Sign signs string with specified private key.

func (*SignTool) VerifyBytes added in v0.0.14

func (t *SignTool) VerifyBytes(pubkey *ecdsa.PublicKey, b []byte, s string) error

VerifyBytes verifies a digital signature. Returns nil if all is well or an error indicating what went wrong. The equivalent command at the command line is: echo -n 'Make America Great Again!' | openssl dgst -verify pub1.pem -signature signature.dat

func (*SignTool) VerifyBytesN added in v0.0.14

func (t *SignTool) VerifyBytesN(pubkeys []*ecdsa.PublicKey, b []byte, s string) error

VerifyBytesN verifies with multiple public keys possibly matching.

type TokenRequest added in v0.0.14

type TokenRequest struct {
	TokenRequestID string `json:"tokenRequestId"` // Unique token request ID.
	AcceptURL      string `json:"acceptUrl"`      // URL to redirect client or build QR on top of it.
}

TokenRequest is representation of payload, received on corporate auth.

type Transaction added in v0.0.14

type Transaction struct {
	ID              string `json:"id"`              // Unique transaction ID.
	Time            int32  `json:"time"`            // Unix time of transaction.
	Description     string `json:"description"`     // Message attached to transaction.
	MCC             int32  `json:"mcc"`             // Merchant Category Code using ISO18245.
	Hold            bool   `json:"hold"`            // Authorization hold.
	Amount          int64  `json:"amount"`          // Amount in account currency (cents).
	OperationAmount int64  `json:"operationAmount"` // Amount in transaction currency (cents).
	CurrencyCode    int32  `json:"currencyCode"`    // Currency code using ISO4217.
	CommissionRate  int64  `json:"commissionRate"`  // Amount of commission in account currency.
	CashBackAmount  int64  `json:"cashbackAmount"`  // Amount of cash-back in account currency.
	Balance         int64  `json:"balance"`         // Balance in account currency.
}

Transaction is a banking transaction.

type UserInfo

type UserInfo struct {
	Name       string    `json:"name"`       // User name.
	WebHookURL string    `json:"webHookUrl"` // URL for receiving new transactions.
	Accounts   []Account `json:"accounts"`   // List of available accounts
}

UserInfo is an overview of user and related accounts.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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