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 ( b7d316...255319 )
by Victor Hugo
01:12 queued 11s
created

mollie.*PaymentLinksService.List   A

Complexity

Conditions 5

Size

Total Lines 19
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 6.4222

Importance

Changes 0
Metric Value
cc 5
eloc 14
dl 0
loc 19
c 0
b 0
f 0
ccs 8
cts 13
cp 0.6153
crap 6.4222
rs 9.2333
nop 1
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"net/http"
7
	"time"
8
9
	"github.com/google/go-querystring/query"
10
)
11
12
// PaymentLink is a resource that can be shared with your customers
13
// and will redirect them to them the payment page where they can
14
// complete the payment.
15
//
16
// See: https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link
17
type PaymentLink struct {
18
	ID          string           `json:"id,omitempty"`
19
	Resource    string           `json:"resource,omitempty"`
20
	Description string           `json:"description,omitempty"`
21
	ProfileID   string           `json:"profileId,omitempty"`
22
	RedirectURL string           `json:"redirectUrl,omitempty"`
23
	WebhookURL  string           `json:"webhookUrl,omitempty"`
24
	Mode        Mode             `json:"mode,omitempty"`
25
	Amount      Amount           `json:"amount,omitempty"`
26
	CreatedAt   *time.Time       `json:"createdAt,omitempty"`
27
	PaidAt      *time.Time       `json:"paidAt,omitempty"`
28
	UpdatedAt   *time.Time       `json:"updatedAt,omitempty"`
29
	ExpiresAt   *time.Time       `json:"expiresAt,omitempty"`
30
	Links       PaymentLinkLinks `json:"_links,omitempty"`
31
}
32
33
// PaymentLinkLinks describes all the possible links returned with
34
// a payment link struct.
35
//
36
// See: https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link
37
type PaymentLinkLinks struct {
38
	Self          *URL `json:"self,omitempty`
39
	Documentation *URL `json:"documentation,omitempty"`
40
	PaymentLink   *URL `json:"paymentLink,omitempty"`
41
	Next          *URL `json:"next,omitempty"`
42
	Previous      *URL `json:"previous,omitempty"`
43
}
44
45
// PaymentLinkOptions represents query string parameters to modify
46
// the payment links requests.
47
type PaymentLinkOptions struct {
48
	ProfileID string `url:"profileId,omitempty"`
49
	From      string `url:"from,omitemtpy"`
50
	Limit     int    `url:"limit,omitempty"`
51
}
52
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
// PaymentLinksService operates over the payment link resource.
62
type PaymentLinksService service
63
64
// Get retrieves a single payment link object by its id/token.
65
//
66
// See: https://docs.mollie.com/reference/v2/payment-links-api/get-payment-link
67
func (pls *PaymentLinksService) Get(id string) (pl *PaymentLink, err error) {
68 1
	req, err := pls.client.NewAPIRequest(http.MethodGet, fmt.Sprintf("v2/payment-links/%s", id), nil)
69 1
	if err != nil {
70
		return
71
	}
72
73 1
	res, err := pls.client.Do(req)
74 1
	if err != nil {
75
		return
76
	}
77 1
	if err = json.Unmarshal(res.content, &pl); err != nil {
78
		return
79
	}
80 1
	return
81
}
82
83
// Create generates payment links that by default, unlike regular payments, do not expire.
84
//
85
// See: https://docs.mollie.com/reference/v2/payment-links-api/create-payment-link
86
func (pls *PaymentLinksService) Create(p PaymentLink, opts *PaymentLinkOptions) (np *PaymentLink, err error) {
87 1
	u := "v2/payment-links"
88 1
	if opts != nil {
89
		v, _ := query.Values(opts)
90
		u = fmt.Sprintf("%s?%s", u, v.Encode())
91
	}
92 1
	req, err := pls.client.NewAPIRequest(http.MethodPost, u, p)
93 1
	if err != nil {
94
		return
95
	}
96
97 1
	res, err := pls.client.Do(req)
98 1
	if err != nil {
99
		return
100
	}
101 1
	if err = json.Unmarshal(res.content, &np); err != nil {
102
		return
103
	}
104 1
	return
105
}
106
107
// List retrieves all payments links created with the current website profile,
108
// ordered from newest to oldest.
109
//
110
// See: https://docs.mollie.com/reference/v2/payment-links-api/list-payment-links
111
func (pls *PaymentLinksService) List(opts *PaymentLinkOptions) (pl *PaymentLinksList, err error) {
112 1
	u := "v2/payment-links"
113 1
	if opts != nil {
114
		v, _ := query.Values(opts)
115
		u = fmt.Sprintf("%s?%s", u, v.Encode())
116
	}
117 1
	req, err := pls.client.NewAPIRequest(http.MethodGet, u, nil)
118 1
	if err != nil {
119
		return
120
	}
121
122 1
	res, err := pls.client.Do(req)
123 1
	if err != nil {
124
		return
125
	}
126 1
	if err = json.Unmarshal(res.content, &pl); err != nil {
127
		return
128
	}
129 1
	return
130
}
131