mono

package module
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 25 Imported by: 4

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

As far as monobank have 3 types of API, we prepated three usage documentations:

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(context.Background())
    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(context.Background(), 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

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 DefaultBaseURL = "https://api.monobank.ua"

DefaultBaseURL is production URL of Monobank API.

Variables

This section is empty.

Functions

func ParseCustomECPrivateKey added in v0.0.11

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.
	Type         AccountType  `json:"type"`         // Type of card.
	IBAN         string       `json:"iban"`         // IBAN.
	MaskedPan    []string     `json:"maskedPan"`
}

Account is simple representation of bank account.

type AccountType added in v0.2.2

type AccountType string

AccountType is type of the account.

const (
	Platinum AccountType = "platinum"
	White    AccountType = "white"
	Black    AccountType = "black"
	FOP      AccountType = "fop"
)

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.11

type CashBackType string

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

const (
	// None is cash-back type for foreign currencies accounts.
	None CashBackType = "None"
	// UAH is default cash-back type for almost all accounts.
	UAH CashBackType = "UAH"
	// Miles available only on Iron Card.
	Miles CashBackType = "Miles"
)

type Corporate added in v0.0.11

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

Corporate gives access to corporate methods.

func NewCorporate added in v0.0.11

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

NewCorporate returns new client of MonoBank Corporate API.

func (*Corporate) Auth added in v0.0.11

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

Auth initializes access.

func (*Corporate) CheckAuth added in v0.0.11

func (c *Corporate) CheckAuth(ctx context.Context, reqID string) (bool, error)

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

func (*Corporate) GetJSON added in v0.0.11

func (c *Corporate) GetJSON(ctx context.Context, 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.11

func (c *Corporate) PostJSON(ctx context.Context, 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(ctx context.Context) ([]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.11

func (c *Corporate) Transactions(ctx context.Context, 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.11

func (c *Corporate) User(ctx context.Context, 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.11

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.11

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.11

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.11

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.11

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

Personal gives access to personal methods.

func NewPersonal added in v0.0.11

func NewPersonal(token string) *Personal

NewPersonal returns new client of MonoBank Personal API.

func (*Personal) GetJSON added in v0.0.11

func (ac *Personal) GetJSON(ctx context.Context, 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.11

func (ac *Personal) PostJSON(
	ctx context.Context,
	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.11

func (p *Personal) Rates(ctx context.Context) ([]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.11

func (p *Personal) SetWebHook(ctx context.Context, 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.11

func (p *Personal) Transactions(ctx context.Context, 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.11

func (p *Personal) User(ctx context.Context) (*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.11

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

Public gives access to public methods.

func NewPublic added in v0.0.11

func NewPublic() *Public

NewPublic returns new client of MonoBank Public API.

func (*Public) GetJSON added in v0.0.11

func (c *Public) GetJSON(ctx context.Context, 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.11

func (c *Public) PostJSON(
	ctx context.Context,
	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.11

func (c *Public) Rates(ctx context.Context) ([]Exchange, error)

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

func (*Public) SetBaseURL added in v0.2.1

func (c *Public) SetBaseURL(url string)

SetBaseURL set baseURL to the new specified URL.

type SignTool added in v0.0.11

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.11

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.11

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.11

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.11

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

VerifyBytesN verifies with multiple public keys possibly matching.

type Time added in v0.2.3

type Time struct {
	time.Time
}

Time defines a timestamp encoded as epoch seconds in JSON Most of it's code taken from https://github.com/pieterclaerhout/example-json-unixtimestamp/blob/master/cmd/example-json-timestamp/time.go

func (Time) MarshalJSON added in v0.2.3

func (t Time) MarshalJSON() ([]byte, error)

MarshalJSON is used to convert the timestamp to JSON

func (*Time) UnmarshalJSON added in v0.2.3

func (t *Time) UnmarshalJSON(s []byte) (err error)

UnmarshalJSON is used to convert the timestamp from JSON

type TokenRequest added in v0.0.11

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.11

type Transaction struct {
	ID              string `json:"id"`              // Unique transaction ID.
	Time            Time   `json:"time"`            // UTC 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
personal Module
public Module

Jump to

Keyboard shortcuts

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