Skip to content

Commit 03f4ee9

Browse files
committed
invoice service updated
1 parent f7fb570 commit 03f4ee9

File tree

10 files changed

+303
-9
lines changed

10 files changed

+303
-9
lines changed

src/main/java/com/fiscalapi/Main.java

Lines changed: 100 additions & 0 deletions
Large diffs are not rendered by default.

src/main/java/com/fiscalapi/abstractions/IFiscalApiHttpClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ public interface IFiscalApiHttpClient {
88
<T> ApiResponse<T> get(String url, Class<T> responseType);
99
<T> ApiResponse<T> post(String url, Object body, Class<T> responseType);
1010
<T> ApiResponse<T> put(String url, Object body, Class<T> responseType);
11+
<T> ApiResponse<T> delete(String url, Object body, Class<T> responseType);
1112
ApiResponse<Boolean> delete(String url);
13+
1214
}
Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
package com.fiscalapi.abstractions;
22

33
import com.fiscalapi.common.ApiResponse;
4-
import com.fiscalapi.models.invoicing.Invoice;
4+
import com.fiscalapi.models.invoicing.*;
55

66
public interface IInvoiceService extends IFiscalApiService<Invoice> {
77
// Podríamos añadir métodos específicos
8-
ApiResponse<Invoice> cancelInvoice(String invoiceId);
8+
9+
//Cancelar una factura, por referencias o por valores.
10+
ApiResponse<InvoiceCancellationResponse> cancel(InvoiceCancellationRequest request);
11+
12+
// Consultar la situación (status) de una factura.
13+
ApiResponse<InvoiceStatusResponse> status(InvoiceStatusRequest request);
14+
15+
16+
// Generar PDF de una factura por valores o por referencias.
17+
ApiResponse<PdfResponse> getPdf(PdfRequest request);
18+
19+
20+
// Envío de facturas por correo
21+
22+
ApiResponse<Boolean> send (InvoiceEmailRequest request);
23+
24+
925
// etc.
1026
}

src/main/java/com/fiscalapi/http/FiscalApiHttpClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public <T> ApiResponse<T> put(String url, Object body, Class<T> responseType) {
6060
return execute(request, responseType);
6161
}
6262

63+
64+
6365
@Override
6466
public ApiResponse<Boolean> delete(String url) {
6567
Request request = new Request.Builder()
@@ -69,6 +71,17 @@ public ApiResponse<Boolean> delete(String url) {
6971
return execute(request, Boolean.class);
7072
}
7173

74+
@Override
75+
public <T> ApiResponse<T> delete(String url, Object body, Class<T> responseType) {
76+
RequestBody requestBody = createRequestBody(body);
77+
Request request = new Request.Builder()
78+
.url(url)
79+
.delete(requestBody)
80+
.build();
81+
return execute(request, responseType);
82+
}
83+
84+
7285
// Método auxiliar para serializar el body de la solicitud
7386
private RequestBody createRequestBody(Object body) {
7487
try {

src/main/java/com/fiscalapi/models/invoicing/FileResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.fiscalapi.models.invoicing;
22

33
/**
4-
* Modelo de respuesta para generación de PDF o recuperación de XML
4+
* Modelo de respuesta de archivos en la api.
55
*/
66
public class FileResponse {
77
private String base64File;
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
/**
4+
* Modelo de envío de facturas por correo
5+
*
6+
* Este modelo se utiliza para enviar una factura por correo electrónico.
7+
* Contiene la información necesaria para el envío.
8+
*
9+
* Se puede enviar la factura (XML y PDF) por valores o por referencias:
10+
* - Por referencias: Solo se requieren los campos 'invoiceId' y 'toEmail', se aplicarán las reglas de reporte
11+
* - Por valores: Se deben pasar todos los campos para personalizar el PDF
12+
*/
13+
public class InvoiceEmailRequest {
14+
15+
/**
16+
* ID de la factura para la cual se generará el PDF.
17+
* Campo requerido.
18+
*/
19+
private String invoiceId;
20+
21+
/**
22+
* Correo electrónico del destinatario.
23+
* Campo requerido.
24+
*/
25+
private String toEmail;
26+
27+
/**
28+
* Color de la banda del PDF en formato hexadecimal.
29+
* Por ejemplo: "#FFA500".
30+
* Campo opcional.
31+
*/
32+
private String bandColor;
33+
34+
/**
35+
* Color de la fuente del texto sobre la banda en formato hexadecimal.
36+
* Por ejemplo: "#FFFFFF".
37+
* Campo opcional.
38+
*/
39+
private String fontColor;
40+
41+
/**
42+
* Logotipo en formato base64 que se mostrará en el PDF.
43+
* Campo opcional.
44+
*/
45+
private String base64Logo;
46+
47+
// Constructores
48+
49+
/**
50+
* Constructor por defecto
51+
*/
52+
public InvoiceEmailRequest() {
53+
}
54+
55+
/**
56+
* Constructor para envío por referencias
57+
*
58+
* @param invoiceId ID de la factura
59+
* @param toEmail Correo electrónico del destinatario
60+
*/
61+
public InvoiceEmailRequest(String invoiceId, String toEmail) {
62+
this.invoiceId = invoiceId;
63+
this.toEmail = toEmail;
64+
}
65+
66+
/**
67+
* Constructor completo para envío por valores
68+
*
69+
* @param invoiceId ID de la factura
70+
* @param toEmail Correo electrónico del destinatario
71+
* @param bandColor Color de la banda del PDF
72+
* @param fontColor Color de la fuente sobre la banda
73+
* @param base64Logo Logotipo en formato base64
74+
*/
75+
public InvoiceEmailRequest(String invoiceId, String toEmail, String bandColor, String fontColor, String base64Logo) {
76+
this.invoiceId = invoiceId;
77+
this.toEmail = toEmail;
78+
this.bandColor = bandColor;
79+
this.fontColor = fontColor;
80+
this.base64Logo = base64Logo;
81+
}
82+
83+
// Getters y Setters
84+
85+
public String getInvoiceId() {
86+
return invoiceId;
87+
}
88+
89+
public void setInvoiceId(String invoiceId) {
90+
this.invoiceId = invoiceId;
91+
}
92+
93+
public String getToEmail() {
94+
return toEmail;
95+
}
96+
97+
public void setToEmail(String toEmail) {
98+
this.toEmail = toEmail;
99+
}
100+
101+
public String getBandColor() {
102+
return bandColor;
103+
}
104+
105+
public void setBandColor(String bandColor) {
106+
this.bandColor = bandColor;
107+
}
108+
109+
public String getFontColor() {
110+
return fontColor;
111+
}
112+
113+
public void setFontColor(String fontColor) {
114+
this.fontColor = fontColor;
115+
}
116+
117+
public String getBase64Logo() {
118+
return base64Logo;
119+
}
120+
121+
public void setBase64Logo(String base64Logo) {
122+
this.base64Logo = base64Logo;
123+
}
124+
}

src/main/java/com/fiscalapi/models/invoicing/PdfGenerationRequest.java renamed to src/main/java/com/fiscalapi/models/invoicing/PdfRequest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* Modelo para la generación de PDF
55
*/
6-
public class PdfGenerationRequest {
6+
public class PdfRequest {
77
private String invoiceId;
88
private String bandColor;
99
private String fontColor;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
/**
4+
* Modelo de respuesta para generación de PDF
5+
*/
6+
public class PdfResponse extends FileResponse{
7+
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.fiscalapi.models.invoicing;
2+
3+
4+
/**
5+
* Modelo de respuesta para recuperación de XML de facturas.
6+
*/
7+
public class XmlResponse extends FileResponse{
8+
9+
}

src/main/java/com/fiscalapi/services/InvoiceService.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.fiscalapi.abstractions.IInvoiceService;
66
import com.fiscalapi.common.ApiResponse;
77
import com.fiscalapi.common.FiscalApiSettings;
8-
import com.fiscalapi.models.invoicing.Invoice;
8+
import com.fiscalapi.models.invoicing.*;
99

1010
public class InvoiceService extends BaseFiscalApiService<Invoice> implements IInvoiceService {
1111

@@ -19,10 +19,32 @@ protected Class<Invoice> getTypeParameterClass() {
1919
}
2020

2121
@Override
22-
public ApiResponse<Invoice> cancelInvoice(String invoiceId) {
23-
String endpoint = buildEndpoint(invoiceId + "/cancel", null);
24-
// Supongamos que el body es vacío:
25-
return httpClient.post(endpoint, null, Invoice.class);
22+
public ApiResponse<InvoiceCancellationResponse> cancel(InvoiceCancellationRequest requestModel) {
23+
24+
String endpoint = buildEndpoint("", null);
25+
return httpClient.delete(endpoint, requestModel, InvoiceCancellationResponse.class);
26+
}
27+
28+
@Override
29+
public ApiResponse<InvoiceStatusResponse> status(InvoiceStatusRequest request) {
30+
31+
String endpoint = buildEndpoint("status", null);
32+
33+
return httpClient.post(endpoint, request, InvoiceStatusResponse.class);
34+
}
35+
36+
@Override
37+
public ApiResponse<PdfResponse> getPdf(PdfRequest request) {
38+
39+
String endpoint = buildEndpoint("pdf", null);
40+
41+
return httpClient.post(endpoint, request, PdfResponse.class);
42+
}
43+
44+
@Override
45+
public ApiResponse<Boolean> send(InvoiceEmailRequest request) {
46+
String endpoint = buildEndpoint("send", null);
47+
return httpClient.post(endpoint, request, Boolean.class);
2648
}
2749

2850

0 commit comments

Comments
 (0)