1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"encoding/json" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
"time" |
8
|
|
|
|
9
|
|
|
"github.com/google/go-querystring/query" |
10
|
|
|
) |
11
|
|
|
|
12
|
|
|
// PartnerClient describes a partner client. |
13
|
|
|
type PartnerClient struct { |
14
|
|
|
Resource string `json:"resource,omitempty"` |
15
|
|
|
ID string `json:"id,omitempty"` |
16
|
|
|
OrganizationCreatedAt *time.Time `json:"organizationCreatedAt,omitempty"` |
17
|
|
|
Commission Commission `json:"commission,omitempty"` |
18
|
|
|
Links PartnerClientLinks `json:"_links,omitempty"` |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
// PartnerClientList describes a list of partner clients. |
22
|
|
|
type PartnerClientList struct { |
23
|
|
|
Count int `json:"count,omitempty"` |
24
|
|
|
PartnerClients struct { |
25
|
|
|
Clients []*PartnerClient `json:"clients,omitempty"` |
26
|
|
|
} `json:"_embedded,omitempty"` |
27
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
// PartnerClientLinks contains URL objects relevant to the client. |
31
|
|
|
type PartnerClientLinks struct { |
32
|
|
|
Self *URL `json:"self,omitempty"` |
33
|
|
|
Organization *URL `json:"organization,omitempty"` |
34
|
|
|
Onboarding *URL `json:"onboarding,omitempty"` |
35
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// Commission describes a partner take from any |
39
|
|
|
// operation on Mollie's API. |
40
|
|
|
type Commission struct { |
41
|
|
|
Count int `json:"count,omitempty"` |
42
|
|
|
TotalAmount *Amount `json:"totalAmount,omitempty"` |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// GetPartnerClientOptions contains valid query parameters for the get clients endpoint. |
46
|
|
|
type GetPartnerClientOptions struct { |
47
|
|
|
Embed string `url:"embed,omitempty"` |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
// ListPartnerClientsOptions contains valid query parameters for the list clients endpoint. |
51
|
|
|
type ListPartnerClientsOptions struct { |
52
|
|
|
From int `url:"from,omitempty"` |
53
|
|
|
Limit int `url:"limit,omitempty"` |
54
|
|
|
Year int `url:"year,omitempty"` |
55
|
|
|
Month int `url:"month,omitempty"` |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// PartnerService operates over the partners API. |
59
|
|
|
type PartnerService service |
60
|
|
|
|
61
|
|
|
// Get retrieves all clients. |
62
|
|
|
// |
63
|
|
|
// See: https://docs.mollie.com/reference/v2/partners-api/list-clients |
64
|
|
|
func (ps *PartnerService) List(opts *ListPartnerClientsOptions) (pc *PartnerClientList, err error) { |
65
|
1 |
|
u := "v2/clients" |
66
|
1 |
|
if opts != nil { |
67
|
1 |
|
v, _ := query.Values(opts) |
68
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil) |
72
|
1 |
|
if err != nil { |
73
|
1 |
|
return |
74
|
|
|
} |
75
|
|
|
|
76
|
1 |
|
res, err := ps.client.Do(req) |
77
|
1 |
|
if err != nil { |
78
|
1 |
|
return |
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
if err = json.Unmarshal(res.content, &pc); err != nil { |
82
|
1 |
|
return |
83
|
|
|
} |
84
|
1 |
|
return |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// Get retrieves a single client by its ID. |
88
|
|
|
// |
89
|
|
|
// See: https://docs.mollie.com/reference/v2/partners-api/get-client |
90
|
|
|
func (ps *PartnerService) Get(id string, opts *GetPartnerClientOptions) (pc *PartnerClient, err error) { |
91
|
1 |
|
u := fmt.Sprintf("v2/clients/%s", id) |
92
|
1 |
|
if opts != nil { |
93
|
1 |
|
v, _ := query.Values(opts) |
94
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
95
|
|
|
} |
96
|
|
|
|
97
|
1 |
|
req, err := ps.client.NewAPIRequest(http.MethodGet, u, nil) |
98
|
1 |
|
if err != nil { |
99
|
1 |
|
return |
100
|
|
|
} |
101
|
|
|
|
102
|
1 |
|
res, err := ps.client.Do(req) |
103
|
1 |
|
if err != nil { |
104
|
1 |
|
return |
105
|
|
|
} |
106
|
|
|
|
107
|
1 |
|
if err = json.Unmarshal(res.content, &pc); err != nil { |
108
|
1 |
|
return |
109
|
|
|
} |
110
|
1 |
|
return |
111
|
|
|
} |
112
|
|
|
|