예제 #1
0
        public ActionResult RealizarPagoList(Card card)
        {
            string      data        = generarToken(card);
            List <Item> lista       = (List <Item>)Session["cart"];
            string      orderList   = "";
            List <int>  idProductos = new List <int>();

            var suma = 0;

            foreach (var item in lista)
            {
                suma      = (int)(suma + (item.producto.precio * item.cantidad));
                orderList = orderList + "-" + item.producto.IdProducto.ToString();
                idProductos.Add(item.producto.IdProducto);
            }
            ViewBag.listaIdProductos = idProductos;

            // var producto = db.Productoes.Find(IdProducto);
            var form_precio = suma;

            var json_object = JObject.Parse(data);

            var userId = db.AspNetUsers.Find(User.Identity.GetUserId()).IdUsuario;

            Dictionary <string, object> metadata = new Dictionary <string, object>
            {
                { "order_id", orderList },
                { "User ", userId }
            };

            Dictionary <string, object> map2 = new Dictionary <string, object>
            {
                { "amount", suma *100 },
                { "capture", true },
                { "currency_code", "PEN" },
                { "description", "Venta de Gift Cards" },
                { "email", (string)json_object["email"] },
                { "installments", 0 },
                { "metadata", metadata },
                { "source_id", (string)json_object["id"] }
            };

            //ViewBag.charge = new Charge(security()).Create(map2);
            string dataResponse  = new Charge(security()).Create(map2);
            var    json_response = JObject.Parse(dataResponse);

            if ((string)json_response["outcome"]["type"] == "venta_exitosa")
            {
                var codigo_pago = (string)json_response["id"];
                //Observaciones = (string)json_response["outcome"]["merchant_message"];
                DAL.Stock itemStock;
                foreach (var item in lista)
                {
                    itemStock = db.Stocks.Where(t => t.IdProducto == item.producto.IdProducto).FirstOrDefault();
                    db.ActualizarStock(itemStock.IdStock, userId, "no disponible", codigo_pago, "Cencosud", DateTime.Now, (item.producto.precio).ToString());
                }

                TTemplateEmail nuevo = new TTemplateEmail();
                nuevo.EnviarCorreo(db.AspNetUsers.Find(User.Identity.GetUserId()).UserName);
                //nuevo.EnviarCorreo("*****@*****.**");
                nuevo.EnviarCorreo("*****@*****.**");

                return(RedirectToAction("CompraCorrecta", "Home", new { mensaje = (string)json_response["outcome"]["user_message"] }));
            }
            else
            {
                return(RedirectToAction("RealizarPagoList", new { mensaje = "Ocurrieron algunos problemas al realizar la transacion." }));
            }
        }
예제 #2
0
        public ActionResult RealizarPago(Card card, int IdProducto)
        {
            var producto    = db.Productoes.Find(IdProducto);
            var form_precio = producto.precio;
            Dictionary <string, object> map = new Dictionary <string, object>
            {
                { "card_number", card.cardNumber },
                { "cvv", card.cvv },
                { "expiration_month", card.expiration_month },
                { "expiration_year", card.expiration_year },
                { "email", card.email }
            };
            String data        = new Token(security()).Create(map);
            var    json_object = JObject.Parse(data);

            var userId = db.AspNetUsers.Find(User.Identity.GetUserId()).IdUsuario;

            Dictionary <string, object> metadata = new Dictionary <string, object>
            {
                { "order_id", Convert.ToString(producto.IdProducto) },
                { "User ", userId }
            };

            Dictionary <string, object> map2 = new Dictionary <string, object>
            {
                { "amount", (int)(producto.precio ?? 0) * 100 },
                { "capture", true },
                { "currency_code", "PEN" },
                { "description", "Venta de Gift Cards" },
                { "email", card.email },
                { "installments", 0 },
                { "metadata", metadata },
                { "source_id", (string)json_object["id"] }
            };

            //ViewBag.charge = new Charge(security()).Create(map2);
            string dataResponse  = new Charge(security()).Create(map2);
            var    json_response = JObject.Parse(dataResponse);

            if ((string)json_response["outcome"]["type"] == "venta_exitosa")
            {
                var codigo_pago = (string)json_response["id"];
                //Observaciones = (string)json_response["outcome"]["merchant_message"];


                DAL.Stock oStock = db.Stocks.Where(t => t.IdProducto == IdProducto).FirstOrDefault();
                db.ActualizarStock(oStock.IdStock, userId, codigo_pago, "no disponible", "Cencosud", DateTime.Now, (producto.precio).ToString());


                TTemplateEmail nuevo = new TTemplateEmail();
                nuevo.EnviarCorreo(db.AspNetUsers.Find(User.Identity.GetUserId()).UserName);
                //nuevo.EnviarCorreo("*****@*****.**");
                nuevo.EnviarCorreo("*****@*****.**");

                return(RedirectToAction("CompraCorrecta", new { mensaje = (string)json_response["outcome"]["user_message"] }));
            }
            else
            {
                return(RedirectToAction("RealizarPago", new { IdProducto = IdProducto, mensaje = "Ocurrieron algunos probemas al realizar la transacion." }));
            }
        }