public IActionResult SummaryPost(string stripeToken, ShoppingCartViewModel shoppingCartVMFromView) { var currentUserName = _httpContextAccessor.HttpContext.User.Identity.Name; //if the user is already logged in if (currentUserName != null) { var currentUser = _unitOfWork.ApplicationUser .GetFirstOrDefault(u => u.UserName == currentUserName, "Company"); var shoppingCartViewModel = new ShoppingCartViewModel() { ListOfProductsInCart = _unitOfWork.ShoppingCart .GetAll(cart => cart.ApplicationUserId == currentUser.Id, null, "Product"), OrderHeader = new OrderHeader() }; shoppingCartViewModel.OrderHeader.ApplicationUser = currentUser; shoppingCartViewModel.OrderHeader.PaymentStatus = GlobalUti.PaymentStatusPending; shoppingCartViewModel.OrderHeader.OrderStatus = GlobalUti.StatusPending; shoppingCartViewModel.OrderHeader.ApplicationUserId = currentUser.Id; shoppingCartViewModel.OrderHeader.OrderDate = DateTime.Now; shoppingCartViewModel.OrderHeader.Name = shoppingCartVMFromView.OrderHeader.Name; shoppingCartViewModel.OrderHeader.PhoneNumber = shoppingCartVMFromView.OrderHeader.PhoneNumber; shoppingCartViewModel.OrderHeader.StreetAddress = shoppingCartVMFromView.OrderHeader.StreetAddress; shoppingCartViewModel.OrderHeader.City = shoppingCartVMFromView.OrderHeader.City; shoppingCartViewModel.OrderHeader.State = shoppingCartVMFromView.OrderHeader.State; shoppingCartViewModel.OrderHeader.PostalCode = shoppingCartVMFromView.OrderHeader.PostalCode; _unitOfWork.OrderHeader.Add(shoppingCartViewModel.OrderHeader); _unitOfWork.Save(); foreach (var productInCart in shoppingCartViewModel.ListOfProductsInCart) { productInCart.Price = GlobalUti.GetPriceBasedOnQuantity(productInCart.Count, productInCart.Product.Price, productInCart.Product.Price50, productInCart.Product.Price100); var orderDetail = new OrderDetail() { ProductId = productInCart.Product.Id, OrderHeaderId = shoppingCartViewModel.OrderHeader.Id, Price = productInCart.Price, Count = productInCart.Count }; shoppingCartViewModel.OrderHeader.OrderTotal = Math.Round(orderDetail.Price * orderDetail.Count, 2); _unitOfWork.OrderDetail.Add(orderDetail); } _unitOfWork.ShoppingCart.RemoveRange(shoppingCartViewModel.ListOfProductsInCart); _httpContextAccessor.HttpContext.Session.SetString(GlobalUti.ShoppingCartSession, "0"); if (stripeToken != null) { // var options = new ChargeCreateOptions() // { // Amount = Convert.ToInt32(shoppingCartViewModel.OrderHeader.OrderTotal * 100), // Currency = "aud", // Description = "Order ID: " + shoppingCartViewModel.OrderHeader.Id, // Source = stripeToken // }; // // var service = new ChargeService(); // var charge = service.Create(options); // // if (charge.BalanceTransactionId == null) // shoppingCartViewModel.OrderHeader.PaymentStatus = GlobalUti.PaymentStatusRejected; // else // { shoppingCartViewModel.OrderHeader.PaymentStatus = GlobalUti.PaymentStatusApproved; shoppingCartViewModel.OrderHeader.TransactionId = "HardCodeBalanceTransactionId"; // shoppingCartViewModel.OrderHeader.TransactionId = charge.BalanceTransactionId; // } // // if (charge.Status.ToLower() == "succeeded") // { shoppingCartViewModel.OrderHeader.OrderStatus = GlobalUti.StatusApproved; shoppingCartViewModel.OrderHeader.PaymentDate = DateTime.Now; // } } else { //order will be created for authorised company shoppingCartViewModel.OrderHeader.PaymentDueDate = DateTime.Now.AddDays(30); shoppingCartViewModel.OrderHeader.PaymentStatus = GlobalUti.PaymentStatusDelayedPayment; shoppingCartViewModel.OrderHeader.OrderStatus = GlobalUti.StatusApproved; } _unitOfWork.Save(); return(RedirectToAction("OrderConfirmation", "ShoppingCart", new { id = shoppingCartViewModel.OrderHeader.Id })); } //if user is not logged in return(RedirectToAction("OrderConfirmation", "ShoppingCart")); }