Skip to content

vtopc/go-monobank

Repository files navigation

go-monobank

Godoc Reference CI codecov

Monobank REST API client.

Features

  • Personal API(with Token authorization).
  • API for providers(corporate) with authorization.
  • Webhooks(including API for providers).
  • Jars(only in Personal API).

Installation

go get github.com/vtopc/go-monobank@latest

This will update yours go.mod file.

Usage examples

NOTE: Do not forget to check errors.

Public client

package main

import (
    "context"
    "fmt"

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

func main() {
    // Create public client.
    client := monobank.NewClient(nil)

    response, _ := client.Currency(context.Background())
    fmt.Println(response)
}

Personal client

package main

import (
    "context"
    "fmt"
    "os"

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

func main() {
    token := os.Getenv("TOKEN")

    // Create authorized client.
    client := monobank.NewPersonalClient(nil).WithAuth(monobank.NewPersonalAuthorizer(token))

    response, _ := client.ClientInfo(context.Background())
    fmt.Println(response)
}

Corporate client

package main

import (
    "context"
    "fmt"

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

var secKey []byte // put here you private key

const webhook = "https://example.com/webhook"

func main() {
    // Create auth creator.
    authMaker, _ := monobank.NewCorpAuthMaker(secKey)

    // Create authorized client.
    client, _ := monobank.NewCorporateClient(nil, authMaker)

    // If the user is not authorized yet, do next:
    resp, _ := client.Auth(context.Background(), webhook, monobank.PermSt, monobank.PermPI)

    // Send `resp.AcceptURL` to the user and wait until it will authorize your client
    // in Monobank app on mobile, you will get GET request on `webhook` when it will be done.
    // See Documentation for details.
    // Store `resp.RequestID` somewhere.
    requestID := resp.RequestID

    // If user authorized already:
    response, _ := client.ClientInfo(context.Background(), requestID)
    fmt.Println(response)
}

Documentation

Similar projects

TODO

  • More unit tests