Exemplo n.º 1
0
        public ActionResult RedirectFromPaypal(string ids)
        {
            Temp_PayPal p = _context.Temp_PayPal.Single(m => m.Id == ids);

            Pay(p.Ticket_Game_Ids);
            _context.Temp_PayPal.Remove(p);
            return(RedirectToAction("Index", "Order"));
        }
Exemplo n.º 2
0
        public ActionResult ValidateCommand()
        {
            string tgs        = "";
            double?totalPrice = 0;
            string product;
            string game        = "";
            int    ticketCount = 0;

            // build tgId-tgName pairs
            foreach (string name in Request.Form.AllKeys)
            {
                try
                {
                    int         n  = Convert.ToInt32(name);
                    Ticket_Game tg = _context.Ticket_Game.Single(m => m.Id == n);
                    if (tg.Sold == 1)
                    {
                        //already sold
                        return(View("Error"));
                    }
                    totalPrice += tg.Price;
                    ticketCount++;
                    game = tg.Game.getFixture();
                    tgs += name + "-" + Request.Form[name] + ",";
                }
                catch (Exception e)
                {
                }
            }
            tgs     = tgs.TrimEnd(',');
            product = ticketCount + " ticket(s) " + game;
            PayPalModel paypal = new PayPalModel();

            paypal.cmd           = "_xclick";
            paypal.Tgs           = tgs;
            paypal.business      = "*****@*****.**";
            paypal.currency_code = "EUR";
            bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandbox"]);

            if (useSandbox)
            {
                ViewBag.actionUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            }
            else
            {
                ViewBag.actionUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr";
            }
            paypal.cancel_return = ConfigurationManager.AppSettings["CancelUrl"];
            paypal.@return       = "https://localhost:44315/PayPal/RedirectFromPayPal?ids=" + paypal.id;
            paypal.notify_url    = "https://localhost:44315/PayPal/NotifyFromPaypal";



            paypal.item_name = product;
            paypal.amount    = totalPrice.ToString();
            Temp_PayPal tp = new Temp_PayPal
            {
                Id = paypal.id,
                Ticket_Game_Ids = paypal.Tgs
            };

            _context.Temp_PayPal.Add(tp);
            _context.SaveChanges();
            return(View(paypal));
        }