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 |
|
getURL := fmt.Sprintf("v2/organizations/%s", id) |
43
|
|
|
|
44
|
1 |
|
req, err := os.client.NewAPIRequest(http.MethodGet, getURL, nil) |
45
|
1 |
|
if err != nil { |
46
|
1 |
|
return |
47
|
|
|
} |
48
|
1 |
|
res, err := os.client.Do(req) |
49
|
1 |
|
if err != nil { |
50
|
1 |
|
return |
51
|
|
|
} |
52
|
1 |
|
if err = json.Unmarshal(res.content, &o); err != nil { |
53
|
1 |
|
return |
54
|
|
|
} |
55
|
1 |
|
return |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// GetCurrent retrieve the currently authenticated organization |
59
|
|
|
func (os *OrganizationsService) GetCurrent() (o *Organization, err error) { |
60
|
1 |
|
getURL := "v2/organizations/me" |
61
|
|
|
|
62
|
1 |
|
req, err := os.client.NewAPIRequest(http.MethodGet, getURL, nil) |
63
|
1 |
|
if err != nil { |
64
|
1 |
|
return |
65
|
|
|
} |
66
|
1 |
|
res, err := os.client.Do(req) |
67
|
1 |
|
if err != nil { |
68
|
1 |
|
return |
69
|
|
|
} |
70
|
1 |
|
if err = json.Unmarshal(res.content, &o); err != nil { |
71
|
1 |
|
return |
72
|
|
|
} |
73
|
1 |
|
return |
74
|
|
|
} |
75
|
|
|
|