Beispiel #1
0
 public ActionResult SalesList()
 {
     if (Session["Usuario"] != null)
     {
         srvVentas    sVenta = new srvVentas();
         List <Venta> st     = sVenta.ObtenerVentas(1);
         ViewBag.ventas = st;
         return(View());
     }
     else
     {
         return(RedirectToAction("Login", "Admin"));
     }
 }
Beispiel #2
0
 public JsonResult CancelSale(string order_id)
 {
     try
     {
         MP mp = new MP(srvConfig.MP_client_id(), srvConfig.MP_client_secret());
         // get info order --> "Order"
         string baseUrl = "https://api.mercadopago.com";
         string url     = "merchant_orders/" + order_id + "?access_token=" + srvConfig.MP_client_access_token();
         using (var client = new HttpClient())
         {
             client.BaseAddress = new Uri(baseUrl);
             var responseTask = client.GetAsync(url);
             responseTask.Wait();
             var result = responseTask.Result;
             if (result.IsSuccessStatusCode)
             {
                 var readTask = result.Content.ReadAsStringAsync();
                 readTask.Wait();
                 JObject Order    = JObject.Parse(readTask.Result);
                 JToken  payments = Order["payments"];
                 foreach (JToken payment in payments)
                 {
                     if (payment["status"].ToString() == "approved")
                     {
                         mp.cancelPayment(payment["id"].ToString());
                     }
                 }
                 srvVentas sVentas = new srvVentas();
                 sVentas.CancelarVenta(order_id);
             }
         }
         return(Json("true"));
     }
     catch (Exception)
     {
         return(Json("false"));
     }
 }
Beispiel #3
0
        public ActionResult PaymentNotification(string topic, string id)
        {
            // URL Notificacion
            // http://localhost:64615/Sell/PaymentNotification/?topic=payment&id=4205580523

            try
            {
                if (topic == "payment")
                {
                    MP mp = new MP(srvConfig.MP_client_id(), srvConfig.MP_client_secret());

                    // get info pago --> "Payment"
                    Hashtable Payment = mp.getPaymentInfo(id);
                    Payment = ((Hashtable)Payment["response"]);
                    string orderID = ((Hashtable)Payment["collection"])["order_id"].ToString();
                    if (((Hashtable)Payment["collection"])["status"].ToString() == "approved")
                    {
                        // get info order --> "Order"
                        // https://api.mercadopago.com/merchant_orders/857112399?access_token=APP_USR-3825884689807039-100215-028a54b7ff4b3017ab7830f35784a693-357350759
                        string baseUrl = "https://api.mercadopago.com";
                        string url     = "merchant_orders/" + orderID + "?access_token=" + srvConfig.MP_client_access_token();
                        using (var client = new HttpClient())
                        {
                            client.BaseAddress = new Uri(baseUrl);
                            var responseTask = client.GetAsync(url);
                            responseTask.Wait();
                            var result = responseTask.Result;
                            if (result.IsSuccessStatusCode)
                            {
                                var readTask = result.Content.ReadAsStringAsync();
                                readTask.Wait();
                                JObject Order = JObject.Parse(readTask.Result);

                                if (Order["status"].ToString() == "closed")
                                {
                                    Venta oVenta = new Venta();
                                    //oVenta.emailComprador
                                    oVenta.MP_state_shipments = "";
                                    oVenta.MP_order_id        = Order["id"].ToString();
                                    oVenta.MP_state_order     = Order["status"].ToString();
                                    oVenta.fecha      = DateTime.Now;
                                    oVenta.montoTotal = Convert.ToInt32(Order["total_amount"].ToString());

                                    if (Order["shipments"].ToString() != null)
                                    {
                                        JToken Shipment         = Order["shipments"].First;
                                        JToken receiver_address = Shipment["receiver_address"];
                                        JToken city             = receiver_address["city"];
                                        JToken state            = receiver_address["state"];
                                        oVenta.direccionShipments = receiver_address["address_line"].ToString() + ", " + city["name"].ToString() + ", " + state["name"].ToString() + ", CP:" + receiver_address["zip_code"].ToString();
                                        oVenta.MP_state_shipments = Shipment["status"].ToString();
                                        // oVenta.idLocalidad = city["name"].ToString();
                                    }

                                    DetalleVenta oDetalleVenta;
                                    JToken       items = Order["items"];
                                    foreach (JToken item in items)
                                    {
                                        oDetalleVenta                = new DetalleVenta();
                                        oDetalleVenta.idProducto     = Convert.ToInt32(item["id"]);
                                        oDetalleVenta.cantidad       = Convert.ToInt32(item["quantity"]);
                                        oDetalleVenta.precioUnitario = Convert.ToInt32(item["unit_price"]);
                                        oDetalleVenta.subTotal       = oDetalleVenta.cantidad * oDetalleVenta.precioUnitario;
                                        oDetalleVenta.descuento      = Convert.ToInt32(item["category_id"]);
                                        oVenta.DetalleVenta.Add(oDetalleVenta);
                                    }
                                    // Guardar
                                    srvVentas sVenta = new srvVentas();
                                    sVenta.GuardarVenta(oVenta);
                                }
                            }
                        }
                    }
                }
                return(View());
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }