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:
- create a user (figo-API-reference)
- credential login (figo-API-reference)
- setup new bank account (figo-API-reference)
- delete a user (figo-API-reference)
- retrieve transactions and account-informations (figo-API-reference)
- retrieve all bankAccounts (figo-API-reference)
- retrieve specific transaction
- request for task
- retrieve standing orders
Install fiGo:
go get github.com/TobiEiss/fiGo
Dependencies:
- gabs for parsing, creating and editing unknown or dynamic JSON in golang
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
Ask your user for an username, email-address and password. Then add to figo:
recPwByteArray, err := connection.CreateUser("testUsername", "[email protected]", "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"
}
Login your users:
userAsJson, err := connection.CredentialLogin("[email protected]", "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!
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"}
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!
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.
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.
// First, let's create some struct-objects for a figoUser and bankCredentials.
figoUser := fastconnect.FigoUser{
Email: "[email protected]",
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!