1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"fmt" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
// PaymentMethodStatus tels the status that the method is in. |
10
|
|
|
// Possible values: activated pending-boarding pending-review |
11
|
|
|
// pending-external rejected. |
12
|
|
|
type PaymentMethodStatus string |
13
|
|
|
|
14
|
|
|
// Available payment method statuses. |
15
|
|
|
const ( |
16
|
|
|
PaymentMethodActivated PaymentMethodStatus = "activated" |
17
|
|
|
PaymentMethodPendingBoarding PaymentMethodStatus = "pending-boarding" |
18
|
|
|
PaymentMethodPendingReview PaymentMethodStatus = "pending-review" |
19
|
|
|
PaymentMethodPendingExternal PaymentMethodStatus = "pending-external" |
20
|
|
|
PaymentMethodRejected PaymentMethodStatus = "pending-rejected" |
21
|
|
|
) |
22
|
|
|
|
23
|
|
|
// PaymentMethodDetails describes a single method with details. |
24
|
|
|
type PaymentMethodDetails struct { |
25
|
|
|
Resource string `json:"resource,omitempty"` |
26
|
|
|
ID string `json:"id,omitempty"` |
27
|
|
|
Description string `json:"description,omitempty"` |
28
|
|
|
MinimumAmount *Amount `json:"minimumAmount,omitempty"` |
29
|
|
|
MaximumAmount *Amount `json:"maximumAmount,omitempty"` |
30
|
|
|
Image *Image `json:"image,omitempty"` |
31
|
|
|
Pricing []*PaymentMethodPricing `json:"pricing,omitempty"` |
32
|
|
|
Issuers []*PaymentMethodIssuer `json:"issuers,omitempty"` |
33
|
|
|
Status *PaymentMethodStatus `json:"status,omitempty"` |
34
|
|
|
Links MethodsLinks `json:"_links,omitempty"` |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// MethodsLinks describes links attached to methods service responses. |
38
|
|
|
type MethodsLinks struct { |
39
|
|
|
Self *URL `json:"self,omitempty"` |
40
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// PaymentMethodPricing contains information about commissions and fees |
44
|
|
|
// applicable to a payment method. |
45
|
|
|
type PaymentMethodPricing struct { |
46
|
|
|
Description string `json:"description,omitempty"` |
47
|
|
|
Fixed *Amount `json:"fixed,omitempty"` |
48
|
|
|
Variable string `json:"variable,omitempty"` |
49
|
|
|
FeeRegion FeeRegion `json:"feeRegion,omitempty"` |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
// PaymentMethodIssuer available for the payment method |
53
|
|
|
// (for iDEAL, KBC/CBC payment button, gift cards, or meal vouchers). |
54
|
|
|
type PaymentMethodIssuer struct { |
55
|
|
|
Resource string `json:"resource,omitempty"` |
56
|
|
|
ID string `json:"id,omitempty"` |
57
|
|
|
Name string `json:"name,omitempty"` |
58
|
|
|
Image Image `json:"image,omitempty"` |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// PaymentMethodsList describes a list of paginated payment methods. |
62
|
|
|
type PaymentMethodsList struct { |
63
|
|
|
Count int `json:"count,omitempty"` |
64
|
|
|
Embedded struct { |
65
|
|
|
Methods []*PaymentMethodDetails |
66
|
|
|
} `json:"_embedded,omitempty"` |
67
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// PaymentMethodOptions are applicable query string parameters to get methods |
71
|
|
|
// from mollie's API. |
72
|
|
|
type PaymentMethodOptions struct { |
73
|
|
|
Locale Locale `url:"locale,omitempty"` |
74
|
|
|
Currency string `url:"currency,omitempty"` |
75
|
|
|
ProfileID string `url:"profileId,omitempty"` |
76
|
|
|
Include string `url:"include,omitempty"` |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
// PaymentMethodsListOptions are applicable query string parameters to list methods |
80
|
|
|
// from mollie's API. |
81
|
|
|
// |
82
|
|
|
// It contains list specific options and embeds GetMethodOptions. |
83
|
|
|
type PaymentMethodsListOptions struct { |
84
|
|
|
PaymentMethodOptions |
85
|
|
|
SequenceType SequenceType `url:"sequenceType,omitempty"` |
86
|
|
|
AmountCurrency string `url:"amount[currency],omitempty"` |
87
|
|
|
AmountValue string `url:"amount[value],omitempty"` |
88
|
|
|
Resource string `url:"resource,omitempty"` |
89
|
|
|
BillingCountry string `url:"billingCountry,omitempty"` |
90
|
|
|
IncludeWallets string `url:"includeWallets,omitempty"` |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
// PaymentMethodsService operates on methods endpoints. |
94
|
|
|
type PaymentMethodsService service |
95
|
|
|
|
96
|
|
|
// Get returns information about the payment method specified by id, |
97
|
|
|
// it also receives a pointer to the method options containing applicable |
98
|
|
|
// query string parameters. |
99
|
|
|
// |
100
|
|
|
// See: https://docs.mollie.com/reference/v2/methods-api/get-method |
101
|
|
|
func (ms *PaymentMethodsService) Get(ctx context.Context, id PaymentMethod, options *PaymentMethodOptions) (res *Response, pmd *PaymentMethodDetails, err error) { |
102
|
1 |
|
u := fmt.Sprintf("v2/methods/%s", id) |
103
|
|
|
|
104
|
1 |
|
res, err = ms.client.get(ctx, u, options) |
105
|
1 |
|
if err != nil { |
106
|
1 |
|
return |
107
|
|
|
} |
108
|
|
|
|
109
|
1 |
|
if err = json.Unmarshal(res.content, &pmd); err != nil { |
110
|
1 |
|
return |
111
|
|
|
} |
112
|
|
|
|
113
|
1 |
|
return |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
// All retrieves all the payment methods enabled for your account/organization. |
117
|
|
|
// |
118
|
|
|
// See: https://docs.mollie.com/reference/v2/methods-api/list-all-methods |
119
|
|
|
func (ms *PaymentMethodsService) All(ctx context.Context, options *PaymentMethodsListOptions) (res *Response, pm *PaymentMethodsList, err error) { |
120
|
1 |
|
return ms.list(ctx, "v2/methods/all", options) |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// List retrieves all enabled payment methods. |
124
|
|
|
// |
125
|
|
|
// The results are not paginated. |
126
|
|
|
// |
127
|
|
|
// See: https://docs.mollie.com/reference/v2/methods-api/list-methods |
128
|
|
|
func (ms *PaymentMethodsService) List(ctx context.Context, options *PaymentMethodsListOptions) (res *Response, pm *PaymentMethodsList, err error) { |
129
|
1 |
|
return ms.list(ctx, "v2/methods", options) |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
func (ms *PaymentMethodsService) list(ctx context.Context, uri string, options interface{}) (res *Response, pm *PaymentMethodsList, err error) { |
133
|
1 |
|
res, err = ms.client.get(ctx, uri, options) |
134
|
1 |
|
if err != nil { |
135
|
1 |
|
return |
136
|
|
|
} |
137
|
|
|
|
138
|
1 |
|
if err = json.Unmarshal(res.content, &pm); err != nil { |
139
|
1 |
|
return |
140
|
|
|
} |
141
|
|
|
|
142
|
1 |
|
return |
143
|
|
|
} |
144
|
|
|
|