|
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
|
|
|
// Chargeback describes a forced transaction reversal initiated by the cardholder's bank |
|
13
|
|
|
type Chargeback struct { |
|
14
|
|
|
Resource string `json:"resource,omitempty"` |
|
15
|
|
|
ID string `json:"id,omitempty"` |
|
16
|
|
|
Amount *Amount `json:"amount,omitempty"` |
|
17
|
|
|
SettlementAmount *Amount `json:"settlementAmount,omitempty"` |
|
18
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
|
19
|
|
|
ReversedAt *time.Time `json:"reversedAt,omitempty"` |
|
20
|
|
|
ChargebackID string `json:"chargebackId,omitempty"` |
|
21
|
|
|
Links *ChargebackLinks `json:"_links,omitempty"` |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
// ChargebackLinks describes all the possible links to be returned with |
|
25
|
|
|
// a chargeback object. |
|
26
|
|
|
type ChargebackLinks struct { |
|
27
|
|
|
Self URL `json:"self,omitempty"` |
|
28
|
|
|
Chargeback URL `json:"chargeback,omitempty"` |
|
29
|
|
|
Settlement URL `json:"settlement,omitempty"` |
|
30
|
|
|
Documentation URL `json:"documentation,omitempty"` |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
// ChargebackOptions describes chargeback endpoint valid query string parameters. |
|
34
|
|
|
// |
|
35
|
|
|
// See: https://docs.mollie.com/reference/v2/chargebacks-api/get-chargeback |
|
36
|
|
|
type ChargebackOptions struct { |
|
37
|
|
|
Include string `url:"include,omitempty"` |
|
38
|
|
|
Embed string `url:"embed,omitempty"` |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
// ListChargebackOptions describes list chargebacks endpoint valid query string parameters. |
|
42
|
|
|
type ListChargebackOptions struct { |
|
43
|
|
|
Include string `url:"include,omitempty"` |
|
44
|
|
|
Embed string `url:"embed,omitempty"` |
|
45
|
|
|
ProfileID string `url:"profileId,omitempty"` |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
// ChargebackList describes how a list of chargebacks will be retrieved by Mollie. |
|
49
|
|
|
type ChargebackList struct { |
|
50
|
|
|
Count int `json:"count,omitempty"` |
|
51
|
|
|
Embedded struct { |
|
52
|
|
|
Chargebacks []Chargeback |
|
53
|
|
|
} `json:"_embedded,omitempty"` |
|
54
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
// ChargebacksService instance operates over chargeback resources |
|
58
|
|
|
type ChargebacksService service |
|
59
|
|
|
|
|
60
|
|
|
// Get retrieves a single chargeback by its ID. Note the original payment’s ID is needed as well. |
|
61
|
|
|
// |
|
62
|
|
|
//If you do not know the original payment’s ID, you can use the List function |
|
63
|
|
|
func (cs *ChargebacksService) Get(paymentID, chargebackID string, options *ChargebackOptions) (p Chargeback, err error) { |
|
64
|
1 |
|
u := fmt.Sprintf("v2/payments/%s/chargebacks/%s", paymentID, chargebackID) |
|
65
|
1 |
|
if options != nil { |
|
66
|
1 |
|
v, _ := query.Values(options) |
|
67
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
|
68
|
|
|
} |
|
69
|
1 |
|
req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil) |
|
70
|
1 |
|
if err != nil { |
|
71
|
1 |
|
return |
|
72
|
|
|
} |
|
73
|
1 |
|
res, err := cs.client.Do(req) |
|
74
|
1 |
|
if err != nil { |
|
75
|
1 |
|
return |
|
76
|
|
|
} |
|
77
|
1 |
|
if err = json.Unmarshal(res.content, &p); err != nil { |
|
78
|
1 |
|
return |
|
79
|
|
|
} |
|
80
|
1 |
|
return |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
// List retrieves a list of chargebacks associated with your account/organization. |
|
84
|
|
|
// |
|
85
|
|
|
// See: https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks |
|
86
|
|
|
func (cs *ChargebacksService) List(options *ListChargebackOptions) (pl ChargebackList, err error) { |
|
87
|
1 |
|
u := fmt.Sprint("v2/chargebacks") |
|
88
|
1 |
|
if options != nil { |
|
89
|
1 |
|
v, _ := query.Values(options) |
|
90
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
|
91
|
|
|
} |
|
92
|
1 |
|
req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil) |
|
93
|
1 |
|
if err != nil { |
|
94
|
1 |
|
return |
|
95
|
|
|
} |
|
96
|
1 |
|
res, err := cs.client.Do(req) |
|
97
|
1 |
|
if err != nil { |
|
98
|
1 |
|
return |
|
99
|
|
|
} |
|
100
|
1 |
|
if err = json.Unmarshal(res.content, &pl); err != nil { |
|
101
|
1 |
|
return |
|
102
|
|
|
} |
|
103
|
1 |
|
return |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
// ListForPayment retrieves a list of chargebacks associated with a single payment. |
|
107
|
|
|
// |
|
108
|
|
|
// See: https://docs.mollie.com/reference/v2/chargebacks-api/list-chargebacks |
|
109
|
|
|
func (cs *ChargebacksService) ListForPayment(paymentID string, options *ListChargebackOptions) (pl ChargebackList, err error) { |
|
110
|
1 |
|
u := fmt.Sprintf("v2/payments/%s/chargebacks", paymentID) |
|
111
|
1 |
|
if options != nil { |
|
112
|
1 |
|
v, _ := query.Values(options) |
|
113
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
|
114
|
|
|
} |
|
115
|
1 |
|
req, err := cs.client.NewAPIRequest(http.MethodGet, u, nil) |
|
116
|
1 |
|
if err != nil { |
|
117
|
1 |
|
return |
|
118
|
|
|
} |
|
119
|
1 |
|
res, err := cs.client.Do(req) |
|
120
|
1 |
|
if err != nil { |
|
121
|
1 |
|
return |
|
122
|
|
|
} |
|
123
|
1 |
|
if err = json.Unmarshal(res.content, &pl); err != nil { |
|
124
|
1 |
|
return |
|
125
|
|
|
} |
|
126
|
1 |
|
return |
|
127
|
|
|
} |
|
128
|
|
|
|