public ViewResult CheckoutReviewOrderCont()
        {
            int orderID;
            int currentOrderId = 0;
            string retMsg = "";
            string token = "";
            string finalPaymentAmount = "";
            string PayerID = "";

            NVPAPICaller payPalCaller = new NVPAPICaller();
            payPalCaller.SetCredentials();

            NVPCodec decoder = new NVPCodec();

            token = UserSessionData.Token.ToString();
            finalPaymentAmount = UserSessionData.PaymentAmount.ToString();
            PayerID = UserSessionData.PayerID;
            currentOrderId = UserSessionData.OrderID;

            bool ret = payPalCaller.DoCheckoutPayment(finalPaymentAmount, token, PayerID, ref decoder, ref retMsg);
            if (ret)
            {
                // Retrieve PayPal confirmation value.
                string PaymentConfirmation = decoder["PAYMENTINFO_0_TRANSACTIONID"].ToString();

                //Update the order
                orderID = UserSessionData.OrderID;
                orderID = UpdateOrderConfirmation(orderID, PaymentConfirmation);

                //Reset session data
                UserSessionData.PaymentAmount = 0;
                UserSessionData.OrderID = 0;

                ViewBag.PaymentConfirmation = PaymentConfirmation;

                //Reduce the quantity of products in stock
                IEnumerable<OrderItem> orderItems = orderItemRepository.OrderItems.Where(x => x.OrderID == orderID);
                foreach (var orderItem in orderItems)
                {
                    UpdateProductQuantity(orderItem.ProductID, orderItem.Quantity);
                }

                return View("CheckoutReviewTrans");
            }
            else
            {
                return View("CheckoutError");
            }
        }
        // PayPal
        public ActionResult CheckoutWithPayPal(Cart cart)
        {
            if (cart.Lines.Count() == 0)
            {
                ModelState.AddModelError("", "Sorry, your cart is empty!");
                return View("Completed");
            }
            else
            {

                int orderID = StoreOrderAndOrderItems(cart);
                UserSessionData.OrderID = orderID;

                NVPAPICaller payPalCaller = new NVPAPICaller();
                payPalCaller.SetCredentials();

                string retMsg = "";
                string token = "";
                decimal amtVal = cart.ComputeTotalValue();
                string amt = amtVal.ToString();
                bool ret = payPalCaller.ShortcutExpressCheckout(cart, amt, ref token, ref retMsg);
                if (ret)
                {

                    UserSessionData.Token = token;
                    UserSessionData.PaymentAmount = amtVal;

                    return Redirect(retMsg);
                }
                else
                {
                    return View("Completed");
                }
            }
        }
        public ViewResult CheckoutReview()
        {
            int orderID;

            string firstName, lastName, company, email,
                streetLine1, streetLine2, streetLine3,
                city, postalCode, county, country;

            string retMsg = "";
            string token = "";
            decimal paymentAmountOnCheckout = 0;
            string PayerID = "";

            NVPAPICaller payPalCaller = new NVPAPICaller();
            payPalCaller.SetCredentials();

            NVPCodec decoder = new NVPCodec();

            token = UserSessionData.Token.ToString();
            paymentAmountOnCheckout = UserSessionData.PaymentAmount;

            bool ret = payPalCaller.GetCheckoutDetails(token, ref PayerID, ref decoder, ref retMsg);
            if (ret)
            {

                // Verify total payment amount as set on CheckoutStart.aspx.
                try
                {
                    decimal paymentAmoutFromPayPal = Convert.ToDecimal(decoder["AMT"].ToString());
                    if (paymentAmountOnCheckout != paymentAmoutFromPayPal)
                    {
                        return View("CheckoutError");
                    }
                }
                catch (Exception)
                {
                    return View("CheckoutError");
                }

                //Session information
                UserSessionData.PayerID = PayerID;
                orderID = UserSessionData.OrderID;

                //Update the order with PayPal Informatin
                company = string.Empty; city = string.Empty; county = string.Empty;
                //OrderDate = Convert.ToDateTime(decoder["TIMESTAMP"].ToString());
                //Username = User.Identity.Name;
                firstName = decoder["FIRSTNAME"].ToString();
                lastName = decoder["LASTNAME"].ToString();
                streetLine1 = decoder["SHIPTOSTREET"].ToString();
                streetLine2 = decoder["SHIPTOCITY"].ToString();
                streetLine3 = decoder["SHIPTOSTATE"].ToString();
                postalCode = decoder["SHIPTOZIP"].ToString();
                country = decoder["SHIPTOCOUNTRYCODE"].ToString();
                email = decoder["EMAIL"].ToString();
                //Total = Convert.ToDecimal(decoder["AMT"].ToString());
                orderID = UpdateOrderShipTo(orderID, firstName, lastName, company, email,
                    streetLine1, streetLine2, streetLine3,
                    city, postalCode, county, country);

                //Prepare for display
                PayPalReview ppReview = new PayPalReview();
                ppReview.OrderID = orderID.ToString();
                ppReview.OrderDate = decoder["TIMESTAMP"].ToString();
                ppReview.Username = User.Identity.Name;
                ppReview.FirstName = firstName;
                ppReview.LastName = lastName;
                ppReview.Address = streetLine1;
                ppReview.City = streetLine2;
                ppReview.State = streetLine3;
                ppReview.PostalCode = postalCode;
                ppReview.Email = email;
                ppReview.TotalAmount = paymentAmountOnCheckout.ToString();
                ViewBag.PayPalReview = ppReview;

                return View("CheckoutReviewOrder");
            }
            else
            {
                return View("CheckoutError");
            }
        }