fiGo

package module
v0.0.0-...-11a8196 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2018 License: MIT Imports: 9 Imported by: 1

README

fiGo - a go driver for the figo-API (figo.io)

Build Status

This project is a golang-driver for figo.
If you want to use this, you need a clientID and a clientSecret. You will get this from figo.

You miss something here? - Please let me know!

Currently implemented:

Getting started

Install fiGo: go get github.com/TobiEiss/fiGo

Dependencies:

  • gabs for parsing, creating and editing unknown or dynamic JSON in golang

Usage

The following is about how to connect to fiGo with the plain-lightweight-slick-fiGo library. If all this is too complicated, use fastconnect!

First create a new connection:

// create a new fiGo-Connection
var connection fiGo.IConnection
figoConnection := fiGo.NewFigoConnection("clientID", "clientSecret")
connection = figoConnection
Create a user

Ask your user for an username, email-address and password. Then add to figo:

recPwByteArray, err := connection.CreateUser("testUsername", "test@test.de", "mysecretpassword")
if err == fiGo.ErrHTTPUnauthorized {
    // TODO: handle if this was unauthorized
} else if err == fiGo.ErrUserAlreadyExists {
    // TODO: handle if user already exists
}

You will get back a recovery-password in JSON-format as byte array:

{"recovery_password": "abcd-efgh-ijkl-mnop"}

Fast way to get this (use gabs):

jsonParsed, err := gabs.ParseJSON(recPwByteArray)
recoveryPassword, ok := jsonParsed.Path("recovery_password").Data().(string)
if ok {
    // do whatever you want with the "recoveryPassword"
}
Credentials login

Login your users:

userAsJson, err := connection.CredentialLogin("test@test.de", "mysecretpassword")
// TODO error handling

You will get all relevant user data like this:

{
   "access_token":"abcdefghijklmnopqrstuvwxyz",
   "token_type":"Bearer",
   "expires_in":600.0,
   "refresh_token":"abcdefghijklmnopqrstuvwxyz",
   "scope":"accounts=rw transactions=rw balance=rw user=rw offline create_user "
}

Tip: Use gabs to get specific fields.
Notice: Keep the access_token for other user-activities.

Crappy? - use fastconnect!

Setup new bank account

Add a bankAccount to an existing figo-account

jsonAnswer, err := connection.SetupNewBankAccount(value, "90090042", "de", []string{"demo", "demo"})

The jsonAnswer contains a task_token. You need this to sync the figo-account with a real bank-account.

{"task_token": "abcdefghijklmnopqrstuvwxyz"}
Delete a user

You want to delete a user? - No problem. Just call code below:

jsonAnswer, err := connection.DeleteUser(accessToken)

Hint: Are you confused? Take a look to fastconnect!

Retrieve transactions and account-informations

To retrieve transactions use the access-Token from credential login:

answerByte, err := connection.RetrieveTransactionsOfAllAccounts(accessToken)

For Account-Information:

answerByte, err := connection.RetrieveAllBankAccounts(accessToken)

You will get back the transactions and account-informations as JSON. Use gabs and Json.Unmarshal to put this directly in a model.

fastconnect

FiGo-fastconnect is a way to interact in a faster way with figo. All the user-/ account-/ .. models are ready. Also all the API-calls.

Getting started with fastconnect
// First, let's create some struct-objects for a figoUser and bankCredentials.
figoUser := fastconnect.FigoUser{
    Email:    "email@example.com",
    Username: "username",
    Password: "mySecretPassword",
}
bankCredentials := fastconnect.BankCredentials{
    BankCode:    "90090042",
    Country:     "de",
    Credentials: []string{"demo", "demo"},
}

// Create a new connection to figo
figoConnection := fiGo.NewFigoConnection("clientID", "clientSecret")

// Now create the user on figo-side
recoveryPassword, err := fastconnect.CreateUser(figoConnection, figoUser)
if recoveryPassword == "" || err != nil {
    // TODO: handle error!
}

// Login the new created user to get an accessToken
accessToken, err = fastconnect.LoginUser(figoConnection, figoUser)
if accessToken == "" || err != nil {
    // Can't create figoUser. TODO: handle this!
}

// Add BankCredentials to the figo-account on figo-side
taskToken, err := fastconnect.SetupNewBankAccount(figoConnection, accessToken, bankCredentials)
if err != nil || taskToken == "" {
    // Error while setup new bankAccount. TODO handle error!
}

// We need to check the snychronize-Task
task, err := fastconnect.RequestTask(figoConnection, accessToken, taskToken)
if err != nil {
    // Should i say something? - Yeah..TODO: handle error!
}

// NOTICE! Check now the task, if everything is ready synchronized. If not, ask again.

// Now, you can retrieve all transations
transactionInterfaces, err := fastconnect.RetrieveAllTransactions(figoConnection, accessToken)
if err != nil || transactionInterfaces == nil {
    // TODO: handle your error here!
}

// convert now to a model. TODO: implement a "Transaction" model with "json"-tags.
transactions := make([]Transaction, 0)
for _, transactionInterface := range transactionInterfaces {
    transactionByte, err := json.Marshal(transactionInterface)
    if err == nil {
        transaction := Transaction{}
        json.Unmarshal(transactionByte, &transaction)
        transactions = append(transactions, transaction)
    }
}

Checkout the fastconnect package for more stuff!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserAlreadyExists - code 30002
	ErrUserAlreadyExists = errors.New("user already exists")

	// ErrHTTPUnauthorized - code 90000
	ErrHTTPUnauthorized = errors.New("invalid authorization")
)
View Source
var (
	// ErrCantFindUser means "Cant find user in fake-figo"
	ErrCantFindUser = errors.New("cant find user")
)

Functions

This section is empty.

Types

type Connection

type Connection struct {
	AuthString string
	Host       string
}

Connection represent a connection to figo

func NewFigoConnection

func NewFigoConnection(clientID string, clientSecret string) *Connection

NewFigoConnection creates a new connection. -> You need a clientID and a clientSecret. (You will get this from figo.io)

func (*Connection) CreateSynchronizationTask

func (connection *Connection) CreateSynchronizationTask(accessToken string, syncTask SyncTask) ([]byte, error)

CreateSynchronizationTask creates a new task to synchronize

func (*Connection) CreateUser

func (connection *Connection) CreateUser(name string, email string, password string) ([]byte, error)

CreateUser creates a new user. Ask User for name, email and a password

func (*Connection) CredentialLogin

func (connection *Connection) CredentialLogin(username string, password string) ([]byte, error)

CredentialLogin create a login. -> First you have to create a user (CreateUser)

func (*Connection) DeleteUser

func (connection *Connection) DeleteUser(accessToken string) ([]byte, error)

DeleteUser deletes an existing user

func (*Connection) ReadIndividualCatalogEntry

func (connection *Connection) ReadIndividualCatalogEntry(accessToken string, catalogCategory string, countryCode string, serviceID string) ([]byte, error)

ReadIndividualCatalogEntry gets all infos for a specific catalog entry. catalogCategory is "banks" or "services" countryCode is "de" or "at" serviceID is something like BLZ

func (*Connection) ReadStandingOrder

func (connection *Connection) ReadStandingOrder(accessToken string, options ...TransactionOption) ([]byte, error)

ReadStandingOrder all standing orders

func (*Connection) RemoveBankAccount

func (connection *Connection) RemoveBankAccount(accessToken string, bankAccountID string) ([]byte, error)

RemoveBankAccount removes a bank account

func (*Connection) RequestForTask

func (connection *Connection) RequestForTask(accessToken, taskToken string) ([]byte, error)

RequestForTask starts a new task or polls it to synchronize real bankAccount and figoAccount

func (*Connection) RequestForTaskWithPinChallenge

func (connection *Connection) RequestForTaskWithPinChallenge(accessToken, taskToken, pin string, savePin bool) ([]byte, error)

RequestForTaskWithPinChallenge can be use to respond to a pin challenge that might occur when syncing

func (*Connection) RetrieveAllBankAccounts

func (connection *Connection) RetrieveAllBankAccounts(accessToken string, cents bool) ([]byte, error)

RetrieveAllBankAccounts retrieves all bankAccounts for an user

func (*Connection) RetrieveSpecificBankAccounts

func (connection *Connection) RetrieveSpecificBankAccounts(accessToken, accountID string, cents bool) ([]byte, error)

RetrieveAllBankAccounts retrieves specific bankAccounts for an user

func (*Connection) RetrieveSpecificTransaction

func (connection *Connection) RetrieveSpecificTransaction(accessToken string, transactionID string) ([]byte, error)

RetrieveSpecificTransaction with accessToken from login-session

func (*Connection) RetrieveTransactionsOfAllAccounts

func (connection *Connection) RetrieveTransactionsOfAllAccounts(accessToken string, options ...TransactionOption) ([]byte, error)

RetrieveTransactionsOfAllAccounts with accessToken from login-session

func (*Connection) RetrieveTransactionsSingleAccount

func (connection *Connection) RetrieveTransactionsSingleAccount(accessToken, accountid string, options ...TransactionOption) ([]byte, error)

func (*Connection) SetHost

func (connection *Connection) SetHost(host string)

SetHost sets a new host

func (*Connection) SetupNewBankAccount

func (connection *Connection) SetupNewBankAccount(accessToken string, bankCode string, country string, credentials []string, savePin bool) ([]byte, error)

SetupNewBankAccount add a new bankAccount to an existing figo-Account

type FakeConnection

type FakeConnection struct {
	Users []map[string]interface{}
}

FakeConnection is a fakes the figoAPI

func NewFakeConnection

func NewFakeConnection() *FakeConnection

NewFakeConnection creates a new "fak-Connection" only in memory

func (*FakeConnection) CreateUser

func (fakeConnection *FakeConnection) CreateUser(name string, email string, password string) ([]byte, error)

CreateUser "store" a user in this fake-Connection

func (*FakeConnection) CredentialLogin

func (fakeConnection *FakeConnection) CredentialLogin(username string, password string) ([]byte, error)

CredentialLogin returns a token -> Notice: first add a user via CreateUser!

func (*FakeConnection) DeleteUser

func (fakeConnection *FakeConnection) DeleteUser(accessToken string) ([]byte, error)

DeleteUser deletes a user from fakeConnection Notice: you need an accessToken from CredentialLogin

func (*FakeConnection) ReadIndividualCatalogEntry

func (fakeConnection *FakeConnection) ReadIndividualCatalogEntry(accessToken string, catalogCategory string, countryCode string, serviceID string) ([]byte, error)

ReadIndividualCatalogEntry TODO

func (*FakeConnection) ReadStandingOrder

func (fakeConnection *FakeConnection) ReadStandingOrder(accessToken string, options ...TransactionOption) ([]byte, error)

ReadStandingOrder TODO

func (*FakeConnection) RemoveBankAccount

func (fakeConnection *FakeConnection) RemoveBankAccount(accessToken string, bankAccountID string) ([]byte, error)

RemoveBankAccount removes a bank account TODO

func (*FakeConnection) RequestForTask

func (fakeConnection *FakeConnection) RequestForTask(accessToken string, taskToken string) ([]byte, error)

RequestForTask should generate new transactions TODO

func (*FakeConnection) RequestForTaskWithPinChallenge

func (fakeConnection *FakeConnection) RequestForTaskWithPinChallenge(accessToken string, taskToken string, pin string, savePin bool) ([]byte, error)

RequestForTaskWithPinChallenge should generate new transactions TODO

func (*FakeConnection) RetrieveAllBankAccounts

func (fakeConnection *FakeConnection) RetrieveAllBankAccounts(accessToken string) ([]byte, error)

RetrieveAllBankAccounts TODO

func (*FakeConnection) RetrieveSpecificTransaction

func (fakeConnection *FakeConnection) RetrieveSpecificTransaction(accessToken string, transactionID string) ([]byte, error)

RetrieveSpecificTransaction TODO

func (*FakeConnection) RetrieveTransactionsOfAllAccounts

func (fakeConnection *FakeConnection) RetrieveTransactionsOfAllAccounts(accessToken string, options ...TransactionOption) ([]byte, error)

RetrieveTransactionsOfAllAccounts TODO

func (*FakeConnection) SetHost

func (fakeConnection *FakeConnection) SetHost(host string)

SetHost is not needed

func (*FakeConnection) SetupNewBankAccount

func (fakeConnection *FakeConnection) SetupNewBankAccount(accessToken string, bankCode string, country string, credentials []string) ([]byte, error)

SetupNewBankAccount sets up a new bank account for an existing account. -> Notice: you need an accessToken from CredentialLogin

type IConnection

type IConnection interface {
	// Set another host
	SetHost(host string)

	// http://docs.figo.io/#create-new-figo-user
	// Ask user for new name, email and password
	CreateUser(name string, email string, password string) ([]byte, error)

	// http://docs.figo.io/#credential-login
	// Login with email (aka username) and password
	CredentialLogin(username string, password string) ([]byte, error)

	// http://docs.figo.io/#delete-current-user
	// Remove user with an accessToken. You get the token after successfully login
	DeleteUser(accessToken string) ([]byte, error)

	// http://docs.figo.io/#setup-new-bank-account
	// Add a BankAccount to figo-Account
	// -> you get accessToken from the login-response
	// -> country is something like "de" (for germany)
	SetupNewBankAccount(accessToken string, bankCode string, country string, credentials []string, savePin bool) ([]byte, error)

	// http://docs.figo.io/#retrieve-all-bank-accounts
	// Retrieves all bankAccounts for an user
	RetrieveAllBankAccounts(accessToken string, cents bool) ([]byte, error)

	// http://docs.figo.io/#delete-bank-account
	// Removes a bankAccount from figo-account
	RemoveBankAccount(accessToken string, bankAccountID string) ([]byte, error)

	// http://docs.figo.io/#poll-task-state
	// request a task
	// -> you need a taskToken. You will get this from SetupNewBankAccount or when triggering a manuel sync
	RequestForTask(accessToken string, taskToken string) ([]byte, error)

	// http://docs.figo.io/#poll-task-state
	// request a task
	// -> you need a taskToken. You will get this from SetupNewBankAccount or when triggering a manual sync
	RequestForTaskWithPinChallenge(accessToken string, taskToken string, pin string, savePin bool) ([]byte, error)

	// http://docs.figo.io/#retrieve-transactions-of-one-or-all-account
	// Retrieves all Transactions
	RetrieveTransactionsOfAllAccounts(accessToken string, options ...TransactionOption) ([]byte, error)

	// Retrieves all Transactions of a single account
	RetrieveTransactionsSingleAccount(accessToken, accountid string, options ...TransactionOption) ([]byte, error)

	// http://docs.figo.io/#retrieve-a-transaction
	// Retrieves a specific Transaction
	RetrieveSpecificTransaction(accessToken string, transactionID string) ([]byte, error)

	// http://docs.figo.io/#tag/Catalog
	// Read individual Catalog Entry
	ReadIndividualCatalogEntry(accessToken string, catalogCategory string, countryCode string, serviceID string) ([]byte, error)

	// http://docs.figo.io/#standing-orders-api-calls-read-standing-orders
	// Read standing orders
	ReadStandingOrder(accessToken string, options ...TransactionOption) ([]byte, error)
}

IConnection represent an interface for connections. This provides to use fakeConnection and a real-figoConnection

type SyncTask

type SyncTask struct {
	State                string   `json:"state"`
	RedirectURI          string   `json:"redirect_uri,omitempty"`
	DisableNotifications bool     `json:"disable_notifications,omitempty"`
	IfNotSyncedSince     int      `json:"if_not_synced_since,omitempty"`
	AutoContinue         bool     `json:"auto_continue,omitempty"`
	AccountIds           []string `json:"account_ids,omitempty"`
	SyncTasks            []string `json:"sync_tasks,omitempty"`
}

SyncTask represents a synchronization task

type TransactionOption

type TransactionOption struct {
	Key   TransactionOptionKey
	Value string
}

TransactionOption are options for transaction-calls

type TransactionOptionKey

type TransactionOptionKey string

TransactionOptionKey are the type for allowed keys

var (
	// Cent if true, the amount of the transactions will be shown in cents.
	Cent TransactionOptionKey = "cents"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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