Skip to content

Commit 269de4c

Browse files
authored
Merge pull request #38 from lunasoft/feature/Validate
Feature/validate
2 parents fd357b3 + cc65a5b commit 269de4c

File tree

13 files changed

+494
-4
lines changed

13 files changed

+494
-4
lines changed

README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,72 @@ public class App {
662662
}
663663
```
664664

665+
# Validación #
666+
667+
## Validación XML ##
668+
Este servicio recibe un comprobante CFDI 3.3 ó 4.0 en formato XML mediante el cual se valida integridad, sello, errores de estructura, matriz de errores del SAT incluyendo complementos, se valida que exista en el SAT, así como el estatus en el SAT.
669+
670+
Este metodo recibe los siguientes parametros:
671+
- Url Servicios SW
672+
- Usuario y contraseña o token
673+
- XML
674+
675+
**Ejemplo de consumo de la libreria para validación de XML mediante usuario y contraseña**
676+
```java
677+
import java.nio.file.Files;
678+
import java.nio.file.Paths;
679+
import mx.com.sw.services.Validate.Validate;
680+
import mx.com.sw.services.Validate.responses.ValidateDetailData;
681+
import mx.com.sw.services.Validate.responses.ValidateNodeDetail;
682+
import mx.com.sw.services.Validate.responses.ValidateResponse;
683+
684+
public class App {
685+
public static void main(String[] args)
686+
{
687+
try
688+
{
689+
//Creamos una instancia de tipo Validate
690+
//A esta le pasamos la Url, Usuario y Contraseña para obtener el token
691+
Validate api = new Validate("http://services.test.sw.com.mx", "user","password", null, 0);
692+
693+
String xml = new String(Files.readAllBytes(Paths.get("pruebas.xml")), "UTF-8");
694+
//Realizamos la peticion de validacion pasando el XML
695+
ValidateResponse response = api.ValidateXML(xml);
696+
697+
//El objeto response tendra los siguientes atributos:
698+
System.out.println(response.getStatus());
699+
List<ValidateNodeDetail> List = response.getDetail();
700+
for(int i=0; i<List.size();i++){
701+
ValidateNodeDetail node = List.get(i);
702+
List<ValidateDetailData> ListData = node.getDetailData();
703+
for(int j=0; j<ListData.size();j++){
704+
ValidateDetailData data = ListData.get(j);
705+
System.out.println("\t\t"+data.getMessage());
706+
System.out.println("\t\t"+data.getMessageDetail());
707+
System.out.println("\t\t"+data.getType());
708+
}
709+
System.out.println("\t"+node.getSection());
710+
}
711+
System.out.println(response.getCadenaOriginalComprobante());
712+
System.out.println(response.getCadenaOriginalSAT());
713+
System.out.println(response.getUuid());
714+
System.out.println(response.getStatusSat());
715+
System.out.println(response.getStatusCodeSat());
716+
Assertions.assertTrue("Success".equalsIgnoreCase(response.getStatus()));
717+
718+
//En caso de error, se pueden visualizar los campos message y/o messageDetail
719+
System.out.println("Error al validar xml");
720+
System.out.println(res.getMessage());
721+
System.out.println(res.getMessageDetail());
722+
}
723+
catch (Exception e)
724+
{
725+
System.out.println(e);
726+
}
727+
}
728+
}
729+
```
730+
665731
# Consulta de Saldos #
666732
Este servicio recibe el token y genera los elementos que componen la consulta de saldos:
667733

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>mx.com.sw</groupId>
55
<artifactId>sdk-java18</artifactId>
6-
<version>0.0.5.1</version>
6+
<version>0.0.6.1</version>
77
<packaging>jar</packaging>
88
<properties>
99
<maven.compiler.source>1.8</maven.compiler.source>

resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"InformacionGlobal": {
2323
"Periodicidad": "01",
2424
"Meses": "01",
25-
"Año": "2021"
25+
"Año": "2023"
2626
},
2727
"Emisor": {
2828
"Rfc": "EKU9003173C9",

resources/CFDI40/CFDI40/CFDI40_Ingreso_Global.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<cfdi:Comprobante xsi:schemaLocation="http://www.sat.gob.mx/cfd/4 http://www.sat.gob.mx/sitio_internet/cfd/4/cfdv40.xsd" Version="4.0" Serie="Serie" Folio="2080427802" Fecha="2022-02-08T18:31:50" Sello="OyIrd0DMQab62A3uAHYCSRqs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XaFg7DGBrXWC8iyqeWE2iobdwIIuXPTMVqQb12m1dAkJVRO5NdHnP/MpqOvOgLqoZBNHGyBg4Gqm4sCJHCxA1c8Elfa2RQTCk0tAzllL4vOnI1GHkGJn65xokGsaU4B4D36xh7eWrfj4/pgWHmtoDAYa8wzSwo2GVCZOs+mtEgOQB91/g==" CondicionesDePago="CondicionesDePago" SubTotal="200" Moneda="MXN" TipoCambio="1" Total="180" TipoDeComprobante="I" Exportacion="01" MetodoPago="PUE" LugarExpedicion="20000"
33
xmlns:cfdi="http://www.sat.gob.mx/cfd/4"
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5-
<cfdi:InformacionGlobal Periodicidad="01" Meses="01" Año="2021" />
5+
<cfdi:InformacionGlobal Periodicidad="01" Meses="01" Año="2023" />
66
<cfdi:Emisor Rfc="EKU9003173C9" Nombre="ESCUELA KEMPER URGATE" RegimenFiscal="601" />
77
<cfdi:Receptor Rfc="XAXX010101000" Nombre="PUBLICO EN GENERAL" DomicilioFiscalReceptor="20000" RegimenFiscalReceptor="616" UsoCFDI="S01" />
88
<cfdi:Conceptos>

resources/pdfresult.pdf

4.25 KB
Binary file not shown.

src/main/java/mx/com/sw/helpers/ResponseHelper.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.PrintWriter;
44
import java.io.StringWriter;
5+
6+
import mx.com.sw.services.Validate.responses.ValidateResponse;
57
import mx.com.sw.services.acceptreject.responses.AcceptRejectResponse;
68
import mx.com.sw.services.account.balance.responses.AccountBalanceResponse;
79
import mx.com.sw.services.account.info.responses.AccountInfoResponse;
@@ -168,7 +170,15 @@ public static StorageResponse toStorageResponse(Throwable ex) {
168170
* @param ex Throwable a ser tratado
169171
* @return {@link ResendResponse}
170172
*/
171-
public static ResendResponse toResendResponse(Throwable ex) {
173+
public static ResendResponse toResendResponse(Throwable ex) {
172174
return new ResendResponse(STATUS_ERROR, ex.getMessage(), getStackError(ex), null);
173175
}
176+
/**
177+
* Este método obtiene una respuesta de tipo ValidateResponse.
178+
* @param ex Throwable a ser tratado
179+
* @return {@link PdfResponse}
180+
*/
181+
public static ValidateResponse toValidateResponse(Throwable ex) {
182+
return new ValidateResponse(STATUS_ERROR, ex.getMessage(), getStackError(ex), null,null,null,null,null,null);
183+
}
174184
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package mx.com.sw.services.Validate;
2+
import java.util.Map;
3+
import java.util.UUID;
4+
import org.apache.http.client.config.RequestConfig;
5+
import mx.com.sw.exceptions.ServicesException;
6+
import mx.com.sw.helpers.GeneralHelpers;
7+
import mx.com.sw.services.Validate.responses.ValidateResponse;
8+
import mx.com.sw.services.Validate.responses.ValidateResponseHandler;
9+
10+
public class Validate extends ValidateService{
11+
private ValidateResponseHandler handler;
12+
13+
/**
14+
* Constructor de la clase.
15+
* @param url url base de la API
16+
* @param user correo o usuario de SW
17+
* @param password password de SW.
18+
* @param proxy ip o dominio de proxy (null si no se utiliza)
19+
* @param proxyPort número de puerto de proxy (cualquier valor si proxy es null)
20+
* @throws ServicesException exception en caso de error.
21+
*/
22+
public Validate(String url, String user, String password, String proxy,
23+
int proxyPort) throws ServicesException {
24+
super(url, user, password, proxy, proxyPort);
25+
handler = new ValidateResponseHandler();
26+
}
27+
28+
/** Constructor de la clase.
29+
* @param url url base de la API
30+
* @param token token infinito de SW.
31+
* @param proxy ip o dominio de proxy (null si no se utiliza)
32+
* @param proxyPort número de puerto de proxy (cualquier valor si proxy es null)
33+
* @throws ServicesException exception en caso de error.
34+
*/
35+
public Validate(String url, String token, String proxy, int proxyPort) throws ServicesException {
36+
super(url, token, proxy, proxyPort);
37+
handler = new ValidateResponseHandler();
38+
}
39+
40+
/**
41+
* Método de validacion enviando un XML.
42+
* @param xmlcontent String xml.
43+
* @return ValidateResponse
44+
*/
45+
public ValidateResponse ValidateXML(String xmlcontent){
46+
try {
47+
Map<String, String> headers = getHeaders();
48+
String boundary = UUID.randomUUID().toString();
49+
String xml = String.format(
50+
"--%s\r\nContent-Disposition: form-data; name=xml;"
51+
+ "filename=xml\r\nContent-Type: application/xml\r\n\r\n%s\r\n--%s--",
52+
boundary, xmlcontent, boundary);
53+
headers.put("Content-Type", "multipart/form-data; boundary=" + boundary);
54+
RequestConfig config = GeneralHelpers.setProxyAndTimeOut(getProxy(), getProxyPort());
55+
return handler.postHTTPMultipart(getUrl(), "validate/cfdi", headers, xml, config,
56+
ValidateResponse.class);
57+
} catch (ServicesException e) {
58+
return handler.handleException(e);
59+
}
60+
}
61+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package mx.com.sw.services.Validate;
2+
import java.util.HashMap;
3+
import java.util.Map;
4+
import mx.com.sw.exceptions.ServicesException;
5+
import mx.com.sw.services.Services;
6+
import mx.com.sw.services.Validate.responses.ValidateResponse;
7+
8+
/**
9+
* ValidateService, servicio de validacion de XML.
10+
*/
11+
public abstract class ValidateService extends Services{
12+
13+
/**
14+
* Constructor de la clase.
15+
* @param url url base de la API
16+
* @param user correo o usuario de SW
17+
* @param password password de SW.
18+
* @param proxy ip o dominio de proxy (null si no se utiliza)
19+
* @param proxyPort número de puerto de proxy (cualquier valor si proxy es null)
20+
* @throws ServicesException exception en caso de error.
21+
*/
22+
protected ValidateService(String url, String user, String password, String proxy,
23+
int proxyPort) throws ServicesException {
24+
super(url, user, password, proxy, proxyPort);
25+
}
26+
27+
/**
28+
* Constructor de la clase.
29+
* @param url url base de la API
30+
* @param token token infinito de SW.
31+
* @param proxy ip o dominio de proxy (null si no se utiliza)
32+
* @param proxyPort número de puerto de proxy (cualquier valor si proxy es null)
33+
* @throws ServicesException exception en caso de error.
34+
*/
35+
protected ValidateService(String url, String token, String proxy, int proxyPort) throws ServicesException {
36+
super(url, token, proxy, proxyPort);
37+
}
38+
39+
/**
40+
* Obtiene los headers minímos para su funcionamiento.
41+
* @return Map String, String
42+
* @throws ServicesException exception en caso de error.
43+
*/
44+
protected Map<String, String> getHeaders() throws ServicesException {
45+
super.setupRequest();
46+
Map<String, String> headers = new HashMap<String, String>();
47+
headers.put("Authorization", "bearer " + this.getToken());
48+
return headers;
49+
}
50+
51+
abstract ValidateResponse ValidateXML(String xmlcontent);
52+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package mx.com.sw.services.Validate.responses;
2+
3+
/**
4+
* ValidateDetailData Clase con la informacion detallada de cada nodo.
5+
*/
6+
public class ValidateDetailData {
7+
private String message;
8+
private String messageDetail;
9+
private String type;
10+
11+
/**
12+
* Retorna message de la seccion
13+
* @return String
14+
*/
15+
public String getMessage(){
16+
return message;
17+
}
18+
public void setMessage(String message){
19+
this.message = message;
20+
}
21+
22+
/**
23+
* Retorna messageDetail detallado de la seccion
24+
* @return String
25+
*/
26+
public String getMessageDetail(){
27+
return messageDetail;
28+
}
29+
public void setMessageDetail(String messageDetail){
30+
this.messageDetail = messageDetail;
31+
}
32+
33+
/**
34+
* Retorna type de la seccion
35+
* @return String
36+
*/
37+
public String getType(){
38+
return type;
39+
}
40+
public void setType(String type){
41+
this.type = type;
42+
}
43+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package mx.com.sw.services.Validate.responses;
2+
import java.util.List;
3+
4+
/**
5+
* ValidateNodeDetail Clase con la informacion de los nodos de la validacion.
6+
*/
7+
public class ValidateNodeDetail {
8+
private String section;
9+
private List<ValidateDetailData> detail;
10+
11+
/**
12+
* Retorna la seccion
13+
* @return String
14+
*/
15+
public String getSection(){
16+
return section;
17+
}
18+
public void setSection(String section){
19+
this.section = section;
20+
}
21+
22+
/**
23+
* Retorna datos detallados de cada seccion
24+
* @return objeto tipo ValidateDetailData
25+
*/
26+
public List<ValidateDetailData> getDetailData(){
27+
return detail;
28+
}
29+
public void setDetailData(List<ValidateDetailData> detail){
30+
this.detail = detail;
31+
}
32+
}

0 commit comments

Comments
 (0)