-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorganizations.go
57 lines (46 loc) · 1.59 KB
/
organizations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package goqonto
import (
"context"
"fmt"
"net/http"
)
// organizationsBasePath Qonto API Organizations Endpoint
const organizationsBasePath = "v2/organizations"
// OrganizationsService provides access to the organizations in Qonto API
type OrganizationsService service
// Organization struct
// https://api-doc.qonto.eu/2.0/organizations/show-organization-1
type Organization struct {
Slug string `json:"slug"`
BankAccounts []BankAccount `json:"bank_accounts"`
}
// BankAccount struct
// https://api-doc.qonto.eu/2.0/organizations/show-organization-1
type BankAccount struct {
Slug string `json:"slug,omitempty"`
IBAN string `json:"iban"`
BIC string `json:"bic"`
Currency string `json:"currency"`
Balance float32 `json:"balance"`
BalanceCents int `json:"balance_cents"`
AuthorizedBalance float32 `json:"authorized_balance"`
AuthorizedBalanceCents int `json:"authorized_balance_cents"`
}
// organizationRoot root key in the JSON response for organizations
type organizationRoot struct {
Organization *Organization `json:"organization"`
}
// Get Organization
func (s *OrganizationsService) Get(ctx context.Context, id string) (*Organization, *Response, error) {
path := fmt.Sprintf("%s/%s", organizationsBasePath, id)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
root := new(organizationRoot)
resp, err := s.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Organization, resp, nil
}