Example #1
0
        public void ExecutarSingle(string senha, Enumeradores.RetornoAccertify retornoAccertify, int score, string action = "")
        {
            var sw = new Stopwatch();

            sw.Start();

            LogUtil.Info(string.Format("##HammerHead.ExecutingSingle## SENHA: {0}, RETORNO_ACCERTIFY: {1}, SCORE: {2}", senha, retornoAccertify, score));

            salvarlogevent = SalvarLog.Events.Listener;

            var vendaBilheteriaID = oVendaBilheteria.BuscaID(senha.Trim());

            LogUtil.Info(string.Format("##HammerHead.ExecutarSingle.VendaBilheteriaIdRetrieved## SENHA: {0}, RETORNO_ACCERTIFY: {1}, SCORE: {2}, TEMPO_DECORRIDO: {3} ms", senha, retornoAccertify, score, sw.ElapsedMilliseconds));

            var vendas = CarregarSingle(vendaBilheteriaID);

            LogUtil.Info(string.Format("##HammerHead.ExecutarSingle.CarregarSingle## SENHA: {0}, RETORNO_ACCERTIFY: {1}, SCORE: {2}, TEMPO_DECORRIDO: {3} ms", senha, retornoAccertify, score, sw.ElapsedMilliseconds));
            oProcessamento.Single           = true;
            oProcessamento.RetornoAccertify = retornoAccertify;

            var venda = vendas.FirstOrDefault();

            if (venda == null)
            {
                return;
            }

            venda.Score = score;
            this.EfetuarPagamento(venda, action);

            sw.Stop();
            LogUtil.Info(string.Format("##HammerHead.ExecutarSingle.Finished## SENHA: {0}, RETORNO_ACCERTIFY: {1}, SCORE: {2}, TEMPO_DECORRIDO_TOTAL: {3} ms", senha, retornoAccertify, score, sw.ElapsedMilliseconds));
        }
Example #2
0
        private void ConsultarAccertify()
        {
            if (Single) //Já foi preenchido!
            {
                return;
            }

            if (!ConfiguracaoAccertify.Instancia.Chaves.Ativo.Valor)
            {
                RetornoAccertify = Enumeradores.RetornoAccertify.Aceitar;
                if (ConfiguracaoHammerHead.Instancia.Configuracao.SalvarLog.Valor)
                {
                    SalvarLog.Salvar("Accertify inativa!. Aceitar automático!", Enumeradores.TipoEntrada.Informacao, SalvarLog.Events.Accertify);
                }

                return;
            }

            if (Venda.DataVenda.Date >= DateTime.Now.AddDays(IRLib.ConfiguracaoAdyen.Instancia.Chaves.DiasProcessamento.Valor))
            {
                if (Venda.Score == 0)
                {
                    RetornoAccertify = Enumeradores.RetornoAccertify.CancelarVendaInvalida; //Aconteceu erro ao processar a venda na accertify (provavel nem ter sido enviado), se passar muito tempo, cancela por venda inválida
                }
                else if (Venda.Score <= ConfiguracaoAccertify.Instancia.Chaves.ScoreAceitarTempoExcedido.Valor)
                {
                    RetornoAccertify = Enumeradores.RetornoAccertify.Aceitar;
                }
                else
                {
                    RetornoAccertify = Enumeradores.RetornoAccertify.CancelarTempoLimiteExcedido;
                }

                return;
            }

            XmlDocument xml        = null;
            XmlDocument xmlRetorno = new XmlDocument();

            try
            {
                xml = Accertify.GerarXMLVenda(Venda);

                xmlRetorno.LoadXml(Utilitario.HTTPPostXML(ConfiguracaoAccertify.Instancia.Chaves.URL.Valor, xml.InnerXml, ConfiguracaoAccertify.Instancia.Chaves.Usuario.Valor, ConfiguracaoAccertify.Instancia.Chaves.Senha.Valor));
            }
            catch (Exception ex)
            {
                throw ex;
            }

            int    score         = Convert.ToInt32(xmlRetorno.GetElementsByTagName("total-score")[0].InnerText);
            string recomendation = xmlRetorno.GetElementsByTagName("recommendation-code")[0].InnerText;

            Venda.Score = score;

            var retorno = (IRLib.Paralela.RetornoAccertify.Recommendation)Enum.Parse(typeof(IRLib.Paralela.RetornoAccertify.Recommendation), recomendation);

            Venda.RetornoAccertify = Accertify.ParseRetorno(recomendation);// RetornoAccertify;
            RetornoAccertify       = Venda.RetornoAccertify;
        }
Example #3
0
        public void ExecutarSingle(string senha, Enumeradores.RetornoAccertify retornoAccertify, int score)
        {
            this.salvarlogevent = SalvarLog.Events.Listener;

            int vendaBilheteriaID = oVendaBilheteria.BuscaID(senha.Trim());

            this.CarregarSingle(vendaBilheteriaID);
            this.oProcessamento.Single           = true;
            this.oProcessamento.RetornoAccertify = retornoAccertify;
            this.Vendas.FirstOrDefault().Score   = score;
            this.EfetuarPagamentos();
        }
Example #4
0
        private Enumeradores.RetornoProcessamento Processar()
        {
            try
            {
                LogUtil.Debug(string.Format("##ProcessamentoTEF.ProcessandoPagamentoEAnalise## CLIENTE: {0}", this.oPagamento.ClienteID));

                if (ConfiguracaoHammerHead.Instancia.Configuracao.AmbienteDeTestes.Valor)
                {
                    SalvarLog.Salvar("Ambiente de testes ativo!", Enumeradores.TipoEntrada.Informacao, SalvarLog.Events.AmbienteTesteAtivo);

                    var rnd = new Random();
                    Thread.Sleep(rnd.Next(2000));
                    var processamento = rnd.Next() % 2 == 0 ? Enumeradores.RetornoProcessamento.Processado : Enumeradores.RetornoProcessamento.CancelarAccertify;

                    LogUtil.Debug(string.Format("##ProcessamentoTEF.ProcessandoPagamentoEAnalise.AmbienteDeTestes## CLIENTE: {0}, RETORNO: {1}, GATEWAY: {2}", this.oPagamento.ClienteID, processamento, this.oPagamento.TipoPagamento));

                    if (this.oPagamento.TipoPagamento != EstruturaPagamento.enumTipoPagamento.Adyen)
                    {
                        return(processamento);
                    }

                    if (processamento == Enumeradores.RetornoProcessamento.Processado && this.oPagamento.FormaPagamentoOrigem == 0)
                    {
                        LogUtil.Debug(string.Format("##ProcessamentoTEF.ProcessandoPagamentoEAnalise.AmbienteDeTestes.PROCESSADO## CLIENTE: {0}, RETORNO: {1}, MSG: {2}", this.oPagamento.ClienteID, processamento, "Capturando pagamento na Adyen"));
                        oPagamento.oAdyen.CapturarPagamento();
                    }
                    else
                    {
                        LogUtil.Debug(string.Format("##ProcessamentoTEF.ProcessandoPagamentoEAnalise.AmbienteDeTestes.RECUSADO## CLIENTE: {0}, RETORNO: {1}, MSG: {2}", this.oPagamento.ClienteID, processamento, "Cancelando pagamento na Adyen"));
                        oPagamento.oAdyen.CancelarPagamento();
                    }

                    return(processamento);
                }
                else
                {
                    switch (this.oPagamento.TipoPagamento)
                    {
                    case EstruturaPagamento.enumTipoPagamento.TEF:
                        return(this.ProcessarTEF());

                    case EstruturaPagamento.enumTipoPagamento.Adyen:
                        return(this.ProcessarAdyen());

                    case EstruturaPagamento.enumTipoPagamento.Paypal:
                        RetornoAccertify = Enumeradores.RetornoAccertify.Bypass;
                        return(Enumeradores.RetornoProcessamento.Bypass);

                    default:
                        return(Enumeradores.RetornoProcessamento.Processado);
                    }
                }
            }
            catch (System.Net.WebException ex)
            {
                LogUtil.Error(string.Format("##ProcessamentoTEF.ProcessandoAdyen.EXCEPTION## CLIENTE: {0}, MSG: {1}", this.oPagamento.ClienteID, ex.Message), ex);
                throw;
            }
            catch (System.Web.Services.Protocols.SoapHeaderException ex)
            {
                LogUtil.Error(string.Format("##ProcessamentoTEF.ProcessandoAdyen.EXCEPTION## CLIENTE: {0}, MSG: {1}", this.oPagamento.ClienteID, ex.Message), ex);
                throw;
            }
            catch (System.Net.Sockets.SocketException ex)
            {
                LogUtil.Error(string.Format("##ProcessamentoTEF.ProcessandoAdyen.EXCEPTION## CLIENTE: {0}, MSG: {1}", this.oPagamento.ClienteID, ex.Message), ex);
                throw;
            }
            catch (Exception ex)
            {
                LogUtil.Error(string.Format("##ProcessamentoTEF.ProcessandoPagamentoEAnalise.EXCEPTION## CLIENTE: {0}, MSG: {1}", this.oPagamento.ClienteID, ex.Message), ex);

                if (ConfiguracaoHammerHead.Instancia.Configuracao.SalvarLog.Valor)
                {
                    SalvarLog.SalvarErro("Transação Inválida.", "Venda: " + Venda.ID + "\nException: " + ex.Message, SalvarLog.Events.Transacoes);
                }

                return(Enumeradores.RetornoProcessamento.CartaoInvalido);
            }
        }
Example #5
0
        private void ConsultarAccertify()
        {
            LogUtil.Debug(string.Format("##ProcessamentoTEF.ConsultandoAccertify## CLIENTE: {0}, RETURN_SINGLE: {1}, PAGAMENTO_ORIGEM: {2}", this.oPagamento.ClienteID, this.Single, this.oPagamento.FormaPagamentoOrigem));

            if (Single || this.oPagamento.FormaPagamentoOrigem > 0 || this.Venda.VendaCancelada) //Já foi preenchido!
            {
                if (this.oPagamento.FormaPagamentoOrigem > 0)
                {
                    RetornoAccertify = Enumeradores.RetornoAccertify.Bypass;
                }
                return;
            }

            if (!ConfiguracaoAccertify.Instancia.Chaves.Ativo.Valor)
            {
                LogUtil.Debug(string.Format("##ProcessamentoTEF.ConsultarAccertify.AccertifyDesativado## CLIENTE: {0}, MSG: {1}", this.oPagamento.ClienteID, "Aceitar automático"));

                RetornoAccertify = Enumeradores.RetornoAccertify.Aceitar;
                if (ConfiguracaoHammerHead.Instancia.Configuracao.SalvarLog.Valor)
                {
                    SalvarLog.Salvar("Accertify inativa!. Aceitar automático!", Enumeradores.TipoEntrada.Informacao, SalvarLog.Events.Accertify);
                }

                return;
            }

            if (Venda.DataVenda.Date >= DateTime.Now.AddDays(ConfiguracaoAdyen.Instancia.Chaves.DiasProcessamento.Valor))
            {
                if (Venda.Score == 0)
                {
                    RetornoAccertify = Enumeradores.RetornoAccertify.CancelarVendaInvalida; //Aconteceu erro ao processar a venda na accertify (provavel nem ter sido enviado), se passar muito tempo, cancela por venda inválida
                }
                else if (Venda.Score <= ConfiguracaoAccertify.Instancia.Chaves.ScoreAceitarTempoExcedido.Valor)
                {
                    RetornoAccertify = Enumeradores.RetornoAccertify.Aceitar;
                }
                else
                {
                    RetornoAccertify = Enumeradores.RetornoAccertify.CancelarTempoLimiteExcedido;
                }

                LogUtil.Debug(string.Format("##ProcessamentoTEF.ConsultandoAccertify.ValidacaoData## CLIENTE: {0}, DATA_VENDA: {1} >= DATA_DIAS_PROC: {2}, RETORNO_ACCERTIFY: {3}", this.oPagamento.ClienteID, Venda.DataVenda.Date, DateTime.Now.AddDays(ConfiguracaoAdyen.Instancia.Chaves.DiasProcessamento.Valor), RetornoAccertify));

                return;
            }

            var sw = new Stopwatch();

            sw.Start();

            var xmlRetorno = new XmlDocument();

            try
            {
                LogUtil.Debug(string.Format("##ProcessamentoTEF.ConsultarAccertify.GerandoXMLVenda## CLIENTE: {0}", this.oPagamento.ClienteID));
                var xml = Accertify.GerarXMLVenda(Venda);

                LogUtil.Debug(string.Format("##ProcessamentoTEF.ConsultarAccertify.ChamandoWSAccertify## CLIENTE: {0}", this.oPagamento.ClienteID));

                var stringXml = Utilitario.HTTPPostXML(ConfiguracaoAccertify.Instancia.Chaves.URL.Valor, xml.InnerXml, ConfiguracaoAccertify.Instancia.Chaves.Usuario.Valor, ConfiguracaoAccertify.Instancia.Chaves.Senha.Valor);

                xmlRetorno.LoadXml(stringXml);
            }
            catch (Exception ex)
            {
                LogUtil.Error(string.Format("##ProcessamentoTEF.ConsultarAccertify.EXCEPTION## CLIENTE: {0}, MSG: {1}", this.oPagamento.ClienteID, ex.Message));
                throw ex;
            }

            var score          = Convert.ToInt32(xmlRetorno.GetElementsByTagName("total-score")[0].InnerText);
            var recommendation = xmlRetorno.GetElementsByTagName("recommendation-code")[0].InnerText;

            Venda.Score = score;

            Venda.RetornoAccertify = Accertify.ParseRetorno(recommendation);// RetornoAccertify;
            RetornoAccertify       = Venda.RetornoAccertify;

            LogUtil.Debug(string.Format("##ProcessamentoTEF.ConsultarAccertify.SUCCESS## CLIENTE: {0}, SCORE: {1}, RECOMMENDATION: {2}, TEMPO_DECORRIDO_ACCERTIFY: {3} ms", this.oPagamento.ClienteID, score, recommendation, sw.ElapsedMilliseconds));
        }