Exemple #1
0
        public IActionResult Cart()
        {
            var productsInCartViewModel = cartLogic.GetProductInCartAsViewModel(HttpContext.Session);


            return(View(productsInCartViewModel));
        }
Exemple #2
0
        public ProductsAndOrderInfoViewModel GetProductsAndOrderInfo(ISession session)
        {
            var productsInCart = cartLogic.GetProductInCartAsViewModel(session);

            if (productsInCart == null)
            {
                return(null);
            }

            var clientOrderInfo = GetClientOrderInfo(session);


            var ProductsAndClientOrderInfo = new ProductsAndOrderInfoViewModel
            {
                ClientOrderInformatiomViewModel = clientOrderInfo,
                ProductsInCartViewModel         = productsInCart
            };

            return(ProductsAndClientOrderInfo);
        }
Exemple #3
0
        public async Task <IActionResult> CreateCheckoutSession()
        {
            var products = cartLogic.GetProductInCartAsViewModel(HttpContext.Session);

            if (products == null)
            {
                RedirectToAction("Index", "Products");
            }

            var options = new SessionCreateOptions
            {
                PaymentMethodTypes = new List <string>
                {
                    "card",
                },

                LineItems  = new List <SessionLineItemOptions>(),
                Mode       = "payment",
                SuccessUrl = "https://example.com/success",
                CancelUrl  = "https://example.com/cancel",
            };

            foreach (var product in products)
            {
                options.LineItems.Add(new SessionLineItemOptions {
                    PriceData = new SessionLineItemPriceDataOptions
                    {
                        UnitAmountDecimal = product.ProductPrice * 100,
                        Currency          = "rub",
                        ProductData       = new SessionLineItemPriceDataProductDataOptions
                        {
                            Name        = product.ProductName,
                            Description = product.ProductDescription
                        },
                    },
                    Quantity = product.Quantity
                });
            }

            var     service = new SessionService();
            Session session = service.Create(options);

            var prodOrders = clientLogic.GetProductsAndOrderInfo(HttpContext.Session);

            await clientLogic.SaveOrder(new OrderInfoViewModel
            {
                AddressPrimary    = prodOrders.ClientOrderInformatiomViewModel.AddressPrimary,
                AddressSecondary  = prodOrders.ClientOrderInformatiomViewModel.AddressSecondary,
                City              = prodOrders.ClientOrderInformatiomViewModel.City,
                Country           = prodOrders.ClientOrderInformatiomViewModel.Country,
                EmailCustomer     = prodOrders.ClientOrderInformatiomViewModel.EmailCustomer,
                FirstNameCustomer = prodOrders.ClientOrderInformatiomViewModel.FirstNameCustomer,
                LastNameCustomer  = prodOrders.ClientOrderInformatiomViewModel.LastNameCustomer,
                OrderBuyerComment = prodOrders.ClientOrderInformatiomViewModel.OrderBuyerComment,
                PostCode          = prodOrders.ClientOrderInformatiomViewModel.PostCode,
                Stocks            = prodOrders.ProductsInCartViewModel.Select(x => new StockMinViewModel
                {
                    Quantity = x.Quantity,
                    StockId  = x.StockId
                }),
                StripeOrderRef = session.ClientReferenceId,
                SessionId      = HttpContext.Session.Id
            });



            return(Json(new { id = session.Id }));
        }