Example #1
0
        /// <summary>
        /// Funcion que se encarga de realizar el timbrado de una facturacion dandole el nombre del archivo xml que se timbrara
        /// </summary>
        /// <param name="nameFile">variable de tipo string</param>
        public static void timbrado(string nameFile)
        {
            try
            {
                /* Consumir web service de timbrado */
                StampSOAP     selloSOAP            = new StampSOAP();
                stamp         oStamp               = new stamp();
                stampResponse selloResponse        = new stampResponse();
                Incidencia    incidencia           = new Incidencia();
                string        MESPATH              = @"C:\SiscomSoft\Facturas\XML\" + DateTime.Now.ToString("MMMM") + "," + DateTime.Now.Year;
                string        NameWithoutExtension = Path.GetFileNameWithoutExtension(MESPATH + @"\" + nameFile);

                //Cargas tu archivo xml
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.Load(MESPATH + @"\" + nameFile);

                //Conviertes el archivo en byte
                byte[] byteXmlDocument = Encoding.UTF8.GetBytes(xmlDocument.OuterXml);
                //Conviertes el byte resultado en base64
                string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument);
                //Convirtes el resultado nuevamente a byte
                byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument);

                //Timbras el archivo
                oStamp.xml      = byteXmlDocument;
                oStamp.username = "******";
                oStamp.password = "******";

                //Recibes la respuesta de timbrado
                selloResponse = selloSOAP.stamp(oStamp);
                /* Consumir web service de timbrado */

                if (selloResponse.stampResult.Incidencias != null)
                {
                    StreamWriter error = new StreamWriter(@"C:\SiscomSoft\Facturas\Errors\ERROR_" + NameWithoutExtension + ".log.txt");
                    error.WriteLine("CODIGO ERROR       " + "MENSAJE DE ERROR");
                    for (int i = 0; i < selloResponse.stampResult.Incidencias.Count(); i++)
                    {
                        error.WriteLine(selloResponse.stampResult.Incidencias[i].CodigoError + "                " + selloResponse.stampResult.Incidencias[i].MensajeIncidencia);
                    }
                    error.Close();
                }

                /* Generar SOAP Request de timbrado */
                string SOAPDirectory = @"C:\SiscomSoft\SOAP";
                if (!Directory.Exists(SOAPDirectory))
                {
                    Directory.CreateDirectory(SOAPDirectory);
                }
                StreamWriter  XML  = new StreamWriter(SOAPDirectory + @"\" + "SOAP_ENVELOPE_" + nameFile); //Direccion donde guardaremos el SOAP Envelope
                XmlSerializer soap = new XmlSerializer(oStamp.GetType());                                  //Obtenemos los datos del SOAP de la variable Solicitud
                soap.Serialize(XML, oStamp);
                XML.Close();
                /* Generar SOAP Request de timbrado */
            }
            catch (Exception)
            {
                throw;
            }
        }
 public Boolean Timbrar(ref string errores, ref XmlDocument xml, string rutaXmlSinTImbrar, string rutaXmlTimbrado)
 {
     try
     {
         xml.Load(rutaXmlSinTImbrar);
         StampSOAP timbrado = new StampSOAP();
         stamp     timb     = new stamp();
         timb.xml      = RegresaEN64(xml.OuterXml);
         timb.username = Resources.UsuarioFinkokP;
         timb.password = Resources.ContraFinkok;;
         stampResponse respuestaTimbrado = timbrado.stamp(timb);
         if ((respuestaTimbrado.stampResult.Incidencias.Length == 0) || (respuestaTimbrado.stampResult.Incidencias[0].CodigoError.Contains("307")))
         {
             xml.LoadXml(respuestaTimbrado.stampResult.xml);
             xml.Save(rutaXmlTimbrado);
         }
         else
         {
             errores = respuestaTimbrado.stampResult.Incidencias[0].MensajeIncidencia;
         }
     }
     catch (Exception e)
     {
         errores += e.Message;
     }
     return(string.IsNullOrEmpty(errores) ? true : false);
 }
Example #3
0
 private void timbrar()
 {
     Models.Configuration configuracion = new Models.Configuration();
     using (configuracion)
     {
         List <Models.Configuration> config = configuracion.getConfiguration();
         //Instancias del timbrado
         Timbrado.StampSOAP selloSOAP = new Timbrado.StampSOAP();
         stamp         oStamp         = new stamp();
         stampResponse selloResponse  = new stampResponse();
         //Cargas tu archivo xml
         XmlDocument xmlDocument = new XmlDocument();
         xmlDocument.Load(config[0].Ruta_factura + txtFolio.Text + ".xml");
         //xmlDocument.Load(config[0].Ruta_factura + txtFolio.Text + ".xml");
         //Conviertes el archivo en byte
         byte[] byteXmlDocument = Encoding.UTF8.GetBytes(xmlDocument.OuterXml);
         //Conviertes el byte resultado en base64
         string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument);
         //Convirtes el resultado nuevamente a byte
         byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument);
         //Timbras el archivo
         oStamp.xml      = byteXmlDocument;
         oStamp.username = "******";
         oStamp.password = "******";
         //Generamos request
         String usuario;
         usuario = Environment.UserName;
         String        url  = config[0].Ruta_factura;
         StreamWriter  XML  = new StreamWriter(url + "SOAP_Request.xml");             //Direccion donde guardaremos el SOAP Envelope
         XmlSerializer soap = new XmlSerializer(oStamp.GetType());                    //Obtenemos los datos del objeto oStamp que contiene los parámetros de envió y es de tipo stamp()
         soap.Serialize(XML, oStamp);
         XML.Close();
         //Recibes la respuesta de timbrado
         selloResponse = selloSOAP.stamp(oStamp);
         try
         {
             MessageBox.Show("No se timbro el XML" + "\nCódigo de error: " + selloResponse.stampResult.Incidencias[0].CodigoError.ToString() + "\nMensaje: " + selloResponse.stampResult.Incidencias[0].MensajeIncidencia);
         }
         catch (Exception)
         {
             MessageBox.Show(selloResponse.stampResult.CodEstatus.ToString());
             Models.Facturas factura = new Models.Facturas();
             using (factura)
             {
                 factura.Uuid  = selloResponse.stampResult.UUID.ToString();
                 factura.Folio = Convert.ToInt32(txtFolio.Text);
                 factura.Xml   = selloResponse.stampResult.xml.ToString();
                 factura.update_uuid();
             }
             StreamWriter XMLL = new StreamWriter(url + txtFolio.Text + ".xml");
             XMLL.Write(selloResponse.stampResult.xml);
             XMLL.Close();
             File.Delete(url + "SOAP_Request.xml");
         }
     }
 }
Example #4
0
        private bool Timbrar(Comprobante oComprobante, string mPago, string serie, string folio)
        {
            StampSOAP     selloSOAP     = new StampSOAP();
            stamp         oStamp        = new stamp();
            stampResponse selloResponse = new stampResponse();

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(@"C:\CFDI\pago.xml");//ConfigurationManager.AppSettings["rutaXML"] + lblNombre.Text.Trim() + "\\" + txtSerie.Text + txtFolio.Text + ".xml");

            byte[] byteXmlDocument       = Encoding.UTF8.GetBytes(xmlDocument.OuterXml);
            string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument);

            byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument);

            oStamp.xml      = byteXmlDocument;
            oStamp.username = ConfigurationManager.AppSettings.Get("userFinkok");
            oStamp.password = ConfigurationManager.AppSettings.Get("pswFinkok");

            selloResponse = selloSOAP.stamp(oStamp);
            string xml = selloResponse.stampResult.xml.Replace("\\", "");

            xml = xml.Replace("\n", "");
            XmlDocument doc = new XmlDocument();

            if (xml == "")
            {
                MessageBox.Show("La factura no pudo timbrarse. \n\nCodigo de Error: " + selloResponse.stampResult.Incidencias[0].CodigoError + "\nDescripción: " + selloResponse.stampResult.Incidencias[0].MensajeIncidencia, "Error al timbrar", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                doc.LoadXml(xml);
                if (!Directory.Exists(ConfigurationManager.AppSettings["rutaXML"] + oComprobante.Receptor.Rfc))
                {
                    Directory.CreateDirectory(ConfigurationManager.AppSettings["rutaXML"] + oComprobante.Receptor.Rfc);
                }
                doc.Save(ConfigurationManager.AppSettings["rutaXML"] + oComprobante.Receptor.Rfc + "\\" + serie + folio + ".xml");
                oComprobante.FormaPago  = "PUE";
                oComprobante.MetodoPago = mPago;

                metodos_VENTA.guardarTimbre(oComprobante, ConfigurationManager.AppSettings["noCertificado"], 0, selloResponse.stampResult.Fecha, selloResponse.stampResult.NoCertificadoSAT, selloResponse.stampResult.SatSeal, selloResponse.stampResult.UUID, selloResponse.stampResult.xml, ConfigurationManager.AppSettings["noCertificado"], generaSello(), "");
                Int32 id = metodos_VENTA.ultimoIdVenta();
                metodos_DETALLEVENTA.insertarDETALLEVENTA(0, id, "16477", 0, 1, 0, 0, "CTA", "84111506", "0", "PAGO", 0);

                string cadenaORiginalSAT = "?re=" + ConfigurationManager.AppSettings["rfcEmisor"] + "&rr=" + oComprobante.Emisor.Rfc + "&tt=" + oComprobante.Total + "&id=" + selloResponse.stampResult.UUID;
                gen_qr_file(ConfigurationManager.AppSettings["rutaXML"] + selloResponse.stampResult.UUID + ".png", cadenaORiginalSAT, selloResponse.stampResult.UUID + ".png");

                MessageBox.Show(selloResponse.stampResult.CodEstatus, "Timbrado exitoso", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return(true);
            }
        }
Example #5
0
        private bool Timbrar()
        {
            StampSOAP.StampSOAP selloSOAP = new StampSOAP.StampSOAP();
            stamp         oStamp          = new stamp();
            stampResponse selloResponse   = new stampResponse();

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(@"C:\CFDI\SinTimbrar.xml");//ConfigurationManager.AppSettings["rutaXML"] + lblNombre.Text.Trim() + "\\" + txtSerie.Text + txtFolio.Text + ".xml");

            byte[] byteXmlDocument       = Encoding.UTF8.GetBytes(xmlDocument.OuterXml);
            string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument);

            byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument);

            oStamp.xml      = byteXmlDocument;
            oStamp.username = ConfigurationManager.AppSettings.Get("userFinkok");
            oStamp.password = ConfigurationManager.AppSettings.Get("pswFinkok");

            selloResponse = selloSOAP.stamp(oStamp);
            string xml = selloResponse.stampResult.xml.Replace("\\", "");

            xml = xml.Replace("\n", "");
            XmlDocument doc = new XmlDocument();

            if (xml == "")
            {
                MessageBox.Show("La factura no pudo timbrarse. \n\nCodigo de Error: " + selloResponse.stampResult.Incidencias[0].CodigoError + "\nDescripción: " + selloResponse.stampResult.Incidencias[0].MensajeIncidencia, "Error al timbrar", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            else
            {
                doc.LoadXml(xml);
                if (!Directory.Exists(ConfigurationManager.AppSettings["rutaXML"] + lblNombre.Text.Trim()))
                {
                    Directory.CreateDirectory(ConfigurationManager.AppSettings["rutaXML"] + lblNombre.Text.Trim());
                }
                doc.Save(ConfigurationManager.AppSettings["rutaXML"] + lblNombre.Text.Trim() + "\\" + txtSerie.Text + txtFolio.Text + ".xml");
                metodos_VENTA.guardarTimbre(ConfigurationManager.AppSettings["noCertificado"], Convert.ToInt64(metodos_VENTA.ultimoIdVenta()), selloResponse.stampResult.Fecha, selloResponse.stampResult.NoCertificadoSAT, selloResponse.stampResult.SatSeal, selloResponse.stampResult.UUID, selloResponse.stampResult.xml, ConfigurationManager.AppSettings["noCertificado"], generaSello(), cmbCFDI.Text);

                string cadenaORiginalSAT = "?re=" + ConfigurationManager.AppSettings["rfcEmisor"] + "&rr=" + lblRFC.Text.Trim() + "&tt=" + lblTotal.Text.Trim() + "&id=" + selloResponse.stampResult.UUID;
                gen_qr_file(ConfigurationManager.AppSettings["rutaXML"] + selloResponse.stampResult.UUID + ".png", cadenaORiginalSAT, selloResponse.stampResult.UUID + ".png");

                MessageBox.Show(selloResponse.stampResult.CodEstatus, "Timbrado exitoso", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return(true);
            }
        }
Example #6
0
        private string  Timbrar(string IDVENTA, string rfcReceptor, string serie, string folio, double total)
        {
            StampSOAP.StampSOAP selloSOAP = new StampSOAP.StampSOAP();
            stamp         oStamp          = new stamp();
            stampResponse selloResponse   = new stampResponse();

            XmlDocument xmlDocument = new XmlDocument();

            xmlDocument.Load(@"C:\CFDI\SinTimbrar.xml");//ConfigurationManager.AppSettings["rutaXML"] + lblNombre.Text.Trim() + "\\" + txtSerie.Text + txtFolio.Text + ".xml");

            byte[] byteXmlDocument       = Encoding.UTF8.GetBytes(xmlDocument.OuterXml);
            string stringByteXmlDocument = Convert.ToBase64String(byteXmlDocument);

            byteXmlDocument = Convert.FromBase64String(stringByteXmlDocument);

            oStamp.xml      = byteXmlDocument;
            oStamp.username = ConfigurationManager.AppSettings.Get("userFinkok");
            oStamp.password = ConfigurationManager.AppSettings.Get("pswFinkok");

            selloResponse = selloSOAP.stamp(oStamp);
            string xml = selloResponse.stampResult.xml.Replace("\\", "");

            xml = xml.Replace("\n", "");

            XmlDocument doc = new XmlDocument();

            if (xml == "")
            {
                return("La factura no pudo timbrarse. \n\nCodigo de Error: " + selloResponse.stampResult.Incidencias[0].CodigoError + "\nDescripción: " + selloResponse.stampResult.Incidencias[0].MensajeIncidencia);
            }
            else
            {
                doc.LoadXml(xml);
                if (!Directory.Exists(ConfigurationManager.AppSettings["rutaXML"] + rfcReceptor))
                {
                    Directory.CreateDirectory(ConfigurationManager.AppSettings["rutaXML"] + rfcReceptor);
                }
                doc.Save(ConfigurationManager.AppSettings["rutaXML"] + rfcReceptor + "\\" + serie + folio + ".xml");
                metodos_VENTA.guardarTimbre(ConfigurationManager.AppSettings["noCertificado"], Convert.ToInt64(IDVENTA), selloResponse.stampResult.Fecha, selloResponse.stampResult.NoCertificadoSAT, selloResponse.stampResult.SatSeal, selloResponse.stampResult.UUID, selloResponse.stampResult.xml, ConfigurationManager.AppSettings["noCertificado"], generaSello(), "");

                string cadenaORiginalSAT = "?re=" + ConfigurationManager.AppSettings["rfcEmisor"] + "&rr=" + ConfigurationManager.AppSettings["rfcEmisor"] + "&tt=" + total + "&id=" + selloResponse.stampResult.UUID;
                gen_qr_file(ConfigurationManager.AppSettings["rutaXML"] + selloResponse.stampResult.UUID + ".png", cadenaORiginalSAT, selloResponse.stampResult.UUID + ".png");
                return("La factura se timbró correctamente y generó el folio fiscal " + selloResponse.stampResult.UUID);
            }
        }