1
|
|
|
package mollie |
2
|
|
|
|
3
|
|
|
import ( |
4
|
|
|
"context" |
5
|
|
|
"encoding/json" |
6
|
|
|
"fmt" |
7
|
|
|
) |
8
|
|
|
|
9
|
|
|
// InvoiceStatus status of the invoice. |
10
|
|
|
type InvoiceStatus string |
11
|
|
|
|
12
|
|
|
// Valid status of the invoice. |
13
|
|
|
const ( |
14
|
|
|
InvoiceStatusOpen InvoiceStatus = "open" |
15
|
|
|
InvoiceStatusPaid InvoiceStatus = "paid" |
16
|
|
|
InvoiceStatusOverdue InvoiceStatus = "overdue" |
17
|
|
|
) |
18
|
|
|
|
19
|
|
|
// Invoice describes an invoice details. |
20
|
|
|
type Invoice struct { |
21
|
|
|
Resource string `json:"resource,omitempty"` |
22
|
|
|
ID string `json:"id,omitempty"` |
23
|
|
|
Reference string `json:"reference,omitempty"` |
24
|
|
|
VatNumber string `json:"vatNumber,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
|
|
|
Status InvoiceStatus `json:"status,omitempty"` |
33
|
|
|
Links InvoiceLinks `json:"_links,omitempty"` |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
// LineItem product details. |
37
|
|
|
type LineItem struct { |
38
|
|
|
Count int64 `json:"count,omitempty"` |
39
|
|
|
VatPercentage float64 `json:"vatPercentage,omitempty"` |
40
|
|
|
Period string `json:"period,omitempty"` |
41
|
|
|
Description string `json:"description,omitempty"` |
42
|
|
|
Amount *Amount `json:"amount,omitempty"` |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// InvoiceLinks describes all the possible links to be returned with |
46
|
|
|
// a invoice object. |
47
|
|
|
type InvoiceLinks struct { |
48
|
|
|
Self *URL `json:"self,omitempty"` |
49
|
|
|
PDF *URL `json:"pdf,omitempty"` |
50
|
|
|
Documentation *URL `json:"documentation,omitempty"` |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
// ListInvoicesOptions describes list invoices endpoint valid query string parameters. |
54
|
|
|
type ListInvoicesOptions struct { |
55
|
|
|
Limit int64 `url:"limit,omitempty"` |
56
|
|
|
Reference string `url:"reference,omitempty"` |
57
|
|
|
Year string `url:"year,omitempty"` |
58
|
|
|
From string `url:"from,omitempty"` |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
// InvoicesList describes how a list of invoices will be retrieved by Mollie. |
62
|
|
|
type InvoicesList struct { |
63
|
|
|
Count int `json:"count,omitempty"` |
64
|
|
|
Embedded struct { |
65
|
|
|
Invoices []*Invoice `json:"invoices"` |
66
|
|
|
} `json:"_embedded,omitempty"` |
67
|
|
|
Links PaginationLinks `json:"_links,omitempty"` |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
// InvoicesService instance operates over invoice resources. |
71
|
|
|
type InvoicesService service |
72
|
|
|
|
73
|
|
|
// Get retrieve details of an invoice, using the invoice’s identifier. |
74
|
|
|
func (is *InvoicesService) Get(ctx context.Context, id string) (res *Response, i *Invoice, err error) { |
75
|
1 |
|
u := fmt.Sprintf("v2/invoices/%s", id) |
76
|
|
|
|
77
|
1 |
|
res, err = is.client.get(ctx, u, nil) |
78
|
1 |
|
if err != nil { |
79
|
1 |
|
return |
80
|
|
|
} |
81
|
|
|
|
82
|
1 |
|
if err = json.Unmarshal(res.content, &i); err != nil { |
83
|
1 |
|
return |
84
|
|
|
} |
85
|
|
|
|
86
|
1 |
|
return |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
// List retrieves a list of invoices associated with your account/organization. |
90
|
|
|
func (is *InvoicesService) List(ctx context.Context, options *ListInvoicesOptions) ( |
91
|
|
|
res *Response, |
92
|
|
|
il *InvoicesList, |
93
|
|
|
err error, |
94
|
|
|
) { |
95
|
1 |
|
res, err = is.client.get(ctx, "v2/invoices", options) |
96
|
1 |
|
if err != nil { |
97
|
1 |
|
return |
98
|
|
|
} |
99
|
|
|
|
100
|
1 |
|
if err = json.Unmarshal(res.content, &il); err != nil { |
101
|
1 |
|
return |
102
|
|
|
} |
103
|
|
|
|
104
|
1 |
|
return |
105
|
|
|
} |
106
|
|
|
|