/// <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> /// Deprecated Method for adding a new object to the Ecommerce_RetornoPagamento EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToEcommerce_RetornoPagamento(Ecommerce_RetornoPagamento ecommerce_RetornoPagamento) { base.AddObject("Ecommerce_RetornoPagamento", ecommerce_RetornoPagamento); }
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; } }
/// <summary> /// Create a new Ecommerce_RetornoPagamento object. /// </summary> /// <param name="idRetornoPagamento">Initial value of the IdRetornoPagamento property.</param> /// <param name="idPedido">Initial value of the IdPedido property.</param> /// <param name="idFormaPagamento">Initial value of the IdFormaPagamento property.</param> /// <param name="dataInclusao">Initial value of the DataInclusao property.</param> /// <param name="resultado">Initial value of the Resultado property.</param> public static Ecommerce_RetornoPagamento CreateEcommerce_RetornoPagamento(global::System.Int32 idRetornoPagamento, global::System.Int32 idPedido, global::System.Int32 idFormaPagamento, global::System.DateTime dataInclusao, global::System.String resultado) { Ecommerce_RetornoPagamento ecommerce_RetornoPagamento = new Ecommerce_RetornoPagamento(); ecommerce_RetornoPagamento.IdRetornoPagamento = idRetornoPagamento; ecommerce_RetornoPagamento.IdPedido = idPedido; ecommerce_RetornoPagamento.IdFormaPagamento = idFormaPagamento; ecommerce_RetornoPagamento.DataInclusao = dataInclusao; ecommerce_RetornoPagamento.Resultado = resultado; return ecommerce_RetornoPagamento; }