1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"encoding/json" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
// Organization describes an organization detail |
10
|
|
|
type Organization struct { |
11
|
|
|
Resource string `json:"resource,omitempty"` |
12
|
|
|
ID string `json:"id,omitempty"` |
13
|
|
|
Name string `json:"name,omitempty"` |
14
|
|
|
Email string `json:"email,omitempty"` |
15
|
|
|
Locale string `json:"locale,omitempty"` |
16
|
|
|
Address *Address `json:"address,omitempty"` |
17
|
|
|
RegistrationNumber string `json:"registrationNumber,omitempty"` |
18
|
|
|
VatNumber string `json:"vatNumber,omitempty"` |
19
|
|
|
VatRegulation string `json:"vatRegulation,omitempty"` |
20
|
|
|
Links *OrganizationLinks `json:"_links,omitempty"` |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
// OrganizationLinks describes all the possible links to be returned with |
24
|
|
|
// a organization object. |
25
|
|
|
type OrganizationLinks struct { |
26
|
|
|
Self *URL `json:"self,omitempty"` |
27
|
|
|
Chargebacks *URL `json:"chargebacks,omitempty"` |
28
|
|
|
Customers *URL `json:"customers,omitempty"` |
29
|
|
|
Invoices *URL `json:"invoices,omitempty"` |
30
|
|
|
Payments *URL `json:"payments,omitempty"` |
31
|
|
|
Profiles *URL `json:"profiles,omitempty"` |
32
|
|
|
Refunds *URL `json:"refunds,omitempty"` |
33
|
|
|
Settlements *URL `json:"settlements,omitempty"` |
34
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// OrganizationsService instance operates over organization resources |
38
|
|
|
type OrganizationsService service |
39
|
|
|
|
40
|
|
|
// Get retrieve an organization by its id. |
41
|
|
|
func (os *OrganizationsService) Get(id string) (o *Organization, err error) { |
42
|
1 |
|
return os.get(fmt.Sprintf("v2/organizations/%s", id)) |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// GetCurrent retrieve the currently authenticated organization |
46
|
|
|
func (os *OrganizationsService) GetCurrent() (o *Organization, err error) { |
47
|
1 |
|
return os.get("v2/organizations/me") |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
func (os *OrganizationsService) get(uri string) (o *Organization, err error) { |
51
|
1 |
|
req, err := os.client.NewAPIRequest(http.MethodGet, uri, nil) |
52
|
1 |
|
if err != nil { |
53
|
1 |
|
return |
54
|
|
|
} |
55
|
1 |
|
res, err := os.client.Do(req) |
56
|
1 |
|
if err != nil { |
57
|
1 |
|
return |
58
|
|
|
} |
59
|
1 |
|
if err = json.Unmarshal(res.content, &o); err != nil { |
60
|
1 |
|
return |
61
|
|
|
} |
62
|
1 |
|
return |
63
|
|
|
} |
64
|
|
|
|