Skip to content

Commit

Permalink
Se arreglo el ejemplo
Browse files Browse the repository at this point in the history
  • Loading branch information
Jesus Urias committed Mar 30, 2017
1 parent fc5f511 commit 588a5b4
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 56 deletions.
Binary file modified .DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 31 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,25 @@ Para hacer una petición de timbrado de un CFDI, deberá enviar las credenciales

En el proyecto existe una clase Timbrado.java, la cual facilita la creacion de timbrado, solo es necesario agragarla al proyecto y crear un objeto.
```
//Timbrar Factura
// Parametros generales para el sevicio
String usuario = "AAA010101000";
String contrasena = "h6584D56fVdBbSmmnB";
//
// Timbrar Factura
//
// Parametros para el servicio
String usuarioTimbrado = "usuario_prueba";
String contrasenaTimbrado = "contrasena_prueba";
String documentoTimbrado = "xml";
byte[] archivoXml = Files.readAllBytes(Paths.get("archivoXml.xml"));
String xmlBase64 = Base64.getEncoder().encodeToString(archivoXml);
try {
// Creación del objeto Timbrado
Timbrado timbrado = new Timbrado(usuarioTimbrado, contrasenaTimbrado, documentoTimbrado);
//Ejecución del servicio
SOAPMessage soapResponse = timbrado.Timbrar();
// Creacion del objeto Timbrado
Timbrado timbrado = new Timbrado(usuario, contrasena, xmlBase64);
//Ejecucion del servicio
String facturaTimbrada = timbrado.Timbrar();
// Imprime la respuesta
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
System.out.println("Comprobante timbrado: \n");
System.out.print(facturaTimbrada);
} catch (Exception exception) {
throw exception;
}
Expand All @@ -49,26 +54,27 @@ Para la cancelación son necesarias las credenciales asignadas, RFC del emisor,

En el proyecto existe una clase Cancelacion.java, la cual facilita la creacion de timbrado, solo es necesario agragarla al proyecto y crear un objeto.
```
// Parametros generales para el sevicio
String usuario = "AAA010101000";
String contrasena = "h6584D56fVdBbSmmnB";
//Cancelar Factura
// Parametros para el servicio
String usuarioCancelacion = "usuario_prueba";
String contrasenaCancelacion = "contrasena_prueba";
String rfcEmisorCancelacion = "RFCPRUEBA";
String[] uuidsCancelacion = { "UUID1", "UUID2", "UUID3" };
String pfxCancelacion = "valor_PFX";
String pfxContrasenaCancelacion = "contrasena_prueba";
// Conversión del PFX a base64
byte[] bytes = pfxCancelacion.getBytes(StandardCharsets.UTF_8);
String encodedPfxCancelacion = Base64.getEncoder().encodeToString(bytes);
String rfcEmisorCancelacion = "AAA010101AAA";
String[] uuidsCancelacion = { "E28DBCF2-F852-4B2F-8198-CD8383891EB0", "3CFF7200-0DE5-4BEE-AC22-AA2A49052FBC", "51408B33-FE29-47DA-9517-FBF420240FD3" };
byte[] pfx = Files.readAllBytes(Paths.get("archivoPfx.pfx"));
String pfxContrasena = "12345678a";
// Conversion del PFX a base64
String pfxBase64 = Base64.getEncoder().encodeToString(pfx);
try {
// Creación del objeto Cancelación
Cancelacion timbrado = new Cancelacion(usuarioCancelacion, contrasenaCancelacion, rfcEmisorCancelacion, uuidsCancelacion, encodedPfxCancelacion, pfxContrasenaCancelacion);
//Ejecución del servicio
SOAPMessage soapResponse = timbrado.Cancelar();
// Creacion del objeto Cancelacion
Cancelacion timbrado = new Cancelacion(usuario, contrasena, rfcEmisorCancelacion, uuidsCancelacion, pfxBase64, pfxContrasena);
//Ejecucion del servicio
String facturaCancelada = timbrado.Cancelar();
// Imprime la respuesta
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
System.out.println("Comprabantes cancelados: \n");
System.out.println(facturaCancelada);
} catch (Exception exception) {
throw exception;
}
Expand Down
Binary file added archivoPfx.pfx
Binary file not shown.
15 changes: 15 additions & 0 deletions archivoXml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<cfdi:Comprobante xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" L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fvYftdGRNrZH+dAjWWml2S/hrN9aUxraS5qqO1b7btlAgMBAAGjHTAbMAwGA1UdEwEB/wQCMAAwCwYDVR0PBAQDAgbAMA0GCSqGSIb3DQEBBQUAA4IBAQACPXAWZX2DuKiZVv35RS1WFKgT2ubUO9C+byfZapV6ZzYNOiA4KmpkqHU/bkZHqKjR+R59hoYhVdn+ClUIliZf2ChHh8s0a0vBRNJ3IHfA1akWdzocYZLXjz3m0Er31BY+uS3qWUtPsONGVDyZL6IUBBUlFoecQhP9AO39er8zIbeU2b0MMBJxCt4vbDKFvT9i3V0Puoo+kmmkf15D2rBGR+drd8H8Yg8TDGFKf2zKmRsgT7nIeou6WpfYp570WIvLJQY+fsMp334D05Up5ykYSAxUGa30RdUzA4rxN5hT+W9whWVGD88TD33Nw55uNRUcRO3ZUVHmdWRG+GjhlfsD" fecha="2017-03-30T15:20:50" formaDePago="Pago en una sola exhibicion" metodoDePago="tarjeta de credito o debito" noCertificado="20001000000200001428" sello="KzhT/xJ77mglIpD/slKgjCdpL8XZL6aFA2QgE1VT0b6seLYh+L5OcbK85S51pwja3y1szN+e5viMfl8rsc2XxKNHgZQtANc81oGsDZQsiBfSo5+U25ZEJaw+6Wcp4HC4nmUc1h7CI0H3xJ8Gz2O98WJjoFO7FEZboGzTaid27/w=" subTotal="1.00" tipoDeComprobante="ingreso" total="1.16" version="3.2" xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd">
<cfdi:Emisor rfc="AAA010101AAA">
<cfdi:RegimenFiscal Regimen="Regimen General de Ley Personas Morales de Prueba"/>
</cfdi:Emisor>
<cfdi:Receptor rfc="XAXX010101001"/>
<cfdi:Conceptos>
<cfdi:Concepto cantidad="1" descripcion="Paquete de Timbres" importe="1.00" unidad="No Aplica" valorUnitario="1.00"/>
</cfdi:Conceptos>
<cfdi:Impuestos>
<cfdi:Traslados>
<cfdi:Traslado importe="0.16" impuesto="IVA" tasa="16.00"/>
</cfdi:Traslados>
</cfdi:Impuestos>
</cfdi:Comprobante>
11 changes: 8 additions & 3 deletions src/com/timbox/Cancelacion.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.timbox;

import javax.xml.soap.*;
import java.io.ByteArrayOutputStream;

public class Cancelacion {
// URL del servicio
Expand All @@ -20,22 +21,26 @@ public Cancelacion(String usuarioValue, String contrasenaValue, String rfcEmisor
pfxContrasena = pfxContrasenaValue;
}

public SOAPMessage Cancelar() throws Exception {
public String Cancelar() throws Exception {
// Conexion SOAP
String response = "";
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapResponse = messageFactory.createMessage();
try {
// Ejecucion del metodo para cancelar_cfdi
soapResponse = soapConnection.call(peticionCancelacion(), URL);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
soapResponse.writeTo(outputStream);
response = new String(outputStream.toByteArray());
} catch (Exception ex) {
throw ex;
} finally {
soapConnection.close();
}

return soapResponse;
return response;
}

private SOAPMessage peticionCancelacion() throws Exception {
Expand Down Expand Up @@ -69,7 +74,7 @@ private SOAPMessage peticionCancelacion() throws Exception {
uuidsElement.setAttribute("xsi:type", "urn:uuid");
// Creacion de uuids con string array
for (String uuid: uuids) {
SOAPElement uuidElement = uuidsElement.addChildElement("uuids");
SOAPElement uuidElement = uuidsElement.addChildElement("uuid");
uuidElement.addTextNode(uuid);
uuidElement.setAttribute("xsi:type", "urn:string");
}
Expand Down
44 changes: 24 additions & 20 deletions src/com/timbox/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,52 @@
import javax.xml.soap.SOAPMessage;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {

public static void main(String[] args) throws Exception {
//Timbrar Factura
// Parametros generales para el sevicio
String usuario = "AAA010101000";
String contrasena = "h6584D56fVdBbSmmnB";

//
// Timbrar Factura
//
// Parametros para el servicio
String usuarioTimbrado = "usuario_prueba";
String contrasenaTimbrado = "contrasena_prueba";
String documentoTimbrado = "xml";
byte[] archivoXml = Files.readAllBytes(Paths.get("archivoXml.xml"));
String xmlBase64 = Base64.getEncoder().encodeToString(archivoXml);

try {
// Creacion del objeto Timbrado
Timbrado timbrado = new Timbrado(usuarioTimbrado, contrasenaTimbrado, documentoTimbrado);
Timbrado timbrado = new Timbrado(usuario, contrasena, xmlBase64);
//Ejecucion del servicio
SOAPMessage soapResponse = timbrado.Timbrar();
String facturaTimbrada = timbrado.Timbrar();
// Imprime la respuesta
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
System.out.println("Comprobante timbrado: \n");
System.out.print(facturaTimbrada);
} catch (Exception exception) {
throw exception;
}

//Cancelar Factura
// Parametros para el servicio
String usuarioCancelacion = "usuario_prueba";
String contrasenaCancelacion = "contrasena_prueba";
String rfcEmisorCancelacion = "RFCPRUEBA";
String[] uuidsCancelacion = { "UUID1", "UUID2", "UUID3" };
String pfxCancelacion = "valor_PFX";
String pfxContrasenaCancelacion = "contrasena_prueba";
String rfcEmisorCancelacion = "AAA010101AAA";
String[] uuidsCancelacion = { "E28DBCF2-F852-4B2F-8198-CD8383891EB0", "3CFF7200-0DE5-4BEE-AC22-AA2A49052FBC", "51408B33-FE29-47DA-9517-FBF420240FD3" };
byte[] pfx = Files.readAllBytes(Paths.get("archivoPfx.pfx"));
String pfxContrasena = "12345678a";
// Conversion del PFX a base64
byte[] bytes = pfxCancelacion.getBytes(StandardCharsets.UTF_8);
String encodedPfxCancelacion = Base64.getEncoder().encodeToString(bytes);
String pfxBase64 = Base64.getEncoder().encodeToString(pfx);

try {
// Creacion del objeto Cancelacion
Cancelacion timbrado = new Cancelacion(usuarioCancelacion, contrasenaCancelacion, rfcEmisorCancelacion, uuidsCancelacion, encodedPfxCancelacion, pfxContrasenaCancelacion);
Cancelacion timbrado = new Cancelacion(usuario, contrasena, rfcEmisorCancelacion, uuidsCancelacion, pfxBase64, pfxContrasena);
//Ejecucion del servicio
SOAPMessage soapResponse = timbrado.Cancelar();
String facturaCancelada = timbrado.Cancelar();
// Imprime la respuesta
System.out.print("Response SOAP Message:");
soapResponse.writeTo(System.out);
System.out.println("Comprabantes cancelados: \n");
System.out.println(facturaCancelada);
} catch (Exception exception) {
throw exception;
}
Expand Down
16 changes: 8 additions & 8 deletions src/com/timbox/Timbrado.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.timbox;

import javax.xml.soap.*;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.io.*;

public class Timbrado {
// URL del servicio
Expand All @@ -15,28 +14,29 @@ public class Timbrado {
public Timbrado(String usuarioValue, String contrasenaValue, String documentoValue) {
usuario = usuarioValue;
contrasena = contrasenaValue;
// Conversion del documento XML a base64
byte[] bytes = documentoValue.getBytes(StandardCharsets.UTF_8);
String encodedString = Base64.getEncoder().encodeToString(bytes);
sxml = encodedString;
sxml = documentoValue;
}

public SOAPMessage Timbrar() throws Exception {
public String Timbrar() throws Exception {
// Conexion SOAP
String response = "";
SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
SOAPConnection soapConnection = soapConnectionFactory.createConnection();
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage soapResponse = messageFactory.createMessage();
try {
// Ejecucion del metodo para timbrar_cfdi
soapResponse = soapConnection.call(peticionTimbrado(), URL);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
soapResponse.writeTo(outputStream);
response = new String(outputStream.toByteArray());
} catch (Exception ex) {
throw ex;
} finally {
soapConnection.close();
}

return soapResponse;
return response;
}

private SOAPMessage peticionTimbrado() throws Exception {
Expand Down

0 comments on commit 588a5b4

Please sign in to comment.