Git Product home page Git Product logo

goqonto's Introduction

GoQonto - Qonto API (v2) Go client

GoDoc tests codecov Go Report Card

Installation

The import path for the package is github.com/pixelfactoryio/goqonto/v2

To install it, run:

go get github.com/pixelfactoryio/goqonto/v2

API documentation

Package Documentation is located at : https://pkg.go.dev/github.com/pixelfactoryio/goqonto/v2

Qonto API v2 documentation is located at : https://api-doc.qonto.eu/2.0/welcome

Usage

package main

import (
    "context"
    "encoding/json"
    "fmt"
    "net/http"
    "os"

    "github.com/pixelfactoryio/goqonto/v2"
)

type AuthTransport struct {
    *http.Transport
    Slug   string
    Secret string
}

func (t AuthTransport) RoundTrip(r *http.Request) (*http.Response, error) {
    r.Header.Set("Authorization", fmt.Sprintf("%s:%s", t.Slug, t.Secret))
    return t.Transport.RoundTrip(r)
}

func main() {

    orgID := os.Getenv("QONTO_ORG_ID")
    userLogin := os.Getenv("QONTO_USER_LOGIN")
    userSecretKey := os.Getenv("QONTO_SECRET_KEY")

    client := http.Client{
        Transport: AuthTransport{
            &http.Transport{},
            userLogin,
            userSecretKey,
        },
    }

    qonto := goqonto.NewClient(&client)
    ctx := context.Background()

    // Get Organization
    orga, resp, err := qonto.Organizations.Get(ctx, orgID)
    if err != nil && resp.StatusCode != http.StatusOK {
        panic(err.Error())
    }
    prettyPrint(orga)

    // List Transactions
    params := &goqonto.TransactionsOptions{
        Slug:   orga.Slug,
        IBAN:   orga.BankAccounts[0].IBAN,
        Status: []string{"completed"},
    }

    transactions, resp, err := qonto.Transactions.List(ctx, params)
    if err != nil && resp.StatusCode != http.StatusOK {
        panic(err.Error())
    }

    for _, trx := range transactions {
        prettyPrint(trx)
    }
    prettyPrint(resp.Meta)

    // Get an attachment
    attachement, resp, err := qonto.Attachments.Get(ctx, "1812345c-cf62-49a0-bbb0-f654321678")
    if err != nil && resp.StatusCode != http.StatusOK {
        panic(err.Error())
    }
    prettyPrint(attachement)

    // List memberships
    memberships, resp, err := qonto.Memberships.List(ctx, nil)
    if err != nil && resp.StatusCode != http.StatusOK {
        panic(err.Error())
    }

    for _, member := range memberships {
        prettyPrint(member)
    }
    prettyPrint(resp.Meta)

}

func prettyPrint(v interface{}) {
    b, _ := json.MarshalIndent(v, "", "  ")
    fmt.Println(string(b))
}

Credits

This client is heavily inspired by :

goqonto's People

Contributors

amine7536 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.