-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInvoicesResource.java
More file actions
302 lines (276 loc) · 9.23 KB
/
Copy pathInvoicesResource.java
File metadata and controls
302 lines (276 loc) · 9.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
package io.facturapi.resources;
import com.fasterxml.jackson.core.type.TypeReference;
import io.facturapi.http.FacturapiHttpClient;
import io.facturapi.models.GenericResponse;
import io.facturapi.models.Invoice;
import io.facturapi.models.SearchResult;
import java.io.InputStream;
import java.util.Map;
public class InvoicesResource extends BaseResource {
/**
* Invoice endpoints.
*
* @see <a href="https://docs.facturapi.io/api#tag/Invoices">API reference</a>
*/
public InvoicesResource(FacturapiHttpClient client) {
super(client);
}
/**
* Creates a new valid invoice (CFDI).
*
* @param body Invoice payload.
* @param params Optional query parameters.
* @return Created invoice.
* @see <a href="https://docs.facturapi.io/api#operation/createInvoice">API reference</a>
*/
public Invoice create(Map<String, Object> body, Map<String, ?> params) {
return post("/invoices", body, params, Invoice.class);
}
/**
* Gets a paginated list of invoices created by your organization.
*
* @param params Search and pagination parameters.
* @return Paginated invoice result.
* @see <a href="https://docs.facturapi.io/api#operation/listInvoices">API reference</a>
*/
public SearchResult<Invoice> list(Map<String, ?> params) {
return get("/invoices", params, new TypeReference<SearchResult<Invoice>>() {});
}
/**
* Gets a single invoice by id.
*
* @param id Invoice id.
* @return Invoice object.
* @see <a href="https://docs.facturapi.io/api#operation/getInvoice">API reference</a>
*/
public Invoice retrieve(String id) {
return get("/invoices/" + id, null, Invoice.class);
}
/**
* Cancels an invoice.
*
* @param id Invoice id.
* @param params Cancellation options.
* @return Canceled invoice.
* @see <a href="https://docs.facturapi.io/api#operation/cancelInvoice">API reference</a>
*/
public Invoice cancel(String id, Map<String, ?> params) {
return delete("/invoices/" + id, params, Invoice.class);
}
/**
* Sends the invoice to the customer's email.
*
* @param id Invoice id.
* @param options Email options.
* @return Operation response.
* @see <a href="https://docs.facturapi.io/api#operation/sendInvoiceByEmail">API reference</a>
*/
public GenericResponse sendByEmail(String id, Map<String, Object> options) {
return post("/invoices/" + id + "/email", options, null, GenericResponse.class);
}
/**
* Downloads an invoice PDF file.
*
* @param id Invoice id.
* @return PDF bytes.
* @see <a href="https://docs.facturapi.io/api#operation/downloadInvoice">API reference</a>
*/
public byte[] downloadPdf(String id) {
return client.getBytes("/invoices/" + id + "/pdf");
}
/**
* Opens a streaming invoice PDF download.
*
* @param id Invoice id.
* @return PDF stream. Caller owns closing it.
* @see <a href="https://docs.facturapi.io/api#operation/downloadInvoice">API reference</a>
*/
public InputStream downloadPdfStream(String id) {
return client.getStream("/invoices/" + id + "/pdf");
}
/**
* Downloads an invoice XML file.
*
* @param id Invoice id.
* @return XML bytes.
* @see <a href="https://docs.facturapi.io/api#operation/downloadInvoice">API reference</a>
*/
public byte[] downloadXml(String id) {
return client.getBytes("/invoices/" + id + "/xml");
}
/**
* Opens a streaming invoice XML download.
*
* @param id Invoice id.
* @return XML stream. Caller owns closing it.
* @see <a href="https://docs.facturapi.io/api#operation/downloadInvoice">API reference</a>
*/
public InputStream downloadXmlStream(String id) {
return client.getStream("/invoices/" + id + "/xml");
}
/**
* Downloads an invoice ZIP package with PDF and XML.
*
* @param id Invoice id.
* @return ZIP bytes.
* @see <a href="https://docs.facturapi.io/api#operation/downloadInvoice">API reference</a>
*/
public byte[] downloadZip(String id) {
return client.getBytes("/invoices/" + id + "/zip");
}
/**
* Opens a streaming invoice ZIP download.
*
* @param id Invoice id.
* @return ZIP stream. Caller owns closing it.
* @see <a href="https://docs.facturapi.io/api#operation/downloadInvoice">API reference</a>
*/
public InputStream downloadZipStream(String id) {
return client.getStream("/invoices/" + id + "/zip");
}
/**
* Creates a ZIP request or returns the existing request for the same criteria.
*
* @param data ZIP request criteria.
* @return ZIP request data.
* @see <a href="https://docs.facturapi.io/api#tag/Invoices">API reference</a>
*/
public Map<String, Object> createZipRequest(Map<String, Object> data) {
return post(
"/invoices/zip-requests",
data,
null,
new TypeReference<Map<String, Object>>() {}
);
}
/**
* Gets a paginated list of ZIP requests.
*
* @param params Search and pagination parameters.
* @return Paginated ZIP request result.
* @see <a href="https://docs.facturapi.io/api#tag/Invoices">API reference</a>
*/
public SearchResult<Map<String, Object>> listZipRequests(Map<String, ?> params) {
return get(
"/invoices/zip-requests",
params,
new TypeReference<SearchResult<Map<String, Object>>>() {}
);
}
/**
* Gets a ZIP request by id.
*
* @param id ZIP request id.
* @return ZIP request data.
* @see <a href="https://docs.facturapi.io/api#tag/Invoices">API reference</a>
*/
public Map<String, Object> retrieveZipRequest(String id) {
return get(
"/invoices/zip-requests/" + id,
null,
new TypeReference<Map<String, Object>>() {}
);
}
/**
* Downloads the ZIP generated for a request.
*
* @param id ZIP request id.
* @return ZIP stream. Caller owns closing it.
* @see <a href="https://docs.facturapi.io/api#tag/Invoices">API reference</a>
*/
public InputStream downloadZipRequestStream(String id) {
return client.getStream("/invoices/zip-requests/" + id + "/zip");
}
/**
* Downloads the cancellation receipt XML file.
*
* @param id Invoice id.
* @return XML bytes.
* @see <a href="https://docs.facturapi.io/api#operation/downloadCancellationReceiptXml">API reference</a>
*/
public byte[] downloadCancellationReceiptXml(String id) {
return client.getBytes("/invoices/" + id + "/cancellation_receipt/xml");
}
/**
* Opens a streaming cancellation receipt XML download.
*
* @param id Invoice id.
* @return XML stream. Caller owns closing it.
* @see <a href="https://docs.facturapi.io/api#operation/downloadCancellationReceiptXml">API reference</a>
*/
public InputStream downloadCancellationReceiptXmlStream(String id) {
return client.getStream("/invoices/" + id + "/cancellation_receipt/xml");
}
/**
* Downloads the cancellation receipt PDF file.
*
* @param id Invoice id.
* @return PDF bytes.
* @see <a href="https://docs.facturapi.io/api#operation/downloadCancellationReceiptXml">API reference</a>
*/
public byte[] downloadCancellationReceiptPdf(String id) {
return client.getBytes("/invoices/" + id + "/cancellation_receipt/pdf");
}
/**
* Opens a streaming cancellation receipt PDF download.
*
* @param id Invoice id.
* @return PDF stream. Caller owns closing it.
* @see <a href="https://docs.facturapi.io/api#operation/downloadCancellationReceiptXml">API reference</a>
*/
public InputStream downloadCancellationReceiptPdfStream(String id) {
return client.getStream("/invoices/" + id + "/cancellation_receipt/pdf");
}
/**
* Updates a draft invoice.
*
* @param id Invoice id.
* @param data Invoice updates.
* @return Updated draft invoice.
* @see <a href="https://docs.facturapi.io/api#operation/updateDraftInvoice">API reference</a>
*/
public Invoice updateDraft(String id, Map<String, Object> data) {
return put("/invoices/" + id, data, null, Invoice.class);
}
/**
* Stamps an existing draft invoice.
*
* @param id Invoice id.
* @param params Optional query parameters.
* @return Stamped invoice.
* @see <a href="https://docs.facturapi.io/api#operation/stampDraftInvoice">API reference</a>
*/
public Invoice stampDraft(String id, Map<String, ?> params) {
return post("/invoices/" + id + "/stamp", null, params, Invoice.class);
}
/**
* Refreshes invoice status from SAT.
*
* @param id Invoice id.
* @return Updated invoice.
* @see <a href="https://docs.facturapi.io/api#operation/updateInvoiceStatus">API reference</a>
*/
public Invoice updateStatus(String id) {
return put("/invoices/" + id + "/status", null, null, Invoice.class);
}
/**
* Creates a draft copy from an existing invoice.
*
* @param id Invoice id.
* @return Draft invoice.
* @see <a href="https://docs.facturapi.io/api#operation/copyToDraftInvoice">API reference</a>
*/
public Invoice copyToDraft(String id) {
return post("/invoices/" + id + "/copy", null, null, Invoice.class);
}
/**
* Generates a PDF preview for invoice payload before stamping.
*
* @param body Invoice payload.
* @return PDF bytes.
* @see <a href="https://docs.facturapi.io/api#operation/previewInvoicePdf">API reference</a>
*/
public byte[] previewPdf(Map<String, Object> body) {
return client.postBytes("/invoices/preview/pdf", body);
}
}