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.
Completed
Pull Request — master (#29)
by
unknown
01:27
created

mollie/invoices.go   A

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Test Coverage

Coverage 73.91%

Importance

Changes 0
Metric Value
cc 9
eloc 71
dl 0
loc 108
ccs 17
cts 23
cp 0.7391
crap 10.4384
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A mollie.*InvoicesService.List 0 18 5
A mollie.*InvoicesService.Get 0 15 4
1
package mollie
2
3
import (
4
	"encoding/json"
5
	"fmt"
6
	"github.com/google/go-querystring/query"
7
	"net/http"
8
)
9
10
type InvoiceStatus string
11
12
const (
13
	InvoiceStatusOpen    InvoiceStatus = "open"
14
	InvoiceStatusPaid    InvoiceStatus = "paid"
15
	InvoiceStatusOverdue InvoiceStatus = "overdue"
16
)
17
18
// Invoice describes a invoice detail
19
type Invoice struct {
20
	Resource    string        `json:"resource,omitempty"`
21
	ID          string        `json:"id,omitempty"`
22
	Reference   string        `json:"reference,omitempty"`
23
	VatNumber   string        `json:"vatNumber,omitempty"`
24
	Status      InvoiceStatus `json:"status,omitempty"`
25
	IssuedAt    string        `json:"issuedAt,omitempty"`
26
	PaidAt      string        `json:"paidAt,omitempty"`
27
	DueAt       string        `json:"dueAt,omitempty"`
28
	NetAmount   Amount        `json:"netAmount,omitempty"`
29
	VatAmount   Amount        `json:"vatAmount,omitempty"`
30
	GrossAmount Amount        `json:"grossAmount,omitempty"`
31
	Lines       []*LineItem   `json:"lines,omitempty"`
32
	Links       *InvoiceLinks `json:"_links,omitempty"`
33
}
34
35
// LineItem product detail
36
type LineItem struct {
37
	Period        string  `json:"period,omitempty"`
38
	Description   string  `json:"description,omitempty"`
39
	Count         int64   `json:"count,omitempty"`
40
	VatPercentage float64 `json:"vatPercentage,omitempty"`
41
	Amount        Amount  `json:"amount,omitempty"`
42
}
43
44
// InvoiceLinks describes all the possible links to be returned with
45
// a invoice object.
46
type InvoiceLinks struct {
47
	Self          URL `json:"self,omitempty"`
48
	PDF           URL `json:"pdf,omitempty"`
49
	Documentation URL `json:"documentation,omitempty"`
50
}
51
52
// ListInvoiceOptions describes list invoices endpoint valid query string parameters.
53
type ListInvoiceOptions struct {
54
	Reference string `json:"reference,omitempty"`
55
	Year      string `json:"year,omitempty"`
56
	From      int64  `json:"from,omitempty"`
57
	Limit     int64  `json:"limit,omitempty"`
58
}
59
60
// InvoiceList describes how a list of invoices will be retrieved by Mollie.
61
type InvoiceList struct {
62
	Count    int `json:"count,omitempty"`
63
	Embedded struct {
64
		Invoices []Invoice `json:"invoices"`
65
	} `json:"_embedded,omitempty"`
66
	Links PaginationLinks `json:"_links,omitempty"`
67
}
68
69
// InvoicesService instance operates over invoice resources
70
type InvoicesService service
71
72
// Get retrieve details of an invoice, using the invoice’s identifier.
73
func (is *InvoicesService) Get(id string) (i Invoice, err error) {
74 1
	getURL := fmt.Sprintf("v2/invoices/%s", id)
75
76 1
	req, err := is.client.NewAPIRequest(http.MethodGet, getURL, nil)
77 1
	if err != nil {
78
		return
79
	}
80 1
	res, err := is.client.Do(req)
81 1
	if err != nil {
82
		return
83
	}
84 1
	if err = json.Unmarshal(res.content, &i); err != nil {
85
		return
86
	}
87 1
	return
88
}
89
90
// List retrieves a list of invoices associated with your account/organization.
91
func (is *InvoicesService) List(options *ListInvoiceOptions) (il InvoiceList, err error) {
92 1
	u := fmt.Sprint("v2/invoices")
93 1
	if options != nil {
94 1
		v, _ := query.Values(options)
95 1
		u = fmt.Sprintf("%s?%s", u, v.Encode())
96
	}
97 1
	req, err := is.client.NewAPIRequest(http.MethodGet, u, nil)
98 1
	if err != nil {
99
		return
100
	}
101 1
	res, err := is.client.Do(req)
102 1
	if err != nil {
103
		return
104
	}
105 1
	if err = json.Unmarshal(res.content, &il); err != nil {
106
		return
107
	}
108 1
	return
109
}
110