/// <summary>
        /// Returns a pagedList to a Partial View
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public ActionResult Listagem(int? page, int? numPedido, String nome, String email, int? IdEstado, String Cidade, int? IdPerfilComprador)
        {
            page = page ?? 1;

            //var clientes = new ClienteService().GetByPage(page.Value);

            var clientes = new ClienteService().GetByPageFiltered(page.Value, numPedido, nome, email, IdEstado, Cidade, IdPerfilComprador, EnumerableExtensions.QuantityRegistersPerPage);

            List<ClientePedidoModel> listaClientes = new List<ClientePedidoModel>();

            foreach (var c in clientes.Item1)
            {
                List<Ecommerce_Pedido> listaPedidos = new PedidoService().GetOrdersByIdCliente(c.IdCliente);

                int countPedidos = listaPedidos.Count;

                var clientePedido = new ClientePedidoModel { Cliente = c, Pedidos = listaPedidos, CountPedidos = countPedidos };

                listaClientes.Add(clientePedido);
            }

            var list = new MvcList<ClientePedidoModel>(listaClientes, page.Value, clientes.Item2, EnumerableExtensions.QuantityRegistersPerPage);

            return PartialView(list);
        }
        public ActionResult ListagemPedido(Int32? page, Int32? IdPedido)
        {
            page = page ?? 1;
            var pedido = new PedidoService().GetByPagePedido(page.Value, IdPedido, EnumerableExtensions.QuantityRegistersPerPage);

            var list = new MvcList<Ecommerce_PedidoItem>(pedido.Item1, page.Value, pedido.Item2, Settings.QuantityRegistersPerPage);
            return PartialView(list);
        }
        public ActionResult Editar(int id)
        {
            var ped = new PedidoService().GetById(id);

            ViewBag.StatusPedido = GetStausPedido(ped.StatusPedido);
            ViewBag.SituacaoPedidoDrop = GetSituacaoPedidoSelectListItem(ped.StatusPedido).ToList();

            return View(ped);
        }
        public ActionResult Listagem(Int32? page, DateTime? dataInicio, DateTime? dataFim, int? numeroPedido, int? situacaoPedido, String nomeCliente, int? valorTipoPedido, decimal? valorPedido)
        {
            page = page ?? 1;
            if (valorPedido == 0)
            {
                valorPedido = null;
            }
            var pedido = new PedidoService().GetByPage(page.Value, dataInicio, dataFim, numeroPedido, situacaoPedido, nomeCliente, valorTipoPedido, valorPedido);

            var list = new MvcList<Ecommerce_Pedido>(pedido.Item1, page.Value, pedido.Item2, Settings.QuantityRegistersPerPage);
            return PartialView(list);
        }
        public JsonResult Editar(Ecommerce_Pedido model, bool notificarCliente)
        {
            new PedidoService().UpdateObject(model);

            var dadosEmail = new PedidoService().DadosEmail(model);

            if (notificarCliente && model.StatusPedido == 3)
            {
                Email.SendNotifyCustomerOrder(dadosEmail);
            }
            else if (model.StatusPedido == 2)
            {
                var wsReturn = new WS.Commissions.Commissions().GenerateCommissions(Settings.AutenticationKeyEarningSystem,
                                                                                model.IdPedido, 0);
            }
            else if (model.StatusPedido == 4)
            {
                var wsReturn =
                    new WS.Commissions.Commissions().GenerateReverseCommissions(Settings.AutenticationKeyEarningSystem,
                                                                                model.IdPedido);
            }

            return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Success, Message = Constants._msgUpdateSuccess, ReturnUrl = Url.Content("~/Admin/Pedido/") });
        }
        public ActionResult ConfirmationAuthorize(int? id)
        {
            try
            {
                if (Request.RequestType == "POST")
                {
                    int invoiceNumber = 0;
                    if (Request.Params["x_invoice_num"] != null)
                        invoiceNumber = Convert.ToInt32(Request.Params["x_invoice_num"]);

                    var pedido = new PedidoService().GetRecords(x => x.NumeroPedido == invoiceNumber).FirstOrDefault();

                    //Verify order
                    if (pedido != null)
                    {
                        var parameters = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
                        var authorizeHashMD5 = parameters.Where(x => x.Nome == "MD5 Hash").FirstOrDefault();
                        var apiLogin = parameters.Where(x => x.Nome == "Login ApI").FirstOrDefault();
                        var transKey = parameters.Where(x => x.Nome == "Transaction Key").FirstOrDefault();
                        var urlResponse = parameters.Where(x => x.Nome == "Url de retorno Authorize").FirstOrDefault();

                        var transId = Request.Params["x_trans_id"] != null ? Request.Params["x_trans_id"] : string.Empty;
                        var ammount = Request.Params["x_amount"] != null ? Convert.ToDecimal(Request.Params["x_amount"]) : 0;

                        var md5HashValidator = HashValueToMD5(authorizeHashMD5.Valor + apiLogin.Valor + transId + ammount);

                        var md5HashFromAuthorize = Request.Params["x_MD5_Hash"] != null ? Request.Params["x_MD5_Hash"] : string.Empty;
                        if (md5HashFromAuthorize == md5HashValidator)
                        {
                            if (pedido.IdFormaPagamento == (int)FormaPagamento.Authorize)
                            {
                                var retorno = new Ecommerce_RetornoPagamento
                                {
                                    IdPedido = pedido.IdPedido,
                                    DataInclusao = DateTime.Now,
                                    IdFormaPagamento = pedido.IdFormaPagamento.Value,
                                    Resultado = Request.Params.ToString() //TODO: Serializar e salvar em XML (rvsm)
                                };
                                new PedidoService().InsertRetornoPagamento(retorno);
                            }
                            else
                            {
                                var ex = new Exception(Resources.Resource.Msg_Order_MetodoPagamentoInvalido);
                                LogService.Log("Order.ConfirmationAuthorize()", ex.Message, TipoLog.Erro);
                                throw ex;
                            }

                            //Atualiza o status do pedido
                            pedido.StatusPedido = (int)StatusPedido.EmProcessamento;
                            new PedidoService().UpdateObject(pedido);
                            return PartialView("ConfirmationAuthorize", pedido.IdPedido);
                        }
                        throw new Exception(Resources.Resource.Msg_Order_TransacaoNaoValidada);
                    }
                    throw new Exception(Resources.Resource.Msg_Order_TransacaoNaoDetectada);
                }
                throw new Exception(Resources.Resource.Msg_Order_NaoHouveResposta);
            }
            catch (Exception ex)
            {
                LogService.Log("Order.ConfirmationAuthorize()", ex.Message, TipoLog.Erro);
                throw ex;
            }
        }
        public ActionResult Receipt(int id)
        {
            var order = new PedidoService().GetById(id);

            return View(order);
        }
        public ActionResult ListingOrder(Int32? page, Int32? IdPedido)
        {
            page = page ?? 1;
            var pedido = new PedidoService().GetByPagePedido(page.Value, IdPedido, 4);

            var list = new MvcList<Ecommerce_PedidoItem>(pedido.Item1, page.Value, pedido.Item2, 4);
            return PartialView(list);
        }
        public ActionResult Details(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Title = Resources.Resource.Pedido_Detalhes;

                var pedidoModel = new PedidoService().GetById(id, GetCurrentIdIdioma());
                return View("Details", pedidoModel);
            }
            else
            {
                return RedirectToAction("Index", "Account");
            }
        }
        /// <summary>
        /// Returns a Paged List with the orders
        /// </summary>
        /// <param name="page"></param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <param name="numPedido"></param>
        /// <param name="situacaoPedido"></param>
        /// <returns></returns>
        public ActionResult Listing(int? page, String dateFrom, String dateTo, int? numPedido, int? situacaoPedido)
        {
            page = page ?? 1;

            Tuple<IEnumerable<Ecommerce_Pedido>, Int32> pedidos = null;

            int? idCliente = FormsAuthenticationUtil.UserAuthenticated.IdCliente;

            var dataFrom = !String.IsNullOrWhiteSpace(dateFrom) ? Convert.ToDateTime(dateFrom) : DateTime.MinValue;
            var dataTo = !String.IsNullOrWhiteSpace(dateTo) ? Convert.ToDateTime(dateTo) : DateTime.Today;

            var qtdPerPage = 5;
            if (situacaoPedido == null
                && !numPedido.HasValue
                && String.IsNullOrWhiteSpace(dateFrom)
                && String.IsNullOrWhiteSpace(dateTo))
            {
                pedidos = new PedidoService().GetByPageForEcommerce(page.Value, idCliente.Value, qtdPerPage);
            }
            else
            {
                pedidos = new PedidoService().GetByPageFiltered(page.Value, dataFrom, dataTo, numPedido, situacaoPedido, qtdPerPage, idCliente);
            }

            var list = new MvcList<Ecommerce_Pedido>(pedidos.Item1, page.Value, pedidos.Item2, qtdPerPage);

            return PartialView(list);
        }
        /// <summary>
        /// Atualiza o status do Pedido para EmProcessamento e salva os detalhes da Resposta do Paypal
        /// </summary>
        /// <param name="response"></param>
        /// <returns></returns>
        private static int UpdatePaypalTransaction(string response)
        {
            var options = response.Split('\n');
            var list = options.Select(item => item.Split('=')).Where(option => option.Length == 2).ToDictionary(option => option[0], option => option[1]);
            //Recupera o pedido referente ao response.
            var numPedido = Convert.ToInt32(list["invoice"]);
            var pedido = new PedidoService().GetRecords(p => p.NumeroPedido == numPedido).FirstOrDefault();
            Exception ex;
            if (pedido != null)
            {
                //Salva os detalhes da resposta do gateway
                if (pedido.IdFormaPagamento == (int)FormaPagamento.Paypal)
                {
                    var retorno = new Ecommerce_RetornoPagamento
                    {
                        IdPedido = pedido.IdPedido,
                        DataInclusao = DateTime.Now,
                        IdFormaPagamento = pedido.IdFormaPagamento.Value,
                        Resultado = response //TODO: Serializar e salvar em XML (rvsm)
                    };
                    new PedidoService().InsertRetornoPagamento(retorno);
                }
                else
                {
                    ex = new Exception(Resources.Resource.Msg_Order_MetodoPagamentoInvalido);
                    LogService.Log("Order.UpdatePaypalTransaction()", ex.Message, TipoLog.Erro);
                    throw ex;
                }

                //Atualiza o status do pedido
                pedido.StatusPedido = (int)StatusPedido.EmProcessamento;
                new PedidoService().UpdateObject(pedido);

                return pedido.IdPedido;
            }
            ex = new Exception(Resources.Resource.Msg_Order_PedidoNaoEncontrado);
            LogService.Log("Order.UpdatePaypalTransaction()", ex.Message, TipoLog.Erro);
            throw ex;
        }
        /// <summary>
        /// Confirma o pedido do Paypal e salva os detalhes
        /// </summary>
        /// <param name="transactionId"></param>
        /// <returns></returns>
        protected PedidoModel ConfirmPaypalOrder(string transactionId)
        {
            var parameters = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
            var token = parameters.Where(x => x.Nome == "Token").FirstOrDefault().Valor;

            //Build a url to call Paypal and get data about the Transaction
            //ex. url?cmd=_notify-synch&tx=[TransactionID]&at=[PDTIdentityToken]
            var query = string.Format("cmd=_notify-synch&tx={0}&at={1}", transactionId, token);
            var urlRequest = Settings.PaypalRequest;
            var requestUrl = string.Format("{0}?{1}", urlRequest, query);

            var req = (HttpWebRequest)WebRequest.Create(requestUrl);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.ContentLength = query.Length;

            var stOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
            stOut.Write(query);
            stOut.Close();

            // Do the request to PayPal and get the response
            var stIn = new StreamReader(req.GetResponse().GetResponseStream());
            var strResponse = stIn.ReadToEnd();
            stIn.Close();

            // If response was SUCCESS, parse response string and output details
            if (strResponse.StartsWith("SUCCESS"))
            {
                //Verify order
                var idPedido = UpdatePaypalTransaction(strResponse);

                try
                {
                    //Generate Comission
                    bool resultComission = new WS.Commissions.Commissions().GenerateCommissions(Settings.AutenticationKeyEarningSystem, idPedido, GetIdClientCookie(this));
                }
                catch (Exception ex)
                {
                    LogService.Log("WS.Commissions.Commissions().GenerateCommissions()", ex.Message, TipoLog.Erro);
                }

                if (idPedido != 0)
                {
                    var pedido = new PedidoService().GetById(idPedido, GetCurrentIdIdioma());
                    return pedido;
                }
                throw new Exception(Resources.Resource.Msg_Order_PedidoNaoEncontrado);
            }
            throw new Exception(Resources.Resource.Msg_Order_MensagemNaoValidadaPaypal);
        }
        /// <summary>
        /// Returns a view with the Details of a client
        /// </summary>
        /// <param name="idCliente"></param>
        /// <returns></returns>
        public ActionResult Detalhes(int id)
        {
            ClientePedidoModel cPedModel = new ClientePedidoModel();

            Ecommerce_Cliente cliente = new ClienteService().GetById(id);

            if (cliente != null)
            {
                cPedModel.Cliente = cliente;

                Ecommerce_Cliente_Endereco clienteEndereco = new EnderecoService().GetDefaultShippingAddress(id);

                List<Ecommerce_Pedido> listaPedidos = new PedidoService().GetOrdersByIdCliente(cliente.IdCliente);

                if (clienteEndereco != null)
                {
                    cPedModel.ClienteEndereco = clienteEndereco;
                }

                if (listaPedidos != null)
                {
                    cPedModel.Pedidos = listaPedidos;
                }
            }
            else
            {
                cPedModel.Cliente = new Ecommerce_Cliente();
                cPedModel.ClienteEndereco = new Ecommerce_Cliente_Endereco();
                cPedModel.Pedidos = new List<Ecommerce_Pedido>();
            }

            return View(cPedModel);
        }
Exemple #14
0
        public void NoPrepararPedido(int id)
        {
            PedidoService con = new PedidoService();

            con.NoPrepararPedido(id);
        }
        /// <summary>
        /// Confirmation page
        /// </summary>
        /// <returns></returns>
        public ActionResult Confirmation(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Title = Resources.Resource.Pedido_Confirmacao;
                var pedidoModel = new PedidoService().GetById(id, GetCurrentIdIdioma());

                //
                try
                {
                    if (pedidoModel.IdStatus == 2)
                    {
                        //Generate Comission
                        bool resultComission = new WS.Commissions.Commissions().GenerateCommissions(Settings.AutenticationKeyEarningSystem, id, GetIdClientCookie(this));
                        RemoveIdClientCookie(this);
                    }
                }
                catch (Exception ex)
                {
                    LogService.Log("WS.Commissions.Commissions().GenerateCommissions()", ex.Message, TipoLog.Erro);
                }
                //

                return View("Confirmation", pedidoModel);
            }
            else
            {
                return RedirectToAction("Index", "Account");
            }
        }
 /// <summary>
 /// View to show Printing Confirmation page
 /// </summary>
 /// <param name="idPedido"></param>
 /// <returns></returns>
 public ActionResult Print(int idPedido)
 {
     ViewBag.Title = Resources.Resource.Confirmacao_Imprimir;
     var pedido = new PedidoService().GetById(idPedido, GetCurrentIdIdioma());
     return View(pedido);
 }
Exemple #17
0
        public IHttpActionResult GetImagePedido(int id)
        {
            PedidoService con = new PedidoService();

            return(Ok(con.GetImagePedido(id)));
        }
Exemple #18
0
        public void PostPedidoImage([FromBody] PedidoImage pedido)
        {
            PedidoService con = new PedidoService();

            con.PostPedidoImage(pedido);
        }
Exemple #19
0
        public void RecogerPedido(int id)
        {
            PedidoService con = new PedidoService();

            con.RecogerPedido(id);
        }
        public ActionResult ConfirmationBoletoBradesco()
        {
            //PARAMETERS "transId","numOrder","merchantid","cod","cctype","ccna me","ccemail","numparc","valparc","valtotal","prazo","tipopagto","assinatura",
            var numOrder = Request.Form["numOrder"];
            var numeroPedido = int.Parse(numOrder);

            var parameters = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
            var banco = parameters.FirstOrDefault(m => m.Nome == "Boleto Bradesco Banco");
            var agencia = parameters.FirstOrDefault(m => m.Nome == "Boleto Bradesco Numero Agencia");
            var conta = parameters.FirstOrDefault(m => m.Nome == "Boleto Bradesco Numero Conta");
            var assinatura = parameters.FirstOrDefault(m => m.Nome == "Boleto Bradesco Assinatura");
            var diasPagamento = parameters.FirstOrDefault(m => m.Nome == "Boleto Bradesco Dias Vencimento");
            int diasPgto = int.Parse(diasPagamento.Valor);


            var sb = new StringBuilder();
            var pedido = new PedidoService().GetByNumero(numeroPedido);

            if (pedido != null)
            {
                sb.Append("<BEGIN_ORDER_DESCRIPTION>");
                sb.Append(string.Format("<orderid>=({0})", numOrder));
                foreach (var item in pedido.Ecommerce_PedidoItem.ToList())
                {
                    var produto = new ProdutoService().GetById(item.IdProduto);

                    sb.Append(string.Format("<descritivo>=({0})", produto.Nome));
                    sb.Append(string.Format("<quantidade>=({0})", item.QuantidadeProduto));
                    sb.Append(string.Format("<unidade>=({0})", "UN"));
                    sb.Append(string.Format("<valor>=({0})", Math.Round((item.ValorProduto * item.QuantidadeProduto) * 100), 0));
                }
                sb.Append("<adicional>=(frete)");
                sb.Append(string.Format("<valorAdicional>=({0})", Math.Round(pedido.ValorFrete.GetValueOrDefault() * 100),0));

                if(pedido.ValorTaxaManuseio.GetValueOrDefault() > 0)
                {
                    sb.Append("<adicional>=(manuseio)");
                    sb.Append(string.Format("<valorAdicional>=({0})",Math.Round(pedido.ValorTaxaManuseio.GetValueOrDefault() * 100),0));    
                }
                
                sb.Append("<END_ORDER_DESCRIPTION>");
                sb.Append("<BEGIN_BOLETO_DESCRIPTION>");
                sb.Append(string.Format("<CEDENTE>=({0})",Resources.Resource.BoletoBradesco_Cedente));
                if (banco != null) sb.Append(string.Format("<BANCO>=({0})", banco.Valor));
                if (agencia != null) sb.Append(string.Format("<NUMEROAGENCIA>=({0})", agencia.Valor));
                if (conta != null) sb.Append(string.Format("<NUMEROCONTA>=({0})", conta.Valor));
                if (assinatura != null) sb.Append(string.Format("<ASSINATURA>=({0})", assinatura.Valor));
                sb.Append(string.Format("<DATAEMISSAO>=({0})", DateTime.Today.ToString("dd/MM/yyyy")));
                sb.Append(string.Format("<DATAPROCESSAMENTO>=({0})", DateTime.Today.ToString("dd/MM/yyyy")));
                sb.Append(string.Format("<DATAVENCIMENTO>=({0})", DateTime.Today.AddDays(diasPgto).ToString("dd/MM/yyyy")));
                sb.Append(string.Format("<NOMESACADO>=({0})",pedido.Ecommerce_Cliente.NomeCompleto));
                sb.Append(string.Format("<ENDERECOSACADO>=({0}, {1})", pedido.Ecommerce_PedidoEndereco.Logradouro, pedido.Ecommerce_PedidoEndereco.Numero));
                sb.Append(string.Format("<CIDADESACADO>=({0})",pedido.Ecommerce_PedidoEndereco.Cidade));
                sb.Append(string.Format("<UFSACADO>=({0})",pedido.Ecommerce_PedidoEndereco.Estado.Prefixo));
                sb.Append(string.Format("<CEPSACADO>=({0})",pedido.Ecommerce_PedidoEndereco.Cep.PadRight(8,'0')));
                sb.Append(string.Format("<CPFSACADO>=({0})",(pedido.Ecommerce_Cliente.Documento ?? "").PadRight(11,'0')));
                sb.Append(string.Format("<NUMEROPEDIDO>=({0})",numOrder));
                sb.Append(string.Format(CultureInfo.CreateSpecificCulture("pt-BR"),"<VALORDOCUMENTOFORMATADO>=({0:C})", pedido.ValorTotal.GetValueOrDefault()).Replace(" ",""));
                sb.Append("<SHOPPINGID>=(1)");
                sb.Append(string.Format("<NUMDOC>=({0})",numOrder));
                sb.Append("<END_BOLETO_DESCRIPTION>");
            }

            ViewBag.XML = sb.ToString();

            return View();
        }
        /// <summary>
        /// Form to submit values to gateway
        /// </summary>
        /// <param name="id">idPedido</param>
        /// <returns></returns>
        public ActionResult Payment(int id)
        {
            if (User.Identity.IsAuthenticated)
            {
                ViewBag.Title = Resources.Resource.Pagamento_Titulo;

                //get order details
                var idPedido = new PedidoService().GetRecords(x => x.NumeroPedido == id).FirstOrDefault().IdPedido;
                var pedido = new PedidoService().GetById(idPedido, GetCurrentIdIdioma());

                if (pedido.Status == StatusPedido.AguardandoPagamento &&
                    FormsAuthenticationUtil.UserAuthenticated.IdCliente.HasValue &&
                    FormsAuthenticationUtil.UserAuthenticated.IdCliente.Value == pedido.IdCliente)
                {
                    //get shipping address details
                    var endereco = new EnderecoService().GetShippingAddress(pedido.IdPedido);

                    var cultureInfo = new CultureInfo("en-US");

                    var rgService = new RequestGatewayService();
                    rgService.Model = new RequestGatewayModel
                    {
                        PedidoNumero = pedido.Numero.HasValue ? pedido.Numero.Value.ToString(CultureInfo.InvariantCulture) : string.Empty,
                        PedidoValorFrete = pedido.ValorFrete.ToString(cultureInfo),
                        PedidoValorTaxas = pedido.ValorTaxa.ToString(cultureInfo),
                        PedidoValorManuseio = pedido.ValorManuseio.ToString(cultureInfo),
                        PedidoSubTotal = pedido.Subtotal.ToString(cultureInfo),
                        PedidoTotal = pedido.Total.ToString(cultureInfo),

                        ClienteId = pedido.IdCliente.ToString(CultureInfo.InvariantCulture),
                        ClienteSobrenome = pedido.NomeCliente.Trim().Split(' ').Length > 1 ? pedido.NomeCliente.Trim().Split(' ')[0] : pedido.NomeCliente.Trim(),
                        ClienteNome = pedido.NomeCliente.Trim().Split(' ').Length > 1 ? pedido.NomeCliente.Trim().Substring(pedido.NomeCliente.IndexOf(' '), pedido.NomeCliente.Trim().Length - pedido.NomeCliente.Trim().IndexOf(' ')) : string.Empty,

                        EnderecoCep = endereco.Cep,
                        EnderecoLogradouro = endereco.Logradouro,
                        EnderecoCidade = endereco.IdCidade != null ? endereco.Cidade1.Nome : endereco.Cidade,
                        EnderecoEstado = endereco.IdEstado != null ? endereco.Estado.Nome : string.Empty,
                        EnderecoEmail = endereco.EmailEntrega,
                        EnderecoTelefone = endereco.TelefoneEntrega
                    };

                    switch (pedido.FormaPagamento)
                    {
                        case FormaPagamento.Authorize:
                            var parameters = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
                            var apiLogin = parameters.Where(x => x.Nome == "Login ApI").FirstOrDefault();
                            var transKey = parameters.Where(x => x.Nome == "Transaction Key").FirstOrDefault();
                            var urlResponse = parameters.Where(x => x.Nome == "Url de retorno Authorize").FirstOrDefault();

                            if (apiLogin != null && transKey != null && urlResponse != null)
                            {
                                rgService.QueryString = Settings.AuthorizeQueryString;
                                rgService.Model.GatewayUsuario = apiLogin.Valor;
                                rgService.Model.GatewayUrlRequest = Settings.AuthorizeRequest;
                                rgService.Model.GatewayUrlResponse = urlResponse.Valor;

                                rgService.AdicionalParameters = new Dictionary<String, String>();
                                var timeStamp = ((int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds).ToString();
                                string fingerprint = WebHelpers.HMAC_MD5(transKey.Valor, rgService.Model.GatewayUsuario + "^" + rgService.Model.PedidoNumero + "^" + timeStamp + "^" + rgService.Model.PedidoTotal + "^");

                                rgService.AdicionalParameters.Add("timeStamp", timeStamp);
                                rgService.AdicionalParameters.Add("fingerprint", fingerprint);
                            }

                            return View(rgService);
                        case FormaPagamento.Paypal:
                            var parametros = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
                            var business = parametros.Where(x => x.Nome == "Business").FirstOrDefault().Valor;
                            var urlRetorno = parametros.Where(x => x.Nome == "Url de retorno Paypal").FirstOrDefault().Valor;
                            var urlNotificacao = parametros.Where(x => x.Nome == "Url de notificação").FirstOrDefault().Valor;
                            var urlImagem = parametros.Where(x => x.Nome == "Url da Imagem").FirstOrDefault().Valor;

                            rgService.QueryString = Settings.PaypalQueryString;
                            rgService.Model.GatewayUsuario = business;
                            rgService.Model.GatewayUrlRequest = Settings.PaypalRequest;
                            rgService.Model.GatewayUrlResponse = urlRetorno;

                            rgService.AdicionalParameters = new Dictionary<string, string>();
                            rgService.AdicionalParameters.Add("lc", "PT");// CultureInfo.CurrentUICulture.TextInfo.CultureName.Split('-')[1]
                            rgService.AdicionalParameters.Add("image_url", urlImagem);
                            rgService.AdicionalParameters.Add("notify_url", urlNotificacao);

                            return View(rgService);
                        case FormaPagamento.BoletoBradesco:
                            var paramBoleto = new ParametroService().GetByParameterType((int)TipoParametro.FormaDePagamento);
                            var urlBoleto = paramBoleto.FirstOrDefault(m => m.Nome == "Boleto Bradesco URL") ?? new Parametro();
                            var numLoja = paramBoleto.FirstOrDefault(m => m.Nome == "Boleto Bradesco Numero Loja") ?? new Parametro();

                            rgService.Model.PedidoNumero = idPedido.ToString(CultureInfo.InvariantCulture);
                            rgService.Model.GatewayUrlRequest = string.Format(urlBoleto.Valor, numLoja.Valor, id);
                            rgService.QueryString = string.Format(Settings.BoletoBradescoQueryString, numLoja.Valor, id);

                            return View("PaymentBoleto", rgService);
                        default:
                            return AccessDenied();
                    }
                }
            }
            return AccessDenied();
        }
        public ActionResult Payment(int idFormaPagamento)
        {
            try
            {
                var carrinho = GetCurrentCart();
                var peso = carrinho.Items.Sum(x => x.Quantidade * x.Produto.Peso) / 1000;

                carrinho.ValorFrete = GetShippingPriceUPS(carrinho.ZipCode, peso);

                if (carrinho.ValorFrete >= 0)
                {
                    var idPedido = new PedidoService().Insert(carrinho.Cookie, idFormaPagamento, 1, carrinho.ValorFrete, GetCurrentIdIdioma());
                    var pedido = new PedidoService().GetRecords(x => x.IdPedido == idPedido).FirstOrDefault();
                    var numPedido = 0;
                    if (pedido != null && pedido.NumeroPedido.HasValue)
                        numPedido = pedido.NumeroPedido.Value;
                    return Json(new JsonRequestResult
                    {
                        ResultType = JsonRequestResultType.Success,
                        Message = string.Format(Resources.Resource.Pedido_MensagemSucesso, numPedido),
                        ReturnUrl = Url.Content("~/Order/Payment/" + numPedido)
                    });
                }
                else
                {
                    return Json(new JsonRequestResult
                    {
                        ResultType = JsonRequestResultType.Alert,
                        Message = Resources.Resource.Msg_Geral_FormaEntregaImpossivelEncontrar
                    });
                }
            }
            catch (Exception ex)
            {
                LogService.Log("Order.Insert()", ex);
                return Json(new JsonRequestResult { ResultType = JsonRequestResultType.Error, Message = Resources.Resource.Msg_Geral_Erro });
            }
        }
        /// <summary>
        /// Returns a partialView with the Orders of a Client
        /// </summary>
        /// <param name="page"></param>
        /// <param name="id"> </param>
        /// <returns></returns>
        public ActionResult ListagemPedidos(int? page, int id)
        {
            page = page ?? 1;

            Tuple<IEnumerable<Ecommerce_Pedido>, Int32> pedidos = null;

            pedidos = new PedidoService().GetByPageForEcommerce(page.Value, id, 7);

            var list = new MvcList<Ecommerce_Pedido>(pedidos.Item1, page.Value, pedidos.Item2, 7);

            return PartialView(list);
        }