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 #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;
            }
        }
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);
            }
        }
Example #7
0
        public static void Demonstration()
        {
            stamp Stamp_1 = new stamp {
                Name = "Premiere", Age = 25
            };
            stamp Stamp_2 = new stamp {
                Name = "Again", Age = 47
            };
            int age = Stamp_1.Age;

            Stamp_1.Age = 22;
            stamp guru = Stamp_2;

            Stamp_2.Name = "Again Amend";
            Console.WriteLine("Stamp_1's age:{0}", Stamp_1.Age);
            Console.WriteLine("age's value: {0}", age);
            Console.WriteLine("Stamp_2's name:{0}", Stamp_2.Name);
            Console.WriteLine("guru's name:{0}", guru.Name);
        }
Example #8
0
        public string Cred(string usr, string tok, string ip)
        {
            // was there a bad attempt in last 5 minutes?
            // if so, reject
            stamp stmp = ps.GetI <stamp>("attemptIp", "IP", ip).Result;

            if (stmp != null)
            {
                if (stmp.retMinutes() < 5.0)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - too many requests from IP.");
                    return("error - too many requests from IP. Please wait " + Math.Round(5.0 - stmp.retMinutes(), 2) + " minutes");
                }
            }

            stamp stmpr2 = ps.GetI <stamp>("attemptUser", "USER", usr).Result;

            if (stmpr2 != null)
            {
                if (stmpr2.retMinutes() < 5.0)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - too many requests for user.");
                    return("error - too many requests for user. Please wait " + Math.Round(5.0 - stmpr2.retMinutes(), 2) + " minutes");
                }
            }

            // if not, check this attempt
            // if good continue
            // if bad, reject and mark new bad attempt

            webtoken token = ps.GetI <webtoken>("webtoks", usr, usr).Result;

            if (token == null)
            {
                stmpr2 = new stamp("USER", usr);
                if (!ps.UpsertI <stamp>("attemptUser", stmpr2).Result)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - no token and error upsert attemptUser");
                    return("error - stamp upsert attemptUser");
                }

                var stmpr = new stamp("IP", ip);
                if (!ps.UpsertI <stamp>("attemptIp", stmpr).Result)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - no token and error upsert attemptIp");
                    return("error - stamp upsert attemptIp");
                }

                el(usr + " " + tok + " " + ip + " Cred error - no token");
                return("error - no token found.  Please ensure you are using the correct username, or log into the Rosenlink website and generate your first token by navigating to Options -> Web Token");
            }

            if (token.tok != tok)
            {
                stmpr2 = new stamp("USER", usr);
                if (!ps.UpsertI <stamp>("attemptUser", stmpr2).Result)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - token mismatch and error upsert attemptUser");
                    return("error - stamp upsert attemptUser");
                }

                var stmpr = new stamp("IP", ip);
                if (!ps.UpsertI <stamp>("attemptIp", stmpr).Result)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - token mismatch and error upsert attemptIp");
                    return("error - stamp upsert attemptIp");
                }

                el(usr + " " + tok + " " + ip + " Cred error - token mismatch");
                return("error - token mismatch. Please ensure you are using the correct username, or log into the Rosenlink website and copy paste the value found by navigating to Options -> Web Token");
            }

            sacstr sac = ps.GetI <sacstr>("sacinfo", "sacstr", usr).Result;

            if (sac == null)
            {
                stmpr2 = new stamp("USER", usr);
                if (!ps.UpsertI <stamp>("attemptUser", stmpr2).Result)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - no sacstr and error upsert attemptUser");
                    return("error - stamp upsert attemptUser");
                }

                var stmpr = new stamp("IP", ip);
                if (!ps.UpsertI <stamp>("attemptIp", stmpr).Result)
                {
                    el(usr + " " + tok + " " + ip + " Cred error - no sacstr and error upsert attemptIp");
                    return("error - stamp upsert attemptIp");
                }

                el(usr + " " + tok + " " + ip + " Cred error - no sacstr");
                return("error - no cstr found.  Please ensure you are using the correct username, or log into the Rosenlink website and generate your first token by navigating to Options -> Web Token");
            }

            g(usr + " " + tok + " " + ip + " credentials verified.");
            return(rehpis.Encrypt(sac.sac, usr));
        }
Example #9
0
 AddEntry(type, version, stamp, dataSize);