|
1
|
|
|
package mollie |
|
2
|
|
|
|
|
3
|
|
|
import ( |
|
4
|
|
|
"encoding/json" |
|
5
|
|
|
"fmt" |
|
6
|
|
|
"net/http" |
|
7
|
|
|
|
|
8
|
|
|
"github.com/google/go-querystring/query" |
|
9
|
|
|
) |
|
10
|
|
|
|
|
11
|
|
|
// PaymentMethodInfo describes a single method with details. |
|
12
|
|
|
type PaymentMethodInfo struct { |
|
13
|
|
|
Resource string `json:"resource,omitempty"` |
|
14
|
|
|
ID string `json:"id,omitempty"` |
|
15
|
|
|
Description string `json:"description,omitempty"` |
|
16
|
|
|
MinimumAmount *Amount `json:"minimumAmount,omitempty"` |
|
17
|
|
|
MaximumAmount *Amount `json:"maximumAmount,omitempty"` |
|
18
|
|
|
Image Image `json:"image,omitempty"` |
|
19
|
|
|
Pricing []PaymentMethodPricing `json:"pricing,omitempty"` |
|
20
|
|
|
Links MethodsLinks `json:"_links,omitempty"` |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
// MethodsLinks describes links attached to methods service responses. |
|
24
|
|
|
type MethodsLinks struct { |
|
25
|
|
|
Self URL `json:"self,omitempty"` |
|
26
|
|
|
Docs URL `json:"documentation,omitempty"` |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
// Image describes a generic image resource retrieved by Mollie. |
|
30
|
|
|
type Image struct { |
|
31
|
|
|
Size1x string `json:"size1X,omitempty"` |
|
32
|
|
|
Size2X string `json:"size2X,omitempty"` |
|
33
|
|
|
Svg string `json:"svg,omitempty"` |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
// PaymentMethodPricing contains information about commissions and fees |
|
37
|
|
|
// applicable to a payment method. |
|
38
|
|
|
type PaymentMethodPricing struct { |
|
39
|
|
|
Description string `json:"description,omitempty"` |
|
40
|
|
|
Fixed *Amount `json:"fixed,omitempty"` |
|
41
|
|
|
Variable string `json:"variable,omitempty"` |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// ListMethods describes a list of paginated payment methods. |
|
45
|
|
|
type ListMethods struct { |
|
46
|
|
|
Count int `json:"count,omitempty"` |
|
47
|
|
|
Embedded struct { |
|
48
|
|
|
Methods []PaymentMethodInfo |
|
49
|
|
|
} `json:"_embedded,omitempty"` |
|
50
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
// MethodsOptions are applicable query string parameters to methods |
|
54
|
|
|
// service endpoints. |
|
55
|
|
|
type MethodsOptions struct { |
|
56
|
|
|
Locale Locale `url:"locale,omitempty"` |
|
57
|
|
|
Currency string `url:"currency,omitempty"` |
|
58
|
|
|
ProfileID string `url:"profileId,omitempty"` |
|
59
|
|
|
Include string `url:"include,omitempty"` |
|
60
|
|
|
// Use for List method only |
|
61
|
|
|
SequenceType SequenceType `url:"sequenceType,omitempty"` |
|
62
|
|
|
Amount Amount `url:"amount,omitempty"` |
|
63
|
|
|
Resource string `url:"resource,omitempty"` |
|
64
|
|
|
BillingCountry string `url:"billingCountry,omitempty"` |
|
65
|
|
|
IncludeWallets string `json:"includeWallets,omitempty"` |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
// MethodsService operates on methods endpoints |
|
69
|
|
|
type MethodsService service |
|
70
|
|
|
|
|
71
|
|
|
// Get returns information about the payment method specified by id, |
|
72
|
|
|
// it also receives a pointer to the method options containing applicable |
|
73
|
|
|
// query string parameters |
|
74
|
|
|
// |
|
75
|
|
|
// See: https://docs.mollie.com/reference/v2/methods-api/get-method |
|
76
|
|
|
func (ms *MethodsService) Get(id string, options *MethodsOptions) (pmi *PaymentMethodInfo, err error) { |
|
77
|
1 |
|
u := fmt.Sprintf("v2/methods/%s", id) |
|
78
|
1 |
|
if options != nil { |
|
79
|
1 |
|
v, _ := query.Values(options) |
|
80
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
|
81
|
|
|
} |
|
82
|
1 |
|
req, err := ms.client.NewAPIRequest(http.MethodGet, u, nil) |
|
83
|
1 |
|
if err != nil { |
|
84
|
1 |
|
return |
|
85
|
|
|
} |
|
86
|
1 |
|
res, err := ms.client.Do(req) |
|
87
|
1 |
|
if err != nil { |
|
88
|
1 |
|
return |
|
89
|
|
|
} |
|
90
|
1 |
|
if err = json.Unmarshal(res.content, &pmi); err != nil { |
|
91
|
1 |
|
return |
|
92
|
|
|
} |
|
93
|
1 |
|
return |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
// All retrieves all the payment methods enabled for your account/organization |
|
97
|
|
|
// |
|
98
|
|
|
// See: https://docs.mollie.com/reference/v2/methods-api/list-all-methods |
|
99
|
|
|
func (ms *MethodsService) All(options *MethodsOptions) (pm *ListMethods, err error) { |
|
100
|
1 |
|
u := fmt.Sprintf("v2/methods/all") |
|
101
|
1 |
|
if options != nil { |
|
102
|
1 |
|
v, _ := query.Values(options) |
|
103
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
|
104
|
|
|
} |
|
105
|
1 |
|
req, err := ms.client.NewAPIRequest(http.MethodGet, u, nil) |
|
106
|
1 |
|
if err != nil { |
|
107
|
1 |
|
return |
|
108
|
|
|
} |
|
109
|
1 |
|
res, err := ms.client.Do(req) |
|
110
|
1 |
|
if err != nil { |
|
111
|
1 |
|
return |
|
112
|
|
|
} |
|
113
|
1 |
|
if err = json.Unmarshal(res.content, &pm); err != nil { |
|
114
|
1 |
|
return |
|
115
|
|
|
} |
|
116
|
1 |
|
return |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
// List retrieves all enabled payment methods. |
|
120
|
|
|
// The results are not paginated. |
|
121
|
|
|
// |
|
122
|
|
|
// See: https://docs.mollie.com/reference/v2/methods-api/list-methods |
|
123
|
|
|
func (ms *MethodsService) List(options *MethodsOptions) (pm *ListMethods, err error) { |
|
124
|
1 |
|
u := fmt.Sprintf("v2/methods") |
|
125
|
1 |
|
if options != nil { |
|
126
|
1 |
|
v, _ := query.Values(options) |
|
127
|
1 |
|
u = fmt.Sprintf("%s?%s", u, v.Encode()) |
|
128
|
|
|
} |
|
129
|
1 |
|
req, err := ms.client.NewAPIRequest(http.MethodGet, u, nil) |
|
130
|
1 |
|
if err != nil { |
|
131
|
1 |
|
return |
|
132
|
|
|
} |
|
133
|
1 |
|
res, err := ms.client.Do(req) |
|
134
|
1 |
|
if err != nil { |
|
135
|
1 |
|
return |
|
136
|
|
|
} |
|
137
|
1 |
|
if err = json.Unmarshal(res.content, &pm); err != nil { |
|
138
|
1 |
|
return |
|
139
|
|
|
} |
|
140
|
1 |
|
return |
|
141
|
|
|
} |
|
142
|
|
|
|