1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"fmt" |
7
|
|
|
"time" |
8
|
|
|
) |
9
|
|
|
|
10
|
|
|
// TerminalsService operates over terminals resource. |
11
|
|
|
type TerminalsService service |
12
|
|
|
|
13
|
|
|
// TerminalStatus is the status of the terminal, which is a read-only value determined by Mollie. |
14
|
|
|
type TerminalStatus string |
15
|
|
|
|
16
|
|
|
// Possible terminal statuses. |
17
|
|
|
const ( |
18
|
|
|
TerminalPending TerminalStatus = "pending" |
19
|
|
|
TerminalActive TerminalStatus = "active" |
20
|
|
|
TerminalInactive TerminalStatus = "inactive" |
21
|
|
|
) |
22
|
|
|
|
23
|
|
|
// Terminal symbolizes a physical device to receive payments. |
24
|
|
|
type Terminal struct { |
25
|
|
|
ID string `json:"id,omitempty"` |
26
|
|
|
Resource string `json:"resource,omitempty"` |
27
|
|
|
ProfileID string `json:"profileID,omitempty"` |
28
|
|
|
Status TerminalStatus `json:"status,omitempty"` |
29
|
|
|
Brand string `json:"brand,omitempty"` |
30
|
|
|
Model string `json:"model,omitempty"` |
31
|
|
|
SerialNumber string `json:"serialNumber,omitempty"` |
32
|
|
|
Currency string `json:"currency,omitempty"` |
33
|
|
|
Description string `json:"description,omitempty"` |
34
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
35
|
|
|
UpdatedAt *time.Time `json:"updatedAt,omitempty"` |
36
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
// Get terminal retrieves a single terminal object by its terminal ID. |
40
|
|
|
func (ts *TerminalsService) Get(ctx context.Context, id string) (res *Response, t *Terminal, err error) { |
41
|
1 |
|
res, err = ts.client.get(ctx, fmt.Sprintf("v2/terminals/%s", id), nil) |
42
|
1 |
|
if err != nil { |
43
|
1 |
|
return |
44
|
|
|
} |
45
|
|
|
|
46
|
1 |
|
if err = json.Unmarshal(res.content, &t); err != nil { |
47
|
1 |
|
return |
48
|
|
|
} |
49
|
|
|
|
50
|
1 |
|
return |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// TerminalListOptions holds query string parameters valid for terminals lists. |
54
|
|
|
// |
55
|
|
|
// ProfileID and TestMode are valid only when using access tokens. |
56
|
|
|
type TerminalListOptions struct { |
57
|
|
|
From string `url:"from,omitempty"` |
58
|
|
|
Limit int `url:"limit,omitempty"` |
59
|
|
|
ProfileID string `url:"profileID,omitempty"` |
60
|
|
|
TestMode bool `url:"testMode,omitempty"` |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
// TerminalList describes the response for terminals list endpoints. |
64
|
|
|
type TerminalList struct { |
65
|
|
|
Count int `json:"count,omitempty"` |
66
|
|
|
Embedded struct { |
67
|
|
|
Terminals []*Terminal `json:"terminals,omitempty"` |
68
|
|
|
} `json:"_embedded,omitempty"` |
69
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
// List retrieves a list of terminals symbolizing the physical devices to receive payments. |
73
|
|
|
func (ts *TerminalsService) List(ctx context.Context, options *TerminalListOptions) ( |
74
|
|
|
res *Response, |
75
|
|
|
tl *TerminalList, |
76
|
|
|
err error, |
77
|
|
|
) { |
78
|
1 |
|
if ts.client.HasAccessToken() && ts.client.config.testing { |
79
|
|
|
options.TestMode = true |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
res, err = ts.client.get(ctx, "v2/terminals", options) |
83
|
1 |
|
if err != nil { |
84
|
1 |
|
return |
85
|
|
|
} |
86
|
|
|
|
87
|
1 |
|
if err = json.Unmarshal(res.content, &tl); err != nil { |
88
|
1 |
|
return |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
return |
92
|
|
|
} |
93
|
|
|
|