1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"fmt" |
7
|
|
|
"time" |
8
|
|
|
) |
9
|
|
|
|
10
|
|
|
// PaymentLink is a resource that can be shared with your customers |
11
|
|
|
// and will redirect them to them the payment page where they can |
12
|
|
|
// complete the payment. |
13
|
|
|
// |
14
|
|
|
// See: https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link |
15
|
|
|
type PaymentLink struct { |
16
|
|
|
ID string `json:"id,omitempty"` |
17
|
|
|
Resource string `json:"resource,omitempty"` |
18
|
|
|
Description string `json:"description,omitempty"` |
19
|
|
|
ProfileID string `json:"profileId,omitempty"` |
20
|
|
|
RedirectURL string `json:"redirectUrl,omitempty"` |
21
|
|
|
WebhookURL string `json:"webhookUrl,omitempty"` |
22
|
|
|
Mode Mode `json:"mode,omitempty"` |
23
|
|
|
Amount Amount `json:"amount,omitempty"` |
24
|
|
|
CreatedAt *time.Time `json:"createdAt,omitempty"` |
25
|
|
|
PaidAt *time.Time `json:"paidAt,omitempty"` |
26
|
|
|
UpdatedAt *time.Time `json:"updatedAt,omitempty"` |
27
|
|
|
ExpiresAt *time.Time `json:"expiresAt,omitempty"` |
28
|
|
|
Links PaymentLinkLinks `json:"_links,omitempty"` |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
// PaymentLinkLinks describes all the possible links returned with |
32
|
|
|
// a payment link struct. |
33
|
|
|
// |
34
|
|
|
// See: https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link |
35
|
|
|
type PaymentLinkLinks struct { |
36
|
|
|
Self *URL `json:"self,omitempty"` |
37
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
38
|
|
|
PaymentLink *URL `json:"paymentLink,omitempty"` |
39
|
|
|
Next *URL `json:"next,omitempty"` |
40
|
|
|
Previous *URL `json:"previous,omitempty"` |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
// PaymentLinkOptions represents query string parameters to modify |
44
|
|
|
// the payment links requests. |
45
|
|
|
type PaymentLinkOptions struct { |
46
|
|
|
Limit int `url:"limit,omitempty"` |
47
|
|
|
ProfileID string `url:"profileId,omitempty"` |
48
|
|
|
From string `url:"from,omitempty"` |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
// PaymentLinksList retrieves a list of payment links for the active |
52
|
|
|
// profile or account token owner. |
53
|
|
|
type PaymentLinksList struct { |
54
|
|
|
Count int `json:"count,omitempty"` |
55
|
|
|
Links PaymentLinkLinks `json:"_links,omitempty"` |
56
|
|
|
Embedded struct { |
57
|
|
|
PaymentLinks []*PaymentLink `json:"payment_links,omitempty"` |
58
|
|
|
} `json:"_embedded,omitempty"` |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// UpdatePaymentLinks describes certain details of an existing payment link |
62
|
|
|
// that can be updated. |
63
|
|
|
type UpdatePaymentLinks struct { |
64
|
|
|
Description string `json:"description,omitempty"` |
65
|
|
|
Archived bool `json:"archived,omitempty"` |
66
|
|
|
} |
67
|
|
|
|
68
|
1 |
|
// PaymentLinksService operates over the payment link resource. |
69
|
1 |
|
type PaymentLinksService service |
70
|
1 |
|
|
71
|
|
|
// Get retrieves a single payment link object by its id/token. |
72
|
|
|
// |
73
|
1 |
|
// See: https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link |
74
|
1 |
|
func (pls *PaymentLinksService) Get(ctx context.Context, id string) (res *Response, pl *PaymentLink, err error) { |
75
|
|
|
res, err = pls.client.get(ctx, fmt.Sprintf("v2/payment-links/%s", id), nil) |
76
|
|
|
if err != nil { |
77
|
1 |
|
return |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
if err = json.Unmarshal(res.content, &pl); err != nil { |
81
|
|
|
return |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
// Create generates payment links that by default, unlike regular payments, do not expire. |
88
|
1 |
|
// |
89
|
1 |
|
// See: https://docs.mollie.com/reference/v2/payment-links-api/create-payment-link |
90
|
1 |
|
func (pls *PaymentLinksService) Create(ctx context.Context, p PaymentLink, opts *PaymentLinkOptions) ( |
91
|
|
|
res *Response, |
92
|
|
|
np *PaymentLink, |
93
|
1 |
|
err error, |
94
|
1 |
|
) { |
95
|
|
|
res, err = pls.client.post(ctx, "v2/payment-links", p, opts) |
96
|
|
|
if err != nil { |
97
|
1 |
|
return |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if err = json.Unmarshal(res.content, &np); err != nil { |
101
|
|
|
return |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
// List retrieves all payments links created with the current website profile, |
108
|
|
|
// ordered from newest to oldest. |
109
|
1 |
|
// |
110
|
1 |
|
// See: https://docs.mollie.com/reference/v2/payment-links-api/list-payment-links |
111
|
1 |
|
func (pls *PaymentLinksService) List(ctx context.Context, opts *PaymentLinkOptions) ( |
112
|
|
|
res *Response, |
113
|
|
|
pl *PaymentLinksList, |
114
|
1 |
|
err error, |
115
|
1 |
|
) { |
116
|
|
|
res, err = pls.client.get(ctx, "v2/payment-links", opts) |
117
|
|
|
if err != nil { |
118
|
1 |
|
return |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
if err = json.Unmarshal(res.content, &pl); err != nil { |
122
|
|
|
return |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// Update changes certain details of an existing payment link. |
129
|
|
|
// |
130
|
|
|
// See: https://docs.mollie.com/reference/update-payment-link |
131
|
|
|
func (pls *PaymentLinksService) Update(ctx context.Context, id string, p UpdatePaymentLinks) ( |
132
|
|
|
res *Response, |
133
|
|
|
pl *PaymentLink, |
134
|
|
|
err error, |
135
|
|
|
) { |
136
|
|
|
res, err = pls.client.patch(ctx, fmt.Sprintf("v2/payment-links/%s", id), p) |
137
|
|
|
if err != nil { |
138
|
|
|
return |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if err = json.Unmarshal(res.content, &pl); err != nil { |
142
|
|
|
return |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
// Delete removes a payment link from the website profile. |
149
|
|
|
// |
150
|
|
|
// See: https://docs.mollie.com/reference/delete-payment-link |
151
|
|
|
func (pls *PaymentLinksService) Delete(ctx context.Context, id string) (res *Response, err error) { |
152
|
|
|
res, err = pls.client.delete(ctx, fmt.Sprintf("v2/payment-links/%s", id)) |
153
|
|
|
if err != nil { |
154
|
|
|
return |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
return |
158
|
|
|
} |
159
|
|
|
|