1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"fmt" |
7
|
|
|
"net/http" |
8
|
|
|
"time" |
9
|
|
|
) |
10
|
|
|
|
11
|
|
|
// ProfileStatus determines whether the profile is able to receive live payments. |
12
|
|
|
type ProfileStatus string |
13
|
|
|
|
14
|
|
|
// Possible profile statuses. |
15
|
|
|
const ( |
16
|
|
|
StatusUnverified ProfileStatus = "unverified" |
17
|
|
|
StatusVerified ProfileStatus = "verified" |
18
|
|
|
StatusBlocked ProfileStatus = "blocked" |
19
|
|
|
) |
20
|
|
|
|
21
|
|
|
// CreateOrUpdateProfile describes the parameters to create or update a profile. |
22
|
|
|
type CreateOrUpdateProfile struct { |
23
|
|
|
Name string `json:"name,omitempty"` |
24
|
|
|
Website string `json:"website,omitempty"` |
25
|
|
|
Email string `json:"email,omitempty"` |
26
|
|
|
Description string `json:"description,omitempty"` |
27
|
|
|
Phone PhoneNumber `json:"phone,omitempty"` |
28
|
|
|
BusinessCategory BusinessCategory `json:"businessCategory,omitempty"` |
29
|
|
|
CategoryCode CategoryCode `json:"categoryCode,omitempty"` |
30
|
|
|
Mode Mode `json:"mode,omitempty"` |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
// Profile will usually reflect the trademark or brand name |
34
|
|
|
// of the profile’s website or application. |
35
|
|
|
type Profile struct { |
36
|
|
|
Resource string `json:"resource,omitempty"` |
37
|
|
|
ID string `json:"id,omitempty"` |
38
|
|
|
Name string `json:"name,omitempty"` |
39
|
|
|
Website string `json:"website,omitempty"` |
40
|
|
|
Description string `json:"description,omitempty"` |
41
|
|
|
CountriesOfActivity []string `json:"countriesOfActivity,omitempty"` |
42
|
|
|
Email string `json:"email,omitempty"` |
43
|
|
|
Phone PhoneNumber `json:"phone,omitempty"` |
44
|
|
|
Mode Mode `json:"mode,omitempty"` |
45
|
|
|
BusinessCategory BusinessCategory `json:"businessCategory,omitempty"` |
46
|
|
|
CategoryCode CategoryCode `json:"categoryCode,omitempty"` |
47
|
|
|
Status ProfileStatus `json:"status,omitempty"` |
48
|
|
|
Review ProfileReview `json:"review,omitempty"` |
49
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
50
|
|
|
Links ProfileLinks `json:"_links,omitempty"` |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// ProfileReview contains the status of the profile review. |
54
|
|
|
type ProfileReview struct { |
55
|
|
|
Status ProfileReviewStatus `json:"status,omitempty"` |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
// ProfileReviewStatus determines whether the profile is able to receive live payments. |
59
|
|
|
type ProfileReviewStatus string |
60
|
|
|
|
61
|
|
|
// Possible profile review statuses. |
62
|
|
|
const ( |
63
|
|
|
ReviewStatusPending ProfileReviewStatus = "pending" |
64
|
|
|
ReviewStatusRejected ProfileReviewStatus = "rejected" |
65
|
|
|
) |
66
|
|
|
|
67
|
|
|
// ProfileLinks contains URL's to relevant information related to |
68
|
|
|
// a profile. |
69
|
|
|
type ProfileLinks struct { |
70
|
|
|
Self *URL `json:"self,omitempty"` |
71
|
|
|
Dashboard *URL `json:"dashboard,omitempty"` |
72
|
|
|
Chargebacks *URL `json:"chargebacks,omitempty"` |
73
|
|
|
Methods *URL `json:"methods,omitempty"` |
74
|
|
|
Payments *URL `json:"payments,omitempty"` |
75
|
|
|
Refunds *URL `json:"refunds,omitempty"` |
76
|
1 |
|
CheckoutPreviewURL *URL `json:"checkoutPreviewUrl,omitempty"` |
77
|
1 |
|
Documentation *URL `json:"documentation,omitempty"` |
78
|
1 |
|
} |
79
|
|
|
|
80
|
|
|
// ProfileListOptions are optional query string parameters for the list profiles request. |
81
|
1 |
|
type ProfileListOptions struct { |
82
|
1 |
|
Limit int `url:"limit,omitempty"` |
83
|
|
|
From string `url:"from,omitempty"` |
84
|
|
|
} |
85
|
1 |
|
|
86
|
|
|
// ProfileList contains a list of profiles for your account. |
87
|
|
|
type ProfileList struct { |
88
|
|
|
Count int `json:"count,omitempty"` |
89
|
|
|
Embedded struct { |
90
|
1 |
|
Profiles []*Profile `json:"profiles,omitempty"` |
91
|
|
|
} `json:"_embedded,omitempty"` |
92
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
// EnableVoucherIssuer describes the parameters to enable a voucher issuer. |
96
|
1 |
|
type EnableVoucherIssuer struct { |
97
|
|
|
ContractID string `json:"contractId,omitempty"` |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
// ProfilesService operates over profile resource. |
101
|
1 |
|
type ProfilesService service |
102
|
1 |
|
|
103
|
|
|
// List returns all the profiles for the authenticated account. |
104
|
|
|
func (ps *ProfilesService) List(ctx context.Context, opts *ProfileListOptions) ( |
105
|
1 |
|
res *Response, |
106
|
1 |
|
pl *ProfileList, |
107
|
|
|
err error, |
108
|
|
|
) { |
109
|
1 |
|
res, err = ps.client.get(ctx, "v2/profiles", opts) |
110
|
|
|
if err != nil { |
111
|
|
|
return |
112
|
|
|
} |
113
|
|
|
|
114
|
1 |
|
if err = json.Unmarshal(res.content, &pl); err != nil { |
115
|
1 |
|
return |
116
|
1 |
|
} |
117
|
|
|
|
118
|
|
|
return |
119
|
1 |
|
} |
120
|
1 |
|
|
121
|
|
|
// Get retrieves the a profile by ID. |
122
|
|
|
func (ps *ProfilesService) Get(ctx context.Context, id string) (res *Response, p *Profile, err error) { |
123
|
1 |
|
return ps.get(ctx, id) |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
// Current returns the profile belonging to the API key. |
127
|
|
|
// This method only works when using API keys. |
128
|
1 |
|
func (ps *ProfilesService) Current(ctx context.Context) (res *Response, p *Profile, err error) { |
129
|
1 |
|
return ps.get(ctx, "me") |
130
|
1 |
|
} |
131
|
|
|
|
132
|
|
|
func (ps *ProfilesService) get(ctx context.Context, id string) (res *Response, p *Profile, err error) { |
133
|
1 |
|
res, err = ps.client.get(ctx, fmt.Sprintf("v2/profiles/%s", id), nil) |
134
|
1 |
|
if err != nil { |
135
|
|
|
return |
136
|
|
|
} |
137
|
1 |
|
|
138
|
|
|
if err = json.Unmarshal(res.content, &p); err != nil { |
139
|
|
|
return |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return |
143
|
1 |
|
} |
144
|
1 |
|
|
145
|
1 |
|
// Create stores a new profile in your Mollie account. |
146
|
|
|
func (ps *ProfilesService) Create(ctx context.Context, np CreateOrUpdateProfile) ( |
147
|
|
|
res *Response, |
148
|
1 |
|
p *Profile, |
149
|
|
|
err error, |
150
|
|
|
) { |
151
|
|
|
res, err = ps.client.post(ctx, "v2/profiles", np, nil) |
152
|
|
|
if err != nil { |
153
|
|
|
return |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
if err = json.Unmarshal(res.content, &p); err != nil { |
157
|
|
|
return |
158
|
1 |
|
} |
159
|
1 |
|
|
160
|
1 |
|
return |
161
|
|
|
} |
162
|
|
|
|
163
|
1 |
|
// Update allows you to perform mutations on a profile. |
164
|
1 |
|
func (ps *ProfilesService) Update(ctx context.Context, id string, up CreateOrUpdateProfile) ( |
165
|
|
|
res *Response, |
166
|
|
|
p *Profile, |
167
|
1 |
|
err error, |
168
|
|
|
) { |
169
|
|
|
res, err = ps.client.patch(ctx, fmt.Sprintf("v2/profiles/%s", id), up, nil) |
170
|
|
|
if err != nil { |
171
|
|
|
return |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
if err = json.Unmarshal(res.content, &p); err != nil { |
175
|
|
|
return |
176
|
1 |
|
} |
177
|
1 |
|
|
178
|
1 |
|
return |
179
|
|
|
} |
180
|
|
|
|
181
|
1 |
|
// Delete enables profile deletions, rendering the profile unavailable |
182
|
|
|
// for further API calls and transactions. |
183
|
|
|
func (ps *ProfilesService) Delete(ctx context.Context, id string) (res *Response, err error) { |
184
|
|
|
res, err = ps.client.delete(ctx, fmt.Sprintf("v2/profiles/%s", id), nil) |
185
|
|
|
if err != nil { |
186
|
|
|
return |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
return |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
// EnablePaymentMethod enables a payment method on a specific or authenticated profile. |
193
|
1 |
|
// If you're using API tokens for authentication, pass "me" as id. |
194
|
1 |
|
func (ps *ProfilesService) EnablePaymentMethod(ctx context.Context, id string, pm PaymentMethod) ( |
195
|
1 |
|
res *Response, |
196
|
|
|
pmi *PaymentMethodDetails, |
197
|
|
|
err error, |
198
|
1 |
|
) { |
199
|
1 |
|
res, err = ps.client.post(ctx, fmt.Sprintf("v2/profiles/%s/methods/%s", id, pm), nil, nil) |
200
|
|
|
if err != nil { |
201
|
|
|
return |
202
|
1 |
|
} |
203
|
|
|
|
204
|
|
|
if err = json.Unmarshal(res.content, &pmi); err != nil { |
205
|
|
|
return |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
return |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
// DisablePaymentMethod disables a payment method on a specific or authenticated profile. |
212
|
|
|
// If you're using API tokens for authentication, pass "me" as id. |
213
|
1 |
|
func (ps *ProfilesService) DisablePaymentMethod(ctx context.Context, id string, pm PaymentMethod) ( |
214
|
1 |
|
res *Response, |
215
|
1 |
|
err error, |
216
|
|
|
) { |
217
|
|
|
res, err = ps.client.delete(ctx, fmt.Sprintf("v2/profiles/%s/methods/%s", id, pm), nil) |
218
|
1 |
|
if err != nil { |
219
|
|
|
return |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
// EnableGiftCardIssuer activates the requested gift card issuer for the provided |
226
|
|
|
// profile id when using Organization tokens or App Access tokens. |
227
|
|
|
// |
228
|
|
|
// See: https://docs.mollie.com/reference/v2/profiles-api/enable-gift-card-issuer |
229
|
|
|
func (ps *ProfilesService) EnableGiftCardIssuer(ctx context.Context, profileID string, issuer GiftCardIssuer) ( |
230
|
1 |
|
res *Response, |
231
|
1 |
|
gc *GiftCardEnabled, |
232
|
1 |
|
err error, |
233
|
|
|
) { |
234
|
|
|
res, err = ps.toggleGiftCardIssuerStatus(ctx, profileID, http.MethodPost, issuer) |
235
|
1 |
|
if err != nil { |
236
|
1 |
|
return |
237
|
|
|
} |
238
|
|
|
|
239
|
1 |
|
if err = json.Unmarshal(res.content, &gc); err != nil { |
240
|
|
|
return |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
return |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
// DisableGiftCardIssuer deactivates the requested gift card issuer for the provided |
247
|
|
|
// profile id when using Organization tokens or App Access tokens. |
248
|
|
|
// |
249
|
|
|
// See: https://docs.mollie.com/reference/v2/profiles-api/disable-gift-card-issuer |
250
|
1 |
|
func (ps *ProfilesService) DisableGiftCardIssuer(ctx context.Context, profileID string, issuer GiftCardIssuer) ( |
251
|
1 |
|
res *Response, |
252
|
1 |
|
err error, |
253
|
|
|
) { |
254
|
|
|
res, err = ps.toggleGiftCardIssuerStatus(ctx, profileID, http.MethodDelete, issuer) |
255
|
1 |
|
if err != nil { |
256
|
|
|
return |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
return |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
// EnableGiftCardIssuerForCurrent activates the specified issuer for the |
263
|
|
|
// current profile when using API tokens. |
264
|
|
|
// |
265
|
|
|
// See: https://docs.mollie.com/reference/v2/profiles-api/enable-gift-card-issuer |
266
|
1 |
|
func (ps *ProfilesService) EnableGiftCardIssuerForCurrent(ctx context.Context, issuer GiftCardIssuer) ( |
267
|
|
|
res *Response, |
268
|
1 |
|
gc *GiftCardEnabled, |
269
|
|
|
err error, |
270
|
1 |
|
) { |
271
|
|
|
res, err = ps.toggleGiftCardIssuerStatus(ctx, "me", http.MethodPost, issuer) |
272
|
1 |
|
if err != nil { |
273
|
|
|
return |
274
|
|
|
} |
275
|
1 |
|
|
276
|
1 |
|
if err = json.Unmarshal(res.content, &gc); err != nil { |
277
|
|
|
return |
278
|
|
|
} |
279
|
1 |
|
|
280
|
|
|
return |
281
|
|
|
} |
282
|
|
|
|
283
|
|
|
// DisableGiftCardIssuerForCurrent deactivates the specified issuer for the |
284
|
|
|
// current profile when using API tokens. |
285
|
|
|
// |
286
|
|
|
// See: https://docs.mollie.com/reference/v2/profiles-api/disable-gift-card-issuer |
287
|
|
|
func (ps *ProfilesService) DisableGiftCardIssuerForCurrent(ctx context.Context, issuer GiftCardIssuer) ( |
288
|
|
|
res *Response, |
289
|
|
|
err error, |
290
|
|
|
) { |
291
|
|
|
res, err = ps.toggleGiftCardIssuerStatus(ctx, "me", http.MethodDelete, issuer) |
292
|
|
|
if err != nil { |
293
|
|
|
return |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
return |
297
|
|
|
} |
298
|
|
|
|
299
|
|
|
// EnableVoucherIssuer activates the requested voucher issuer for the provided |
300
|
|
|
// profile id when using Organization tokens or App Access tokens. |
301
|
|
|
// |
302
|
|
|
// See: https://docs.mollie.com/reference/v2/profiles-api/enable-voucher-issuer |
303
|
|
|
func (ps *ProfilesService) EnableVoucherIssuer( |
304
|
|
|
ctx context.Context, |
305
|
|
|
profileID string, |
306
|
|
|
issuer VoucherIssuer, |
307
|
|
|
vi *EnableVoucherIssuer, |
308
|
|
|
) ( |
309
|
|
|
res *Response, |
310
|
|
|
vc *VoucherIssuerEnabled, |
311
|
|
|
err error, |
312
|
|
|
) { |
313
|
|
|
res, err = ps.toggleVoucherIssuerStatus(ctx, profileID, http.MethodPost, issuer) |
314
|
|
|
if err != nil { |
315
|
|
|
return |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
if err = json.Unmarshal(res.content, &vc); err != nil { |
319
|
|
|
return |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
return |
323
|
|
|
} |
324
|
|
|
|
325
|
|
|
// DisableVoucherIssuer deactivates the requested voucher issuer for the provided |
326
|
|
|
// profile id when using Organization tokens or App Access tokens. |
327
|
|
|
// |
328
|
|
|
// See: https://docs.mollie.com/reference/v2/profiles-api/disable-voucher-issuer |
329
|
|
|
func (ps *ProfilesService) DisableVoucherIssuer(ctx context.Context, profileID string, issuer VoucherIssuer) ( |
330
|
|
|
res *Response, |
331
|
|
|
err error, |
332
|
|
|
) { |
333
|
|
|
res, err = ps.toggleVoucherIssuerStatus(ctx, profileID, http.MethodDelete, issuer) |
334
|
|
|
if err != nil { |
335
|
|
|
return |
336
|
|
|
} |
337
|
|
|
|
338
|
|
|
return |
339
|
|
|
} |
340
|
|
|
|
341
|
|
|
// EnableVoucherIssuerForCurrent activates the specified issuer for the |
342
|
|
|
// current profile when using API tokens. |
343
|
|
|
func (ps *ProfilesService) EnableVoucherIssuerForCurrent(ctx context.Context, issuer VoucherIssuer) ( |
344
|
|
|
res *Response, |
345
|
|
|
vc *VoucherIssuerEnabled, |
346
|
|
|
err error, |
347
|
|
|
) { |
348
|
|
|
res, err = ps.toggleVoucherIssuerStatus(ctx, "me", http.MethodPost, issuer) |
349
|
|
|
if err != nil { |
350
|
|
|
return |
351
|
|
|
} |
352
|
|
|
|
353
|
|
|
if err = json.Unmarshal(res.content, &vc); err != nil { |
354
|
|
|
return |
355
|
|
|
} |
356
|
|
|
|
357
|
|
|
return |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
// DisableVoucherIssuerForCurrent deactivates the specified issuer for the |
361
|
|
|
// current profile when using API tokens. |
362
|
|
|
func (ps *ProfilesService) DisableVoucherIssuerForCurrent(ctx context.Context, issuer VoucherIssuer) ( |
363
|
|
|
res *Response, |
364
|
|
|
err error, |
365
|
|
|
) { |
366
|
|
|
res, err = ps.toggleVoucherIssuerStatus(ctx, "me", http.MethodDelete, issuer) |
367
|
|
|
if err != nil { |
368
|
|
|
return |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
return |
372
|
|
|
} |
373
|
|
|
|
374
|
|
|
func (ps *ProfilesService) toggleGiftCardIssuerStatus( |
375
|
|
|
ctx context.Context, |
376
|
|
|
profile string, |
377
|
|
|
method string, |
378
|
|
|
issuer GiftCardIssuer) ( |
379
|
|
|
r *Response, |
380
|
|
|
err error, |
381
|
|
|
) { |
382
|
|
|
u := fmt.Sprintf("v2/profiles/%s/methods/giftcard/issuers/%s", profile, issuer) |
383
|
|
|
|
384
|
|
|
switch method { |
385
|
|
|
case http.MethodDelete: |
386
|
|
|
r, err = ps.client.delete(ctx, u, nil) |
387
|
|
|
case http.MethodPost: |
388
|
|
|
r, err = ps.client.post(ctx, u, nil, nil) |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
if err != nil { |
392
|
|
|
return |
393
|
|
|
} |
394
|
|
|
|
395
|
|
|
return |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
func (ps *ProfilesService) toggleVoucherIssuerStatus( |
399
|
|
|
ctx context.Context, |
400
|
|
|
profile string, |
401
|
|
|
method string, |
402
|
|
|
issuer VoucherIssuer) ( |
403
|
|
|
r *Response, |
404
|
|
|
err error, |
405
|
|
|
) { |
406
|
|
|
u := fmt.Sprintf("v2/profiles/%s/methods/voucher/issuers/%s", profile, issuer) |
407
|
|
|
|
408
|
|
|
switch method { |
409
|
|
|
case http.MethodDelete: |
410
|
|
|
r, err = ps.client.delete(ctx, u, nil) |
411
|
|
|
case http.MethodPost: |
412
|
|
|
r, err = ps.client.post(ctx, u, nil, nil) |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
if err != nil { |
416
|
|
|
return |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
return |
420
|
|
|
} |
421
|
|
|
|