1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"encoding/json" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
"time" |
8
|
|
|
) |
9
|
|
|
|
10
|
|
|
// Organization describes an organization detail |
11
|
|
|
type Organization struct { |
12
|
|
|
Resource string `json:"resource,omitempty"` |
13
|
|
|
ID string `json:"id,omitempty"` |
14
|
|
|
Name string `json:"name,omitempty"` |
15
|
|
|
Email string `json:"email,omitempty"` |
16
|
|
|
Locale string `json:"locale,omitempty"` |
17
|
|
|
Address *Address `json:"address,omitempty"` |
18
|
|
|
RegistrationNumber string `json:"registrationNumber,omitempty"` |
19
|
|
|
VatNumber string `json:"vatNumber,omitempty"` |
20
|
|
|
VatRegulation string `json:"vatRegulation,omitempty"` |
21
|
|
|
Links OrganizationLinks `json:"_links,omitempty"` |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
// OrganizationLinks describes all the possible links to be returned with |
25
|
|
|
// a organization object. |
26
|
|
|
type OrganizationLinks struct { |
27
|
|
|
Self *URL `json:"self,omitempty"` |
28
|
|
|
Chargebacks *URL `json:"chargebacks,omitempty"` |
29
|
|
|
Customers *URL `json:"customers,omitempty"` |
30
|
|
|
Dashboard *URL `json:"dashboard,omitempty"` |
31
|
|
|
Invoices *URL `json:"invoices,omitempty"` |
32
|
|
|
Payments *URL `json:"payments,omitempty"` |
33
|
|
|
Profiles *URL `json:"profiles,omitempty"` |
34
|
|
|
Refunds *URL `json:"refunds,omitempty"` |
35
|
|
|
Settlements *URL `json:"settlements,omitempty"` |
36
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// PartnerType alias for organization partner types. |
40
|
|
|
type PartnerType string |
41
|
|
|
|
42
|
|
|
// Available partner types. |
43
|
|
|
const ( |
44
|
|
|
PartnerTypeOauth PartnerType = "oauth" |
45
|
|
|
PartnerTypeSignUpLink PartnerType = "signuplink" |
46
|
|
|
PartnerTypeUserAgent PartnerType = "useragent" |
47
|
|
|
) |
48
|
|
|
|
49
|
|
|
// UserAgentToken are time limited valid access tokens. |
50
|
|
|
type UserAgentToken struct { |
51
|
|
|
Token string |
52
|
|
|
StartsAt *time.Time |
53
|
|
|
EndsAt *time.Time |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// OrganizationPartnerLinks is an object with several URL objects |
57
|
|
|
// relevant to the partner resource. |
58
|
|
|
type OrganizationPartnerLinks struct { |
59
|
|
|
Self *URL `json:"self,omitempty"` |
60
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
61
|
|
|
SignUpLink *URL `json:"signuplink,omitempty"` |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// OrganizationPartnerStatus response descriptor. |
65
|
|
|
type OrganizationPartnerStatus struct { |
66
|
|
|
IsCommissionPartner bool `json:"isCommissionPartner,omitempty"` |
67
|
|
|
PartnerContractUpdateAvailable bool `json:"partnerContractUpdate_available,omitempty"` |
68
|
|
|
Resource string `json:"resource,omitempty"` |
69
|
|
|
PartnerType PartnerType `json:"partnerType,omitempty"` |
70
|
|
|
UserAgentTokens []*UserAgentToken `json:"userAgentTokens,omitempty"` |
71
|
|
|
PartnerContractSignedAt *time.Time `json:"partnerContractSignedAt,omitempty"` |
72
|
|
|
Links OrganizationPartnerLinks `json:"_links,omitempty"` |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// OrganizationsService instance operates over organization resources |
76
|
|
|
type OrganizationsService service |
77
|
|
|
|
78
|
|
|
// Get retrieve an organization by its id. |
79
|
|
|
func (os *OrganizationsService) Get(id string) (o *Organization, err error) { |
80
|
1 |
|
return os.get(fmt.Sprintf("v2/organizations/%s", id)) |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
// GetCurrent retrieve the currently authenticated organization |
84
|
|
|
func (os *OrganizationsService) GetCurrent() (o *Organization, err error) { |
85
|
1 |
|
return os.get("v2/organizations/me") |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
// GetPartnerStatus retrieves details about the partner status |
89
|
|
|
// of the currently authenticated organization. |
90
|
|
|
// |
91
|
|
|
// See: https://docs.mollie.com/reference/v2/organizations-api/get-partner |
92
|
|
|
func (os *OrganizationsService) GetPartnerStatus() (ops *OrganizationPartnerStatus, err error) { |
93
|
1 |
|
req, err := os.client.NewAPIRequest(http.MethodGet, "v2/organizations/me/partner", nil) |
94
|
1 |
|
if err != nil { |
95
|
1 |
|
return |
96
|
|
|
} |
97
|
|
|
|
98
|
1 |
|
res, err := os.client.Do(req) |
99
|
1 |
|
if err != nil { |
100
|
1 |
|
return |
101
|
|
|
} |
102
|
|
|
|
103
|
1 |
|
if err = json.Unmarshal(res.content, &ops); err != nil { |
104
|
1 |
|
return |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
return |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
func (os *OrganizationsService) get(uri string) (o *Organization, err error) { |
111
|
1 |
|
req, err := os.client.NewAPIRequest(http.MethodGet, uri, nil) |
112
|
1 |
|
if err != nil { |
113
|
1 |
|
return |
114
|
|
|
} |
115
|
1 |
|
res, err := os.client.Do(req) |
116
|
1 |
|
if err != nil { |
117
|
1 |
|
return |
118
|
|
|
} |
119
|
1 |
|
if err = json.Unmarshal(res.content, &o); err != nil { |
120
|
1 |
|
return |
121
|
|
|
} |
122
|
1 |
|
return |
123
|
|
|
} |
124
|
|
|
|