monobank

package module
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2020 License: MIT Imports: 10 Imported by: 0

README

go-monobank

Godoc Reference CI codecov

Monobank REST API client. Currently, supported only personal authorization(with Token).

Usage

package main

import (
    "context"
    "fmt"
    "os"

    "github.com/vtopc/go-monobank"
)

func main(){
    client := monobank.New(nil).WithAuth(monobank.NewPersonalAuthorizer(os.Getenv("TOKEN")))
    response, _ := client.ClientInfo(context.Background())
    fmt.Println(response)
}

Official docs

Similar projects

TODO

  • Corporate Authorization
  • Corporate API(init/check auth)
  • More unit tests

Documentation

Overview

Package mono - is MonoBank API client https://api.monobank.ua/docs/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	AccountID    string   `json:"id"`
	Balance      int64    `json:"balance"`
	CreditLimit  int64    `json:"creditLimit"`
	CurrencyCode int      `json:"currencyCode"`
	CashbackType string   `json:"cashbackType"` // enum: None, UAH, Miles
	CardMasks    []string `json:"maskedPan"`    // card number masks
	Type         CardType `json:"type"`
}

type Accounts

type Accounts []Account

type Authorizer

type Authorizer interface {
	// SetAuth modifies http.Request and sets authorization tokens
	SetAuth(*http.Request) error
}

type CardType added in v0.6.0

type CardType string
const (
	Black    CardType = "black"
	White    CardType = "white"
	Platinum CardType = "platinum"
)

type Client

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

func New

func New(client *http.Client) Client

New - returns new monobank Client

func (Client) Auth added in v0.7.0

func (c Client) Auth(ctx context.Context, callbackURL string) (*TokenRequest, error)

Auth initializes access.

func (Client) CheckAuth added in v0.7.0

func (c Client) CheckAuth(ctx context.Context) error

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

func (Client) ClientInfo

func (c Client) ClientInfo(ctx context.Context) (*ClientInfo, error)

func (Client) Currency

func (c Client) Currency(ctx context.Context) (Currencies, error)

func (Client) SetWebHook

func (c Client) SetWebHook(ctx context.Context, uri string) error

func (Client) Transactions added in v0.2.0

func (c Client) Transactions(ctx context.Context, accountID string, from, to time.Time) (
	Transactions, error)

TODO: make `to` optional

func (Client) WithAuth

func (c Client) WithAuth(auth Authorizer) Client

WithAuth returns copy of Client with authorizer

func (Client) WithBaseURL

func (c Client) WithBaseURL(uri string) Client

WithAuth returns copy of Client with overridden baseURL

type ClientInfo

type ClientInfo struct {
	Name       string   `json:"name"`
	WebHookURL string   `json:"webHookUrl"`
	Accounts   Accounts `json:"accounts"`
}

ClientInfo - client/user info

type CorporateAPI added in v0.7.0

type CorporateAPI interface {
	PersonalAPI
}

type Currencies

type Currencies []Currency

type Currency

type Currency struct {
	CurrencyCodeA int           `json:"currencyCodeA"`
	CurrencyCodeB int           `json:"currencyCodeB"`
	Date          epoch.Seconds `json:"date"`
	RateSell      float64       `json:"rateSell"`
	RateBuy       float64       `json:"rateBuy"`
	RateCross     float64       `json:"rateCross"`
}

type PersonalAPI added in v0.2.0

type PersonalAPI interface {
	PublicAPI

	// ClientInfo - https://api.monobank.ua/docs/#/definitions/UserInfo
	ClientInfo(context.Context) (*ClientInfo, error)

	// Transactions - gets bank account statements(transations)
	// https://api.monobank.ua/docs/#/definitions/StatementItems
	Transactions(ctx context.Context, accountID string, from, to time.Time) (Transactions, error)

	// SetWebHook - sets webhook for statements
	SetWebHook(ctx context.Context, uri string) error
}

type PersonalAuthorizer

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

func NewPersonalAuthorizer

func NewPersonalAuthorizer(token string) PersonalAuthorizer

func (PersonalAuthorizer) SetAuth

func (a PersonalAuthorizer) SetAuth(req *http.Request) error

type PublicAPI added in v0.2.0

type PublicAPI interface {
	// Currency https://api.monobank.ua/docs/#/definitions/CurrencyInfo
	Currency(context.Context) (Currencies, error)
}

type PublicAuthorizer

type PublicAuthorizer struct{}

func NewPublicAuthorizer

func NewPublicAuthorizer() PublicAuthorizer

func (PublicAuthorizer) SetAuth

func (a PublicAuthorizer) SetAuth(_ *http.Request) error

type TokenRequest added in v0.7.0

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

type Transaction added in v0.2.0

type Transaction struct {
	ID              string        `json:"id"`
	Time            epoch.Seconds `json:"time"`
	Description     string        `json:"description"`
	MCC             int32         `json:"mcc"`
	Hold            bool          `json:"hold"`
	Amount          int64         `json:"amount"`
	OperationAmount int64         `json:"operationAmount"`
	CurrencyCode    int           `json:"currencyCode"`
	CommissionRate  int64         `json:"commissionRate"`
	CashbackAmount  int64         `json:"cashbackAmount"`
	Balance         int64         `json:"balance"`
	Comment         string        `json:"comment"`
}

Transaction - bank account statement

type Transactions added in v0.2.0

type Transactions []Transaction

Transactions - transactions

type WebHookData

type WebHookData struct {
	AccountID   string      `json:"account"`
	Transaction Transaction `json:"statementItem"`
}

type WebHookRequest

type WebHookRequest struct {
	WebHookURL string `json:"webHookUrl"`
}

type WebHookResponse

type WebHookResponse struct {
	Type string      `json:"type"` // "StatementItem"
	Data WebHookData `json:"data"`
}

Jump to

Keyboard shortcuts

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