예제 #1
0
        public async Task <bool> CreateOrUpdatePaymentIntent(string userId)
        {
            StripeConfiguration.ApiKey = _config["StripeSettings:SecretKey"];

            var carts = await _cartItemService.GetAll(userId);

            if (carts.Count == 0)
            {
                return(false);
            }

            var service = new PaymentIntentService();

            int amount = 0;

            foreach (var item in carts)
            {
                amount += item.Quantity + item.ProductDetail.Product.Price;
            }


            var options = new PaymentIntentCreateOptions
            {
                Amount             = amount * 100,
                Currency           = "usd",
                PaymentMethodTypes = new List <string> {
                    "card"
                }
            };
            await service.CreateAsync(options);


            return(true);
        }
예제 #2
0
        public IActionResult Get()
        {
            var cartItems    = _cartItemService.GetAll();
            var cartItemDtos = _mapper.Map <IList <CartItemDto> >(cartItems);

            return(Ok(cartItemDtos));
        }
예제 #3
0
        public async Task <ActionResult <CartItem> > GetAll()
        {
            var userId = HttpContext.User.Identity.Name;

            var order = await _cartItemService.GetAll(userId);

            return(Ok(order));
        }
예제 #4
0
        public IActionResult GetAll()
        {
            var result = _cartItemService.GetAll();

            if (result.Success)
            {
                return(Ok());
            }
            return(BadRequest());
        }
        public void GetCartItemsInvokesCartItemRepo_WhenGettingCartItems()
        {
            // Arrange
            _cartService = new CartItemService(_cartItemRepository);

            // Act
            var items = _cartService.GetAll();

            // Assert
            Mock.Get(_cartItemRepository).Verify(pr => pr.GetCartItems(), Times.Once);
        }
 public IActionResult GetAll()
 {
     return(Ok(cartItemService.GetAll()));
 }