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 ( 62d1d3...ebeb07 )
by
unknown
01:33
created

mollie.*SalesInvoicesService.Delete   A

Complexity

Conditions 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 2
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
package mollie
2
3
import (
4
	"context"
5
	"encoding/json"
6
	"fmt"
7
	"time"
8
)
9
10
// SalesInvoiceStatus represents the status for the invoice to end up in.
11
type SalesInvoiceStatus string
12
13
// Possible values for SalesInvoiceStatus.
14
const (
15
	// DraftSalesInvoiceStatus indicates that the invoice is not paid or not sent and can be updated after creation.
16
	DraftSalesInvoiceStatus SalesInvoiceStatus = "draft"
17
	// IssuedSalesInvoiceStatus sends it to the recipient so they may then pay through our payment system.
18
	IssuedSalesInvoiceStatus SalesInvoiceStatus = "issued"
19
	// PaidSalesInvoiceStatus marks the invoice as paid.
20
	PaidSalesInvoiceStatus SalesInvoiceStatus = "paid"
21
)
22
23
// SalesInvoiceSource is the way through which the invoice is to be set to paid.
24
type SalesInvoiceSource string
25
26
// Possible values for SalesInvoiceSource.
27
const (
28
	ManualSalesInvoiceSource      SalesInvoiceSource = "manual"
29
	PaymentLinkSalesInvoiceSource SalesInvoiceSource = "payment_link"
30
	PaymentSalesInvoiceSource     SalesInvoiceSource = "payment"
31
)
32
33
// SalesInvoiceVATScheme represents the VAT scheme for the sales invoice.
34
type SalesInvoiceVATScheme string
35
36
// Possible values for SalesInvoiceVATScheme.
37
const (
38
	StandardSalesInvoiceVATScheme SalesInvoiceVATScheme = "standard"
39
	// OneStopShopSalesInvoiceVATScheme indicates that the One Stop Shop (OSS) VAT scheme is used.
40
	// You must be enrolled with One Stop Shop enabled to use it.
41
	OneStopShopSalesInvoiceVATScheme SalesInvoiceVATScheme = "one-stop-shop"
42
)
43
44
// SalesInvoiceVATMode represents the VAT mode for the sales invoice.
45
type SalesInvoiceVATMode string
46
47
// Possible values for SalesInvoiceVATMode.
48
const (
49
	// VAT is added on top of the prices.
50
	ExclusiveSalesInvoiceVATMode SalesInvoiceVATMode = "exclusive"
51
	// VAT is included in the prices.
52
	InclusiveSalesInvoiceVATMode SalesInvoiceVATMode = "inclusive"
53
)
54
55
// SalesInvoicePaymentTerm represents the payment term for the sales invoice.
56
// Defaults to 30 days.
57
type SalesInvoicePaymentTerm string
58
59
// Possible values for SalesInvoicePaymentTerm.
60
const (
61
	PaymentTerm7Days  SalesInvoicePaymentTerm = "7 days"
62
	PaymentTerm14Days SalesInvoicePaymentTerm = "14 days"
63
	PaymentTerm30Days SalesInvoicePaymentTerm = "30 days"
64
	PaymentTerm45Days SalesInvoicePaymentTerm = "45 days"
65
	PaymentTerm60Days SalesInvoicePaymentTerm = "60 days"
66
	PaymentTerm90Days SalesInvoicePaymentTerm = "90 days"
67
)
68
69
// SalesInvoiceRecipientType represents the type of recipient for the sales invoice.
70
type SalesInvoiceRecipientType string
71
72
// Possible values for SalesInvoiceRecipientType.
73
const (
74
	ConsumerSalesInvoiceRecipientType SalesInvoiceRecipientType = "consumer"
75
	BusinessSalesInvoiceRecipientType SalesInvoiceRecipientType = "business"
76
)
77
78
// SalesInvoiceDiscountType represents the type of discount applied to the sales invoice.
79
type SalesInvoiceDiscountType string
80
81
// Possible values for SalesInvoiceDiscountType.
82
const (
83
	FixedAmountSalesInvoiceDiscountType SalesInvoiceDiscountType = "amount"
84
	PercentageSalesInvoiceDiscountType  SalesInvoiceDiscountType = "percentage"
85
)
86
87
// SalesInvoiceDiscount represents the discount to be applied to the line item.
88
type SalesInvoiceDiscount struct {
89
	Type  SalesInvoiceDiscountType `json:"type,omitempty"`
90
	Value string                   `json:"value,omitempty"`
91
}
92
93
// SalesInvoicePaymentDetails contains details about how the sales invoice was or will be paid.
94
type SalesInvoicePaymentDetails struct {
95
	SourceReference string             `json:"sourceReference,omitempty"`
96
	Source          SalesInvoiceSource `json:"source,omitempty"`
97
}
98
99
// SalesInvoiceEmailDetails contains details about the email sent with the sales invoice.
100
type SalesInvoiceEmailDetails struct {
101
	Subject string `json:"subject,omitempty"`
102
	Body    string `json:"body,omitempty"`
103
}
104
105
// SalesInvoiceRecipient represents the recipient of the sales invoice.
106
type SalesInvoiceRecipient struct {
107
	Address
108
	Type               SalesInvoiceRecipientType `json:"type,omitempty"`
109
	Title              string                    `json:"title,omitempty"`
110
	Email              string                    `json:"email,omitempty"`
111
	Phone              string                    `json:"phone,omitempty"`
112
	OrganizationName   string                    `json:"organizationName,omitempty"`
113
	OrganizationNumber string                    `json:"organizationNumber,omitempty"`
114
	VATNumber          string                    `json:"vatNumber,omitempty"`
115
	Locale             Locale                    `json:"locale,omitempty"`
116
}
117
118
// SalesInvoiceLineItem represents a line item on the sales invoice.
119
type SalesInvoiceLineItem struct {
120
	Description string                `json:"description"`
121
	Quantity    int                   `json:"quantity"`
122
	VATRate     string                `json:"vatRate"`
123
	UnitPrice   Amount                `json:"unitPrice"`
124
	Discount    *SalesInvoiceDiscount `json:"discount,omitempty"`
125
}
126
127
// SalesInvoiceLinks contains links related to the sales invoice.
128
type SalesInvoiceLinks struct {
129
	Self           *URL `json:"self,omitempty"`
130
	InvoicePayment *URL `json:"invoicePayment,omitempty"`
131
	PDF            *URL `json:"pdfLink,omitempty"`
132
	Documentation  *URL `json:"documentation,omitempty"`
133
	Next           *URL `json:"next,omitempty"`
134
	Previous       *URL `json:"previous,omitempty"`
135
}
136
137
// CreateSalesInvoice represents the payload to create a sales invoice.
138
type CreateSalesInvoice struct {
139
	TestMode            bool                       `json:"testmode,omitempty"`
140
	ProfileID           string                     `json:"profileId,omitempty"`
141
	CustomerID          string                     `json:"customerId,omitempty"`
142
	MandateID           string                     `json:"mandateId,omitempty"`
143
	RecipientIdentifier string                     `json:"recipientIdentifier,omitempty"`
144
	Memo                string                     `json:"memo,omitempty"`
145
	Metadata            map[string]string          `json:"metadata,omitempty"`
146
	Status              SalesInvoiceStatus         `json:"status,omitempty"`
147
	VATScheme           SalesInvoiceVATScheme      `json:"vatScheme,omitempty"`
148
	VATMode             SalesInvoiceVATMode        `json:"vatMode,omitempty"`
149
	PaymentTerm         SalesInvoicePaymentTerm    `json:"paymentTerm,omitempty"`
150
	PaymentDetails      SalesInvoicePaymentDetails `json:"paymentDetails,omitempty"`
151
	EmailDetails        SalesInvoiceEmailDetails   `json:"emailDetails,omitempty"`
152
	Recipient           SalesInvoiceRecipient      `json:"recipient,omitempty"`
153
	Lines               []SalesInvoiceLineItem     `json:"lines,omitempty"`
154
	Discount            *SalesInvoiceDiscount      `json:"discount,omitempty"`
155
}
156
157
// UpdateSalesInvoice represents the payload to update a sales invoice.
158
type UpdateSalesInvoice struct {
159
	TestMode            bool                     `json:"testmode,omitempty"`
160
	Memo                string                   `json:"memo,omitempty"`
161
	RecipientIdentifier string                   `json:"recipientIdentifier,omitempty"`
162
	Status              SalesInvoiceStatus       `json:"status,omitempty"`
163
	PaymentTerm         SalesInvoicePaymentTerm  `json:"paymentTerm,omitempty"`
164
	EmailDetails        SalesInvoiceEmailDetails `json:"emailDetails,omitempty"`
165
	Recipient           SalesInvoiceRecipient    `json:"recipient,omitempty"`
166
	Lines               []SalesInvoiceLineItem   `json:"lines,omitempty"`
167
	Discount            *SalesInvoiceDiscount    `json:"discount,omitempty"`
168
}
169
170
// SalesInvoice represents a sales invoice resource.
171
type SalesInvoice struct {
172
	Resource                 string                     `json:"resource,omitempty"`
173
	ID                       string                     `json:"id,omitempty"`
174
	ProfileID                string                     `json:"profileId,omitempty"`
175
	Currency                 string                     `json:"currency,omitempty"`
176
	InvoiceNumber            string                     `json:"invoiceNumber,omitempty"`
177
	Memo                     string                     `json:"memo,omitempty"`
178
	CustomerID               string                     `json:"customerId,omitempty"`
179
	MandateID                string                     `json:"mandateId,omitempty"`
180
	RecipientIdentifier      string                     `json:"recipientIdentifier,omitempty"`
181
	Metadata                 map[string]string          `json:"metadata,omitempty"`
182
	Mode                     Mode                       `json:"mode,omitempty"`
183
	AmountDue                Amount                     `json:"amountDue,omitempty"`
184
	SubtotalAmount           Amount                     `json:"subtotalAmount,omitempty"`
185
	TotalAmount              Amount                     `json:"totalAmount,omitempty"`
186
	TotalVATAmount           Amount                     `json:"totalVatAmount,omitempty"`
187
	DiscountedSubtotalAmount Amount                     `json:"discountedSubtotalAmount,omitempty"`
188
	Status                   SalesInvoiceStatus         `json:"status,omitempty"`
189
	VATScheme                SalesInvoiceVATScheme      `json:"vatScheme,omitempty"`
190
	VATMode                  SalesInvoiceVATMode        `json:"vatMode,omitempty"`
191
	PaymentTerm              SalesInvoicePaymentTerm    `json:"paymentTerm,omitempty"`
192
	PaymentDetails           SalesInvoicePaymentDetails `json:"paymentDetails,omitempty"`
193
	EmailDetails             SalesInvoiceEmailDetails   `json:"emailDetails,omitempty"`
194
	Recipient                SalesInvoiceRecipient      `json:"recipient,omitempty"`
195
	Links                    SalesInvoiceLinks          `json:"_links,omitempty"`
196
	Lines                    []SalesInvoiceLineItem     `json:"lines,omitempty"`
197
	Discount                 *SalesInvoiceDiscount      `json:"discount,omitempty"`
198
	CreatedAt                *time.Time                 `json:"createdAt,omitempty"`
199
	IssuedAt                 *time.Time                 `json:"issuedAt,omitempty"`
200
	PaidAt                   *time.Time                 `json:"paidAt,omitempty"`
201
	DueAt                    *time.Time                 `json:"dueAt,omitempty"`
202
}
203
204
// SalesInvoiceList represents a paginated list of sales invoices.
205
type SalesInvoiceList struct {
206
	Count    int `json:"count,omitempty"`
207
	Embedded struct {
208
		SalesInvoices []SalesInvoice `json:"sales_invoices,omitempty"`
209
	} `json:"_embedded,omitempty"`
210
	Links PaginationLinks `json:"_links,omitempty"`
211
}
212
213
// ListSalesInvoicesOptions specifies the optional parameters to the List method.
214
type ListSalesInvoicesOptions struct {
215
	From     string `url:"from,omitempty"`
216
	Limit    int    `url:"limit,omitempty"`
217
	TestMode bool   `url:"testmode,omitempty"`
218
}
219
220
// SalesInvoicesService handles API operations for sales invoices.
221
type SalesInvoicesService service
222
223
// List retrieves a list of sales invoices.
224
//
225
// See: https://docs.mollie.com/reference/list-sales-invoices
226
func (s *SalesInvoicesService) List(ctx context.Context, opts *ListSalesInvoicesOptions) (
227
	res *Response,
228
	sil *SalesInvoiceList,
229
	err error,
230
) {
231
	res, err = s.client.get(ctx, "/v2/sales-invoices", opts)
232
	if err != nil {
233
		return
234
	}
235
236
	if err = json.Unmarshal(res.content, &sil); err != nil {
237
		return
238
	}
239
240
	return
241
}
242
243
// Get retrieves a single sales invoice by its ID.
244
//
245
// See: https://docs.mollie.com/reference/get-sales-invoice
246
func (s *SalesInvoicesService) Get(ctx context.Context, salesInvoice string) (
247
	res *Response,
248
	si *SalesInvoice,
249
	err error,
250
) {
251
	u := fmt.Sprintf("/v2/sales-invoices/%s", salesInvoice)
252
253
	res, err = s.client.get(ctx, u, nil)
254
	if err != nil {
255
		return
256
	}
257
258
	if err = json.Unmarshal(res.content, &si); err != nil {
259
		return
260
	}
261
262
	return
263
}
264
265
// Create creates a new sales invoice.
266
//
267
// See: https://docs.mollie.com/reference/create-sales-invoice
268
func (s *SalesInvoicesService) Create(ctx context.Context, csi CreateSalesInvoice) (
269
	res *Response,
270
	si *SalesInvoice,
271
	err error,
272
) {
273
	if s.client.HasAccessToken() && s.client.config.testing {
274
		csi.TestMode = true
275
	}
276
277
	res, err = s.client.post(ctx, "/v2/sales-invoices", csi, nil)
278
	if err != nil {
279
		return
280
	}
281
282
	if err = json.Unmarshal(res.content, &si); err != nil {
283
		return
284
	}
285
286
	return
287
}
288
289
// Update updates an existing sales invoice.
290
//
291
// See: https://docs.mollie.com/reference/update-sales-invoice
292
func (s *SalesInvoicesService) Update(ctx context.Context, salesInvoice string, usi UpdateSalesInvoice) (
293
	res *Response,
294
	si *SalesInvoice,
295
	err error,
296
) {
297
	u := fmt.Sprintf("/v2/sales-invoices/%s", salesInvoice)
298
299
	if s.client.HasAccessToken() && s.client.config.testing {
300
		usi.TestMode = true
301
	}
302
303
	res, err = s.client.patch(ctx, u, usi)
304
	if err != nil {
305
		return
306
	}
307
308
	if err = json.Unmarshal(res.content, &si); err != nil {
309
		return
310
	}
311
312
	return
313
}
314
315
// Delete deletes a sales invoice by its ID.
316
//
317
// See: https://docs.mollie.com/reference/delete-sales-invoice
318
func (s *SalesInvoicesService) Delete(ctx context.Context, salesInvoice string) (res *Response, err error) {
319
	u := fmt.Sprintf("/v2/sales-invoices/%s", salesInvoice)
320
321
	res, err = s.client.delete(ctx, u)
322
	if err != nil {
323
		return
324
	}
325
326
	return
327
}
328