Example #1
0
        public ActionResult Confirmation(OrderCartViewModel order)
        {
            var session = HttpContext.Session;
            var cart    = session.Get <Order>("Cart");

            var tApi = new TransactionApi(_apiSettings.ApiBaseUrl);

            var userId = "";

            if (User.Identity.IsAuthenticated)
            {
                userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);
            }



            var transaction = new Transaction
            {
                TransactionID  = 0,
                BuyerFirstName = order.BuyerFirstName,
                BuyerLastName  = order.BuyerLastName,
                BuyerAddress   = order.BuyerAddress,
                BuyerCity      = order.BuyerCity,
                BuyerEmail     = order.BuyerEmail,
                BuyerUserId    = userId,
                TotalAmount    = order.TotalAmount
            };

            //Add transaction & process payment
            Transaction newTransaction = tApi.AddTransaction(transaction);

            if (newTransaction.PaymentStatus == "PaymentApproved")
            {
                var ticketApi = new TicketApi(_apiSettings.ApiBaseUrl);
                foreach (int id in cart.Cart)
                {
                    var t = new Ticket
                    {
                        TicketEventDateID = id,
                        TransactionID     = newTransaction.TransactionID
                    };
                    ticketApi.AddTicketOrder(t);
                }

                var a   = new EmailSender();
                var msg = @"Hello, <br/> Thank you for your ticket purchase with us.<br/>" +
                          "Receipt:<br/>" +
                          "TransactionID: " + newTransaction.TransactionID +
                          "Total tickets bought: " + cart.Cart.Count() +
                          "Total Amount paid: " + newTransaction.TotalAmount;
                a.SendEmailAsync(newTransaction.BuyerEmail, "Thank you for your ticket purchase", msg);

                ViewData["noTickets"] = cart.Cart.Count();
                session.Remove("Cart");
            }


            switch (newTransaction.PaymentStatus)
            {
            case "PaymentRejected":
                ViewData["panel-class"]   = "panel-warning";
                ViewData["PaymentStatus"] = "Payment Rejected";

                break;

            case "UnknownError":
                ViewData["panel-class"]   = "panel-danger";
                ViewData["PaymentStatus"] = "Unknown Error";
                break;

            default:
                ViewData["panel-class"]   = "panel-success";
                ViewData["PaymentStatus"] = "Payment Approved";
                break;
            }
            ViewData["Title"] = "Payment Summary";

            return(View(newTransaction));
        }