Beispiel #1
0
        public static bool IsTransbankReady()
        {
            PipeClient   pipeClient = new PipeClient();
            ServicioPago servicio   = new ServicioPago();

            pipeClient.Message = servicio.BuildMessage(Comandos.Pooling, new List <string> {
                "1"
            });
            // Log.Write("PoolTbk", pipeClient.Message, Evento.Query, Comandos.Pooling);
            pipeClient.SendMessage(Comandos.Pooling);
            try
            {
                if (pipeClient.Resultado.CodigoError == 0)
                {
                    //Log.Write("PoolTbk", pipeClient.Resultado.Data[0], Evento.Response, Comandos.Pooling);
                    return(true);
                }
                else
                {
                    //Log.Write("PoolTbk", pipeClient.Resultado.CodigoError + ": " + pipeClient.Resultado.Data[0], Evento.Response, Comandos.Pooling);
                    return(false);
                }
            }
            catch (Exception ex)
            {
                //Global.log.Error("IsTransbankReady ", ex);

                return(false);
            }
        }
Beispiel #2
0
        public bool SendMessage(ServicioPago.Comandos command)
        {
            if (MessageSentSuccessfully())
            {
                ServicioPago trx = new ServicioPago();

                if (_Resp.Length < (int)ServicioPago.Posicion.MIN_MSG_LEN)
                {
                    Resultado.CodigoError = (int)ServicioPago.ValidaMsg.MSGLEN;
                }
                else if (_Resp.Length > (int)ServicioPago.Posicion.MAX_MSG_LEN)
                {
                    Resultado.CodigoError = (int)ServicioPago.ValidaMsg.MSGLEN;
                }
                else if (_Resp.Substring(0, (int)ServicioPago.Posicion.HEAD_LEN) != ServicioPago.Header || _Resp.Last() != '@')
                {
                    Resultado.CodigoError = (int)ServicioPago.ValidaMsg.MSGFMT;
                }

                if (Resultado.CodigoError != 0)
                {
                    // Resultado.Data = new List<string> { Estado.Servicio.GetError(Resultado.CodigoError) };
                    return(false);
                }

                int respCmd = Convert.ToInt32(_Resp.Substring((int)ServicioPago.Posicion.CMD_POS, (int)ServicioPago.Posicion.CMD_LEN));
                int len     = Convert.ToInt32(_Resp.Substring((int)ServicioPago.Posicion.LEN_POS, (int)ServicioPago.Posicion.LEN_LEN));

                if (_Resp.Length != len)
                {
                    Resultado.CodigoError = (int)ServicioPago.ValidaMsg.MSGLEN;
                }
                else if (respCmd != 999 && respCmd != (int)command)
                {
                    Resultado.CodigoError = (int)ServicioPago.ValidaMsg.MSGCMD;
                }

                if (Resultado.CodigoError != 0)
                {
                    // Resultado.Data = new List<string> { Estado.Servicio.GetError(Resultado.CodigoError) };
                    return(false);
                }
                if (!ServicioPago.IsChecksumValid(_Resp))
                {
                    Resultado.CodigoError = (int)ServicioPago.ValidaMsg.MSGCKS;
                    // Resultado.Data = new List<string> { Estado.Servicio.GetError(Resultado.CodigoError) };
                    return(false);
                }

                string msg = _Resp.Substring((int)ServicioPago.Posicion.DAT_POS, len - (int)ServicioPago.Posicion.FIX_LEN);
                if (respCmd == 999)
                {
                    Resultado.CodigoError = Convert.ToInt32(msg.Substring(0, 5));
                    if (Resultado.CodigoError == (int)ServicioPago.ValidaMsgServer.ERRTBK)
                    {
                        Resultado.Data = new List <string> {
                            msg.Substring(5, msg.Length - 5)
                        }
                    }
                    ;
                    //else
                    //   Resultado.Data = new List<string> { Estado.Servicio.GetError(Resultado.CodigoError) };
                    return(false);
                }

                Resultado.CodigoError = 0;
                Resultado.Data        = msg.Split('|').ToList();
                if (Resultado.Data[0].Contains("&&EST"))
                {
                    Resultado.EstadoSalud        = Resultado.Data[0].Substring(0, 7);
                    Resultado.EstadoSalud        = Resultado.EstadoSalud.Substring(2, 5);
                    Resultado.Data[0]            = Resultado.Data[0].Substring(7, Resultado.Data[0].Length - 7);
                    Globals.EstadoDeSaludMaquina = Resultado.EstadoSalud;
                    //Global.EST = Resultado.EstadoSalud;
                }
                return(true);
            }
            else
            {
                Resultado.CodigoError = -1;
                Resultado.Data        = new List <string> {
                    _Resp
                };
                return(false);
            }
        }