public IActionResult Cart() { List <CartItem> cart = new List <CartItem>(); List <CartVm> cartVm = new List <CartVm>(); cart = HttpContext.Session.Get <List <CartItem> >("products"); if (cart == null) { return(RedirectToAction("Index")); } foreach (var item in cart) { var product = _context.Products.Include(p => p.ProductTypes).FirstOrDefault(c => c.Id == item.ProductId); var newCartVm = new CartVm(); newCartVm.ProductId = item.ProductId; newCartVm.Name = product.Name; newCartVm.Price = product.Price;; newCartVm.ProductColor = product.ProductColor; newCartVm.Type = product.ProductTypes.Type; newCartVm.Quantity = item.Quentity; newCartVm.Image = product.Image; cartVm.Add(newCartVm); } return(View(cartVm)); }
public ActionResult SatinAl(int id) { CartVm vm = new CartVm(); if (Request.Cookies.AllKeys.Contains("kart")) { vm = JsonConvert.DeserializeObject <CartVm>(Request.Cookies["kart"].Value); } Product product = db.Products.Find(id); vm.Products.Add(product); vm.Count = vm.Products.Count; if (vm.Promocode != null && vm.Promocode == "galip50") { vm.TotalPrice = vm.Products.Sum(x => x.Price) * 0.5m; } else { vm.TotalPrice = vm.Products.Sum(x => x.Price); } string json = JsonConvert.SerializeObject(vm); HttpCookie kart = new HttpCookie("kart", json); kart.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(kart); ViewBag.Sayi = vm.Products.Count; return(Json(id)); }
// TODO: separate getting product thumbnail, varation options from here public async Task <CartVm> GetCart(long userId) { var cart = _cartRepository.Query().Include(x => x.Items) .FirstOrDefault(x => x.UserId == userId && x.IsActive); if (cart is null) { return(new CartVm()); } var cartVm = new CartVm { Id = cart.Id, ShippingAmount = cart.ShippingAmount, Items = _cartItemRepository .Query() .Include(x => x.Product).ThenInclude(x => x.ThumbnailImage) .Where(x => x.CartId == cart.Id) .Select(x => new CartItemVm { Id = x.Id, ProductId = x.ProductId, ProductName = x.Product.Name, ProductPrice = x.Product.Price, ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), Quantity = x.Quantity }).ToList() }; cartVm.SubTotal = cartVm.Items.Sum(x => x.Quantity * x.ProductPrice); return(cartVm); }
public IActionResult Index() { if (_currentUser.IsAuthenticated) { var cart = _cartService.GetCart(_currentUser.Id); List <ProductVm> products = _mapper.Map <List <Product>, List <ProductVm> >(_cartService.GetCartItems(cart.Id).ToList()); List <OrderItemsVm> orderItems = _mapper.Map <List <OrderItem>, List <OrderItemsVm> >(cart.OrderItems.ToList()); float total = 0; for (int i = 0; i < products.Count(); i++) { total += (float)products[i].Price * orderItems[i].Quantity; } CartVm model = new CartVm { Id = cart.Id, Products = products, OrderItems = orderItems, Total = total }; return(View("../Cart/Cart", model)); } else { return(RedirectToAction("Login", "Account")); } }
private Payment CreatePayment(CreditCardInfoFormVm request, Order order, CartVm cartVm, User currentUser) { var paymentRequest = CreatePaymentRequest(request, order, cartVm, currentUser); var options = GetIyzcioOptions(); return(Payment.Create(paymentRequest, options)); }
public IActionResult FinishOrder(int orderId) { var cart = _cartService.GetCart(_currentUser.Id); if (cart == null || cart.OrderItems.Count() == 0) { return(ForbiddenView()); } List <ProductVm> products = _mapper.Map <List <Product>, List <ProductVm> >(_cartService.GetCartItems(cart.Id).ToList()); List <OrderItemsVm> orderItems = _mapper.Map <List <OrderItem>, List <OrderItemsVm> >(cart.OrderItems.ToList()); float total = 0; for (int i = 0; i < products.Count(); i++) { total += (float)products[i].Price * orderItems[i].Quantity; } CartVm model = new CartVm { Id = cart.Id, Products = products, OrderItems = orderItems, Total = total }; FinishOrderVm finish = new FinishOrderVm { Cart = model, User = _mapper.Map <User, UserVm>(_userService.GetUserById(_currentUser.Id)) }; if (finish == null) { return(View()); } return(View("../Order/FinishOrder", finish)); }
// TODO separate getting product thumbnail, varation options from here public async Task <CartVm> GetActiveCartDetails(long customerId, long createdById) { var cart = await GetActiveCart(customerId, createdById); if (cart == null) { return(null); } var cartVm = new CartVm() { Id = cart.Id, CouponCode = cart.CouponCode, IsProductPriceIncludeTax = cart.IsProductPriceIncludeTax, TaxAmount = cart.TaxAmount, ShippingAmount = cart.ShippingAmount, OrderNote = cart.OrderNote }; cartVm.Items = _cartItemRepository .Query() .Include(x => x.Product).ThenInclude(p => p.ThumbnailImage) .Include(x => x.Product).ThenInclude(p => p.OptionCombinations).ThenInclude(o => o.Option) .Where(x => x.CartId == cart.Id) .Select(x => new CartItemVm { Id = x.Id, ProductId = x.ProductId, ProductName = x.Product.Name, ProductPrice = x.Product.Price, ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), Quantity = x.Quantity, VariationOptions = CartItemVm.GetVariationOption(x.Product) }).ToList(); cartVm.SubTotal = cartVm.Items.Sum(x => x.Quantity * x.ProductPrice); if (!string.IsNullOrWhiteSpace(cartVm.CouponCode)) { var cartInfoForCoupon = new CartInfoForCoupon { Items = cartVm.Items.Select(x => new CartItemForCoupon { ProductId = x.ProductId, Quantity = x.Quantity }).ToList() }; var couponValidationResult = await _couponService.Validate(customerId, cartVm.CouponCode, cartInfoForCoupon); if (couponValidationResult.Succeeded) { cartVm.Discount = couponValidationResult.DiscountAmount; } else { cartVm.CouponValidationErrorMessage = couponValidationResult.ErrorMessage; } } return(cartVm); }
public async Task <CartVm> CreateCart(CartVm cartVm) { var client = _request.SendAccessToken().Result; HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(cartVm), Encoding.UTF8, "application/json"); var response = await client.PostAsync(_configuration["BackendUrl:Default"] + "/api/Cart", httpContent); response.EnsureSuccessStatusCode(); return(await response.Content.ReadFromJsonAsync <CartVm>()); }
public async Task <IViewComponentResult> InvokeAsync() { var curentUser = await _workContext.GetCurrentUser(); var cart = await _cartService.GetActiveCartDetails(curentUser.Id); if (cart == null) { cart = new CartVm(_currencyService); } return(View(this.GetViewPath(), cart)); }
public ActionResult Listele() { if (Request.Cookies.AllKeys.Contains("kart")) { CartVm vm = JsonConvert.DeserializeObject <CartVm>(Request.Cookies["kart"].Value); return(Json(vm, JsonRequestBehavior.AllowGet)); } else { return(null); } }
// TODO separate getting product thumbnail, varation options from here public async Task <CartVm> GetCart(long userId) { var cart = _cartRepository.Query().FirstOrDefault(x => x.UserId == userId && x.IsActive); if (cart == null) { return(new CartVm()); } var cartVm = new CartVm() { Id = cart.Id, CouponCode = cart.CouponCode, TaxAmount = cart.TaxAmount, ShippingAmount = cart.ShippingAmount }; cartVm.Items = _cartItemRepository .Query() .Include(x => x.Product).ThenInclude(p => p.ThumbnailImage) .Include(x => x.Product).ThenInclude(p => p.OptionCombinations).ThenInclude(o => o.Option) .Where(x => x.CartId == cart.Id) .Select(x => new CartItemVm { Id = x.Id, ProductId = x.ProductId, ProductName = x.Product.Name, ProductPrice = x.Product.Price, ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), Quantity = x.Quantity, VariationOptions = CartItemVm.GetVariationOption(x.Product) }).ToList(); cartVm.SubTotal = cartVm.Items.Sum(x => x.Quantity * x.ProductPrice); if (!string.IsNullOrWhiteSpace(cartVm.CouponCode)) { var cartInfoForCoupon = new CartInfoForCoupon { Items = cartVm.Items.Select(x => new CartItemForCoupon { ProductId = x.ProductId, Quantity = x.Quantity }).ToList() }; var couponValidationResult = await _couponService.Validate(cartVm.CouponCode, cartInfoForCoupon); if (couponValidationResult.Succeeded) { cartVm.Discount = couponValidationResult.DiscountAmount; } } return(cartVm); }
public async Task <CartVm> CreateCart(CartVm cartVm) { //Send access token var client = _httpClientFactory.CreateClient(); //Send json with body HttpContent httpContent = new StringContent(JsonConvert.SerializeObject(cartVm), Encoding.UTF8, "application/json"); var response = await client.PostAsync(_configuration["BackendUrl:Default"] + "/api/Cart", httpContent); response.EnsureSuccessStatusCode(); return(await response.Content.ReadFromJsonAsync <CartVm>()); }
public async Task <IActionResult> List() { var currentUser = await _workContext.GetCurrentUser(); var cart = await _cartService.GetActiveCartDetails(currentUser.Id); if (cart == null) { cart = new CartVm(_currencyService); } return(Json(cart)); }
private bool ValidateRazorpay(CartVm cart) { if (_setting.Value.MinOrderValue.HasValue && _setting.Value.MinOrderValue.Value > cart.OrderTotal) { return(false); } if (_setting.Value.MaxOrderValue.HasValue && _setting.Value.MaxOrderValue.Value < cart.OrderTotal) { return(false); } return(true); }
public async Task <ActionResult <CartVm> > GetCartByUser(string userId) { var cart = await _context.Carts.Include(x => x.CartItems) .ThenInclude(x => x.Product).ThenInclude(x => x.Images).FirstOrDefaultAsync(x => x.UserId == userId); if (cart == null) { return(NotFound()); } var lstProduct = cart.CartItems.ToList(); var cartItemVms = new List <CartItemVm>(); var c = new ProductVm(); foreach (var x in lstProduct.ToList()) { var cartItemVm = new CartItemVm(); var lstImage = new List <string>(); c = new ProductVm { CategoryId = x.Product.CategoryId, Description = x.Product.Description, Id = x.Product.Id, Inventory = x.Product.Inventory, Name = x.Product.Name, Price = x.Product.Price, }; foreach (var y in x.Product.Images.ToList()) { lstImage.Add(y.ImagePath.ToString()); } c.ImageLocation = lstImage; cartItemVm.Quantity = x.Quantity; cartItemVm.productVm = c; cartItemVms.Add(cartItemVm); } var cartVm = new CartVm { Id = cart.Id, TotalPrice = cart.TotalPrice, UserId = cart.UserId, cartItemVms = cartItemVms }; return(cartVm); }
public async Task <ActionResult <CartVm> > GetCartById(int id) { var cart = await _context.Carts.FindAsync(id); if (cart == null) { return(NotFound()); } var lstProduct = cart.CartItems.ToList(); var lstImage = new List <string>(); var cartItemVms = new List <CartItemVm>(); var cartItemVm = new CartItemVm(); foreach (var x in lstProduct) { var c = new ProductVm { CategoryId = x.Product.CategoryId, Description = x.Product.Description, Id = x.Id, Inventory = x.Product.Inventory, Name = x.Product.Name, Price = x.Product.Price, }; foreach (var y in c.ImageLocation) { lstImage.Add(y); } c.ImageLocation = lstImage; cartItemVm.productVm = c; cartItemVms.Add(cartItemVm); } var cartVm = new CartVm { Id = cart.Id, TotalPrice = cart.TotalPrice, UserId = cart.UserId, cartItemVms = cartItemVms }; return(cartVm); }
public async Task <IActionResult> AddToCart(int id) { var product = await _productApiClient.GetById(id); var cartSession = HttpContext.Session.GetString(Constants.CartSession); List <CartVm> currentCart = new List <CartVm>(); if (cartSession != null) { currentCart = JsonConvert.DeserializeObject <List <CartVm> >(cartSession); } int quantity = 1; if (currentCart.Any(x => x.ProductId == id)) { quantity = currentCart.First(x => x.ProductId == id).Quantity + 1; var item = currentCart.Where(x => x.ProductId == id).FirstOrDefault(); item.ProductId = product.Id; item.Name = product.Name; item.OriginalPrice = product.OriginalPrice; item.Price = product.Price; item.Quantity = quantity; item.ThumbnailImage = _config[Constants.AppSettings.BaseAddress] + "/user-content/" + product.ThumbnailImage.First().Url; } else { var cartVm = new CartVm() { ProductId = id, Name = product.Name, OriginalPrice = product.OriginalPrice, Price = product.Price, Quantity = quantity, ThumbnailImage = _config[Constants.AppSettings.BaseAddress] + "/user-content/" + product.ThumbnailImage.First().Url }; currentCart.Add(cartVm); } HttpContext.Session.SetString(Constants.CartSession, JsonConvert.SerializeObject(currentCart)); return(Ok(currentCart)); }
public ActionResult Indirim(string kod) { string promoCode = "galip50"; CartVm vm = JsonConvert.DeserializeObject <CartVm>(Request.Cookies["kart"].Value); if (kod == promoCode && vm.Promocode == null && vm.Products.Count > 0) { vm.Promocode = kod; vm.TotalPrice = vm.TotalPrice - (vm.TotalPrice * 0.5m); string json = JsonConvert.SerializeObject(vm); HttpCookie kart = new HttpCookie("kart", json); kart.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(kart); return(Json(vm)); } else { return(null); } }
public async Task <ActionResult <CartVm> > CreateCart(CartVm cartVm) { List <CartItem> lstProducts = new(); foreach (var x in cartVm.cartItemVms.ToList()) { var pVm = new CartItem(); pVm.Product.CategoryId = x.productVm.CategoryId; pVm.Product.Description = x.productVm.Description; pVm.Product.Id = x.Id; pVm.Product.Inventory = x.productVm.Inventory; pVm.Product.Name = x.productVm.Name; pVm.Product.Price = x.productVm.Price; lstProducts.Add(pVm); } var cart = new Cart { CartItems = lstProducts, Id = cartVm.Id, TotalPrice = cartVm.TotalPrice, UserId = cartVm.UserId }; _context.Carts.Add(cart); await _context.SaveChangesAsync(); return(CreatedAtAction("Get", new { id = cart.Id }, new CartVm { Id = cart.Id, UserId = cart.UserId, TotalPrice = cart.TotalPrice, cartItemVms = cartVm.cartItemVms })); }
public IActionResult CheckOut() { List <CartItem> cart = HttpContext.Session.Get <List <CartItem> >("products"); List <CartVm> cartVms = new List <CartVm>(); if (cart != null) { foreach (var item in cart) { CartVm vm = new CartVm(); var product = _context.Products.FirstOrDefault(c => c.Id == item.ProductId); vm.Name = product.Name; vm.Price = product.Price; vm.Image = product.Image; vm.Quantity = item.Quentity; cartVms.Add(vm); } ViewBag.Product = cartVms; } return(View()); }
public CartVm DataCarrito() { //GetStructCarrito(GetIP(), GetSession()); var blc = RecuperaTotalCarrito(GetIP(), GetSession()); var todas = RecuperatodasLineasCarrito(GetIP(), GetSession()); Random r = new Random(); // int totalLineas = int.Parse(blc.totallines); var cartVm = new CartVm(_currencyService) { Id = r.Next(0, 60000), //int.Parse(DateTime.Now.ToString()), IsProductPriceIncludeTax = true //TaxAmount = cart.TaxAmount, //ShippingAmount = cart.ShippingAmount, //OrderNote = cart.OrderNote }; foreach (CartLine ln in todas.result) { CartItemVm civ = new CartItemVm(_currencyService); civ.Id = long.Parse(ln.line.ToString()); civ.ProductId = long.Parse(ln.identifier); var arti = RecuperaArtículo(GetIP(), GetSession(), civ.ProductId); int sta = 0; _ = int.TryParse(arti.result.stocks, out sta); civ.ProductStockQuantity = decimal.ToInt32(decimal.Parse(arti.result.stocks.Replace(".", ","))); civ.ProductName = ln.description; civ.ProductPrice = decimal.Parse(ln.pricewithtax.Replace(".", ",")); civ.IsProductAvailabeToOrder = true; civ.ProductStockTrackingIsEnabled = false; //Core.Models.Media pti = new ProductThumbnail().; civ.ProductImage = ln.imagesmall; civ.Quantity = decimal.ToInt32(decimal.Parse(ln.quantity)); cartVm.Items.Add(civ); } cartVm.SubTotal = decimal.Parse(blc.totalwithtax.Replace(".", ",")); cartVm.Discount = 0; return(cartVm); }
public async Task <IViewComponentResult> InvokeAsync() { var curentUser = await _workContext.GetCurrentUser(); //aqui cargamos datacarrito var cart2 = await _cartService.GetActiveCartDetails(curentUser.Id); var cart = DataCarrito(); if (cart != null && cart2 != null) { if (cart.Items.Count == cart2.Items.Count) { decimal totalcarrito = decimal.Zero; decimal totalcart = decimal.Zero; foreach (CartItemVm ci in cart.Items) { totalcarrito += (ci.ProductPrice * ci.Quantity); } foreach (CartItemVm ci in cart2.Items) { var p = RecuperaArtículo(GetIP(), GetSession(), ci.ProductId); totalcart += (decimal.Parse(p.result.pricewithtax.Replace(".", ",")) * ci.Quantity); } if (totalcart != totalcarrito) { cart.SubTotal = totalcarrito; } cart.ShippingAmount = cart2.ShippingAmount; } } if (cart2 == null) { cart2 = new CartVm(_currencyService); } return(View(this.GetViewPath(), cart)); }
public ActionResult Sil(int id) { CartVm vm = JsonConvert.DeserializeObject <CartVm>(Request.Cookies["kart"].Value); Product product = db.Products.Find(id); Product deletedProduct = vm.Products.Where(x => x.Id == product.Id).FirstOrDefault(); vm.Products.Remove(deletedProduct); vm.Count = vm.Products.Count; if (vm.Promocode != null && vm.Promocode == "galip50") { vm.TotalPrice = vm.Products.Sum(x => x.Price) * 0.5m; } else { vm.TotalPrice = vm.Products.Sum(x => x.Price); } //vm.TotalPrice -= product.Price; string json = JsonConvert.SerializeObject(vm); HttpCookie kart = new HttpCookie("kart", json); kart.Expires = DateTime.Now.AddDays(7); Response.Cookies.Add(kart); return(Json(vm)); }
// TODO separate getting product thumbnail, varation options from here public async Task <CartVm> GetActiveCartDetails(long customerId, long createdById) { //var carrito = DataCarrito(); //if (carrito == null) //{ // return null; //} //else { // return carrito; //} // datos del carrito se cargan aqui var cart = await GetActiveCart(customerId, createdById); if (cart == null) { return(null); } var cartVm = new CartVm(_currencyService) { Id = cart.Id, CouponCode = cart.CouponCode, IsProductPriceIncludeTax = cart.IsProductPriceIncludeTax, TaxAmount = cart.TaxAmount, ShippingAmount = cart.ShippingAmount, OrderNote = cart.OrderNote }; //tenemos que cargar aqui los datos del carrito, tenemos la ID de los productos en el Cart.Items // recorremos el array. cartVm.Items = _cartItemRepository .Query() .Where(x => x.CartId == cart.Id).ToList() .Select(x => new CartItemVm(_currencyService) { Id = x.Id, ProductId = x.ProductId, // ProductName = x.Product.Name, //ProductPrice = x.Product.Price, //ProductStockQuantity = x.Product.StockQuantity, //ProductStockTrackingIsEnabled = x.Product.StockTrackingIsEnabled, //IsProductAvailabeToOrder = x.Product.IsAllowToOrder && x.Product.IsPublished && !x.Product.IsDeleted, Quantity = x.Quantity }).ToList(); //codigo origen //cartVm.Items = _cartItemRepository // .Query() // .Include(x => x.Product).ThenInclude(p => p.ThumbnailImage) // .Include(x => x.Product).ThenInclude(p => p.OptionCombinations).ThenInclude(o => o.Option) // .Where(x => x.CartId == cart.Id).ToList() // .Select(x => new CartItemVm(_currencyService) // { // Id = x.Id, // ProductId = x.ProductId, // ProductName = x.Product.Name, // ProductPrice = x.Product.Price, // ProductStockQuantity = x.Product.StockQuantity, // ProductStockTrackingIsEnabled = x.Product.StockTrackingIsEnabled, // IsProductAvailabeToOrder = x.Product.IsAllowToOrder && x.Product.IsPublished && !x.Product.IsDeleted, // ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), // Quantity = x.Quantity, // VariationOptions = CartItemVm.GetVariationOption(x.Product) // }).ToList(); cartVm.SubTotal = cartVm.Items.Sum(x => x.Quantity * x.ProductPrice); if (!string.IsNullOrWhiteSpace(cartVm.CouponCode)) { var cartInfoForCoupon = new CartInfoForCoupon { Items = cartVm.Items.Select(x => new CartItemForCoupon { ProductId = x.ProductId, Quantity = x.Quantity }).ToList() }; var couponValidationResult = await _couponService.Validate(customerId, cartVm.CouponCode, cartInfoForCoupon); if (couponValidationResult.Succeeded) { cartVm.Discount = couponValidationResult.DiscountAmount; } else { cartVm.CouponValidationErrorMessage = couponValidationResult.ErrorMessage; } } return(cartVm); }
private CreatePaymentRequest CreatePaymentRequest(CreditCardInfoFormVm request, Order order, CartVm cartVm, User currentUser) { var paymentRequest = new CreatePaymentRequest { Locale = Locale.TR.ToString(), ConversationId = "123456789", Price = Convert.ToString(cartVm.OrderTotal), PaidPrice = "0", Currency = Currency.TRY.ToString(), Installment = 1, BasketId = order.Id.ToString(), PaymentChannel = PaymentChannel.WEB.ToString(), PaymentGroup = PaymentGroup.PRODUCT.ToString(), }; var paymentCard = new PaymentCard { CardHolderName = request.CardHolderName, CardNumber = request.CardNumber, ExpireMonth = request.ExpiryMonth.ToString(), ExpireYear = request.ExpiryYear.ToString(), Cvc = request.Cvv.ToString(), RegisterCard = 0 }; paymentRequest.PaymentCard = paymentCard; var buyer = new Buyer { Id = currentUser.Id.ToString(), Name = order.BillingAddress.ContactName, Surname = order.BillingAddress.LastName, GsmNumber = currentUser.PhoneNumber, Email = currentUser.Email, IdentityNumber = order.BillingAddress.TaxId.ToString(), RegistrationDate = currentUser.CreatedOn.Date.ToString(), Ip = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(), City = order.BillingAddress.City, Country = "Turkey", ZipCode = order.BillingAddress.PostalCode }; paymentRequest.Buyer = buyer; var shippingAddress = new Address { ContactName = order.ShippingAddress.ContactName, City = order.ShippingAddress.City, Country = "Turkey", Description = $"{order.ShippingAddress.AddressLine1} {order.ShippingAddress.AddressLine2} {order.ShippingAddress.District} {order.ShippingAddress.City}", ZipCode = order.ShippingAddress.PostalCode }; paymentRequest.ShippingAddress = shippingAddress; var billingAddress = new Address { ContactName = order.BillingAddress.ContactName, City = order.BillingAddress.City, Country = "Turkey", Description = $"{order.BillingAddress.AddressLine1} {order.BillingAddress.AddressLine2} {order.BillingAddress.District} {order.BillingAddress.City}", ZipCode = order.ShippingAddress.PostalCode }; paymentRequest.BillingAddress = billingAddress; foreach (var orderItem in order.OrderItems) { var productCategory = _productCategoryRepository.Query().FirstOrDefault(f => f.ProductId == orderItem.ProductId); var category = _categoryRepository.Query().FirstOrDefault(f => f.Id == productCategory.CategoryId); paymentRequest.BasketItems.Add(new BasketItem { Id = orderItem.Id.ToString(), Name = orderItem.Product.Name, Category1 = category.Name, ItemType = BasketItemType.PHYSICAL.ToString(), Price = Convert.ToString(orderItem.ProductPrice) }); } paymentRequest.PaymentCard = paymentCard; return(paymentRequest); }
private CreatePaymentRequest Create3dPayment(CreditCardInfoFormVm request, Order order, CartVm cartVm, User currentUser) { var paymentRequest = CreatePaymentRequest(request, order, cartVm, currentUser); paymentRequest.CallbackUrl = new Uri($"{Request.Scheme}://{Request.Host}/iyzico/threeds").AbsolutePath; return(paymentRequest); }
private decimal CalculateFee(CartVm cart) { var percent = _setting.Value.PaymentFee; return((cart.OrderTotal / 100) * percent); }
public CartVm DataCarrito() { //GetStructCarrito(GetIP(), GetSession()); var blc = RecuperaTotalCarrito(GetIP(), GetSession()); var todas = RecuperatodasLineasCarrito(GetIP(), GetSession()); Random r = new Random(); // int totalLineas = int.Parse(blc.totallines); var cartVm = new CartVm(_currencyService) { Id = r.Next(0, 60000), //int.Parse(DateTime.Now.ToString()), IsProductPriceIncludeTax = true //TaxAmount = cart.TaxAmount, //ShippingAmount = cart.ShippingAmount, //OrderNote = cart.OrderNote }; foreach (CartLine ln in todas.result) { CartItemVm civ = new CartItemVm(_currencyService); civ.Id = long.Parse(ln.line.ToString()); civ.ProductId = long.Parse(ln.identifier); var arti = RecuperaArtículo(GetIP(), GetSession(), civ.ProductId); int sta = 0; _ = int.TryParse(arti.result.stocks, out sta); civ.ProductStockQuantity = decimal.ToInt32(decimal.Parse(arti.result.stocks)); civ.ProductName = ln.description; civ.ProductPrice = decimal.Parse(ln.pricewithtax.Replace(".", ",")); civ.IsProductAvailabeToOrder = true; civ.ProductStockTrackingIsEnabled = false; civ.linea = ln.line; //Core.Models.Media pti = new ProductThumbnail().; civ.ProductImage = ln.imagesmall; civ.Quantity = decimal.ToInt32(decimal.Parse(ln.quantity.Replace(".", ","))); // Id = x.Id, // ProductId = x.ProductId, // ProductName = x.Product.Name, // ProductPrice = x.Product.Price, // ProductStockQuantity = x.Product.StockQuantity, // ProductStockTrackingIsEnabled = x.Product.StockTrackingIsEnabled, // IsProductAvailabeToOrder = x.Product.IsAllowToOrder && x.Product.IsPublished && !x.Product.IsDeleted, // ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), // Quantity = x.Quantity, cartVm.Items.Add(civ); } cartVm.SubTotal = decimal.Parse(blc.totalwithtax.Replace(".", ",")); cartVm.Discount = 0; return(cartVm); //Datos esperados, los mismos que devuelve await _cartService.GetActiveCartDetails(currentUser.Id); //var cartVm = new CartVm(_currencyService) //{ // Id = cart.Id, // CouponCode = cart.CouponCode, // IsProductPriceIncludeTax = cart.IsProductPriceIncludeTax, // TaxAmount = cart.TaxAmount, // ShippingAmount = cart.ShippingAmount, // OrderNote = cart.OrderNote //}; //cartVm.Items = _cartItemRepository // .Query() // .Include(x => x.Product).ThenInclude(p => p.ThumbnailImage) // .Include(x => x.Product).ThenInclude(p => p.OptionCombinations).ThenInclude(o => o.Option) // .Where(x => x.CartId == cart.Id).ToList() // .Select(x => new CartItemVm(_currencyService) // { // Id = x.Id, // ProductId = x.ProductId, // ProductName = x.Product.Name, // ProductPrice = x.Product.Price, // ProductStockQuantity = x.Product.StockQuantity, // ProductStockTrackingIsEnabled = x.Product.StockTrackingIsEnabled, // IsProductAvailabeToOrder = x.Product.IsAllowToOrder && x.Product.IsPublished && !x.Product.IsDeleted, // ProductImage = _mediaService.GetThumbnailUrl(x.Product.ThumbnailImage), // Quantity = x.Quantity, // VariationOptions = CartItemVm.GetVariationOption(x.Product) // }).ToList(); //cartVm.SubTotal = cartVm.Items.Sum(x => x.Quantity * x.ProductPrice); //if (!string.IsNullOrWhiteSpace(cartVm.CouponCode)) //{ // var cartInfoForCoupon = new CartInfoForCoupon // { // Items = cartVm.Items.Select(x => new CartItemForCoupon { ProductId = x.ProductId, Quantity = x.Quantity }).ToList() // }; // var couponValidationResult = await _couponService.Validate(customerId, cartVm.CouponCode, cartInfoForCoupon); // if (couponValidationResult.Succeeded) // { // cartVm.Discount = couponValidationResult.DiscountAmount; // } // else // { // cartVm.CouponValidationErrorMessage = couponValidationResult.ErrorMessage; // } //} }