GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 876bc2...53a000 )
by
unknown
01:27
created

mollie/payment_links.go   A

Size/Duplication

Total Lines 195
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
cc 17
eloc 102
dl 0
loc 195
rs 10
c 0
b 0
f 0
ccs 18
cts 18
cp 1
crap 17

6 Methods

Rating   Name   Duplication   Size   Complexity  
A mollie.*PaymentLinksService.Update 0 15 3
A mollie.*PaymentLinksService.Create 0 15 3
A mollie.*PaymentLinksService.Payments 0 15 3
A mollie.*PaymentLinksService.Delete 0 7 2
A mollie.*PaymentLinksService.List 0 15 3
A mollie.*PaymentLinksService.Get 0 11 3
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/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/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
// PaymentLinkPaymentsList retrieves a list of payment associated with a specific
62
// payment link.
63
type PaymentLinkPaymentsList struct {
64
	Count    int              `json:"count,omitempty"`
65
	Links    PaymentLinkLinks `json:"_links,omitempty"`
66
	Embedded struct {
67
		Payments []*Payment `json:"payments,omitempty"`
68 1
	} `json:"_embedded,omitempty"`
69 1
}
70 1
71
// PaymentLinkPaymentsListOptions represents query string parameters to modify
72
// the payment link payments list requests.
73 1
type PaymentLinkPaymentsListOptions struct {
74 1
	Limit    int           `url:"limit,omitempty"`
75
	Sort     SortDirection `url:"sort,omitempty"`
76
	TestMode bool          `url:"testmode,omitempty"`
77 1
}
78
79
// UpdatePaymentLinks describes certain details of an existing payment link
80
// that can be updated.
81
type UpdatePaymentLinks struct {
82
	Description string `json:"description,omitempty"`
83
	Archived    bool   `json:"archived,omitempty"`
84
}
85
86
// PaymentLinksService operates over the payment link resource.
87
type PaymentLinksService service
88 1
89 1
// Get retrieves a single payment link object by its id/token.
90 1
//
91
// See: https://docs.mollie.com/reference/get-payment-link
92
func (pls *PaymentLinksService) Get(ctx context.Context, id string) (res *Response, pl *PaymentLink, err error) {
93 1
	res, err = pls.client.get(ctx, fmt.Sprintf("v2/payment-links/%s", id), nil)
94 1
	if err != nil {
95
		return
96
	}
97 1
98
	if err = json.Unmarshal(res.content, &pl); err != nil {
99
		return
100
	}
101
102
	return
103
}
104
105
// Create generates payment links that by default, unlike regular payments, do not expire.
106
//
107
// See: https://docs.mollie.com/reference/create-payment-link
108
func (pls *PaymentLinksService) Create(ctx context.Context, p PaymentLink, opts *PaymentLinkOptions) (
109 1
	res *Response,
110 1
	np *PaymentLink,
111 1
	err error,
112
) {
113
	res, err = pls.client.post(ctx, "v2/payment-links", p, opts)
114 1
	if err != nil {
115 1
		return
116
	}
117
118 1
	if err = json.Unmarshal(res.content, &np); err != nil {
119
		return
120
	}
121
122
	return
123
}
124
125
// List retrieves all payments links created with the current website profile,
126
// ordered from newest to oldest.
127
//
128
// See: https://docs.mollie.com/reference/list-payment-links
129
func (pls *PaymentLinksService) List(ctx context.Context, opts *PaymentLinkOptions) (
130
	res *Response,
131
	pl *PaymentLinksList,
132
	err error,
133
) {
134
	res, err = pls.client.get(ctx, "v2/payment-links", opts)
135
	if err != nil {
136
		return
137
	}
138
139
	if err = json.Unmarshal(res.content, &pl); err != nil {
140
		return
141
	}
142
143
	return
144
}
145
146
// Update changes certain details of an existing payment link.
147
//
148
// See: https://docs.mollie.com/reference/update-payment-link
149
func (pls *PaymentLinksService) Update(ctx context.Context, id string, p UpdatePaymentLinks) (
150
	res *Response,
151
	pl *PaymentLink,
152
	err error,
153
) {
154
	res, err = pls.client.patch(ctx, fmt.Sprintf("v2/payment-links/%s", id), p)
155
	if err != nil {
156
		return
157
	}
158
159
	if err = json.Unmarshal(res.content, &pl); err != nil {
160
		return
161
	}
162
163
	return
164
}
165
166
// Delete removes a payment link from the website profile.
167
//
168
// See: https://docs.mollie.com/reference/delete-payment-link
169
func (pls *PaymentLinksService) Delete(ctx context.Context, id string) (res *Response, err error) {
170
	res, err = pls.client.delete(ctx, fmt.Sprintf("v2/payment-links/%s", id))
171
	if err != nil {
172
		return
173
	}
174
175
	return
176
}
177
178
// Payments retrieves all payments associated with a specific payment link.
179
//
180
// See: https://docs.mollie.com/reference/get-payment-link-payments
181
func (pls *PaymentLinksService) Payments(ctx context.Context, id string, opts *PaymentLinkPaymentsListOptions) (
182
	res *Response,
183
	pl *PaymentLinkPaymentsList,
184
	err error,
185
) {
186
	res, err = pls.client.get(ctx, fmt.Sprintf("v2/payment-links/%s/payments", id), opts)
187
	if err != nil {
188
		return
189
	}
190
191
	if err = json.Unmarshal(res.content, &pl); err != nil {
192
		return
193
	}
194
195
	return
196
}
197