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);
 }
Пример #2
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;
            }
        }
Пример #3
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);
            }
        }