1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"encoding/json" |
5
|
|
|
"fmt" |
6
|
|
|
"net/http" |
7
|
|
|
"time" |
8
|
|
|
) |
9
|
|
|
|
10
|
|
|
// CapturesService operates over captures resource |
11
|
|
|
type CapturesService service |
12
|
|
|
|
13
|
|
|
// CaptureLinks contains relevant links for a capture object |
14
|
|
|
type CaptureLinks struct { |
15
|
|
|
Self URL `json:"self,omitempty"` |
16
|
|
|
Payment URL `json:"payment,omitempty"` |
17
|
|
|
Shipment URL `json:"shipment,omitempty"` |
18
|
|
|
Settlement URL `json:"settlement,omitempty"` |
19
|
|
|
Documentation URL `json:"documentation,omitempty"` |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
// Capture describes a single capture |
23
|
|
|
// Captures are used for payments that have the authorize-then-capture flow |
24
|
|
|
type Capture struct { |
25
|
|
|
Resource string `json:"resource,omitempty"` |
26
|
|
|
ID string `json:"id,omitempty"` |
27
|
|
|
Mode Mode `json:"mode,omitempty"` |
28
|
|
|
Amount Amount `json:"amount,omitempty"` |
29
|
|
|
SettlementAmount Amount `json:"settlementAmount,omitempty"` |
30
|
|
|
PaymentID string `json:"paymentId,omitempty"` |
31
|
|
|
ShipmentID string `json:"shipmentId,omitempty"` |
32
|
|
|
SettlementID string `json:"settlementId,omitempty"` |
33
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
34
|
|
|
Links CaptureLinks `json:"links,omitempty"` |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// CapturesList describes a list of captures |
38
|
|
|
type CapturesList struct { |
39
|
|
|
Count int `json:"count,omitempty"` |
40
|
|
|
Embedded struct { |
41
|
|
|
Captures []Capture |
42
|
|
|
} `json:"_embedded,omitempty"` |
43
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
// Get retrieves a single capture by its ID. |
47
|
|
|
// Note the original payment’s ID is needed as well. |
48
|
|
|
// |
49
|
|
|
// See: https://docs.mollie.com/reference/v2/captures-api/get-capture |
50
|
|
|
func (cs *CapturesService) Get(pID, cID string) (c *Capture, err error) { |
51
|
1 |
|
u := fmt.Sprintf("v2/payments/%s/captures/%s", pID, cID) |
52
|
1 |
|
req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil) |
53
|
1 |
|
if err != nil { |
54
|
1 |
|
return |
55
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
res, err := cs.client.Do(req) |
58
|
1 |
|
if err != nil { |
59
|
1 |
|
return |
60
|
|
|
} |
61
|
|
|
|
62
|
1 |
|
if err = json.Unmarshal(res.content, &c); err != nil { |
63
|
1 |
|
return |
64
|
|
|
} |
65
|
1 |
|
return |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
// List retrieves all captures for a certain payment |
69
|
|
|
// |
70
|
|
|
// See: https://docs.mollie.com/reference/v2/captures-api/list-captures |
71
|
|
|
func (cs *CapturesService) List(pID string) (cl *CapturesList, err error) { |
72
|
1 |
|
u := fmt.Sprintf("v2/payments/%s/captures", pID) |
73
|
1 |
|
req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil) |
74
|
1 |
|
if err != nil { |
75
|
1 |
|
return |
76
|
|
|
} |
77
|
|
|
|
78
|
1 |
|
res, err := cs.client.Do(req) |
79
|
1 |
|
if err != nil { |
80
|
1 |
|
return |
81
|
|
|
} |
82
|
|
|
|
83
|
1 |
|
if err = json.Unmarshal(res.content, &cl); err != nil { |
84
|
1 |
|
return |
85
|
|
|
} |
86
|
1 |
|
return |
87
|
|
|
} |
88
|
|
|
|