コード例 #1
0
        public async Task <OrderCreatedViewModel> CreateOrder(CheckOutInfoInput checkOutInfoInput)
        {
            var basket = await _basketService.Get();

            var paymentInfoInput = new PaymentInfoInput()
            {
                CardName   = checkOutInfoInput.CardName,
                CardNumber = checkOutInfoInput.CardNumber,
                Expiration = checkOutInfoInput.Expiration,
                CVV        = checkOutInfoInput.CVV,
                TotalPrice = basket.TotalPrice
            };

            var responsePayment = await _paymentService.ReceivePayment(paymentInfoInput);

            if (!responsePayment)
            {
                return(new OrderCreatedViewModel()
                {
                    Error = "Ödeme alınamadı.", IsSuccessful = false
                });
            }

            var orderCreateInput = new OrderCreateInput()
            {
                BuyerId = _sharedIdentityService.GetUserId,
                Address = new AddressCreateInput {
                    Province = checkOutInfoInput.Province, District = checkOutInfoInput.District, Street = checkOutInfoInput.Street, Line = checkOutInfoInput.Line, ZipCode = checkOutInfoInput.ZipCode
                },
            };

            basket.BasketItems.ForEach(x =>
            {
                var orderItem = new OrderItemCreateInput {
                    ProductId = x.CourseId, Price = x.GetCurrentPrice, PictureUrl = "", ProductName = x.CourseName
                };
                orderCreateInput.OrderItems.Add(orderItem);
            });

            var response = await _httpClient.PostAsJsonAsync <OrderCreateInput>("orders", orderCreateInput);

            if (!response.IsSuccessStatusCode)
            {
                return(new OrderCreatedViewModel()
                {
                    Error = "Sipariş oluşturulamadı", IsSuccessful = false
                });
            }

            var orderCreatedViewModel = await response.Content.ReadFromJsonAsync <Response <OrderCreatedViewModel> >();

            orderCreatedViewModel.Data.IsSuccessful = true;
            await _basketService.Delete();

            return(orderCreatedViewModel.Data);
        }
コード例 #2
0
        public async Task <OrderSuspendViewModel> SuspendOrder(CheckOutInfoInput checkOutInfoInput)
        {
            var basket = await _basketService.Get();

            var orderCreateInput = new OrderCreateInput()
            {
                BuyerId = _sharedIdentityService.GetUserId,
                Address = new AddressCreateInput {
                    Province = checkOutInfoInput.Province, District = checkOutInfoInput.District, Street = checkOutInfoInput.Street, Line = checkOutInfoInput.Line, ZipCode = checkOutInfoInput.ZipCode
                },
            };

            basket.BasketItems.ForEach(x =>
            {
                var orderItem = new OrderItemCreateInput {
                    ProductId = x.CourseId, Price = x.GetCurrentPrice, PictureUrl = "", ProductName = x.CourseName
                };
                orderCreateInput.OrderItems.Add(orderItem);
            });


            var paymentInfoInput = new PaymentInfoInput()
            {
                CardName   = checkOutInfoInput.CardName,
                CardNumber = checkOutInfoInput.CardNumber,
                Expiration = checkOutInfoInput.Expiration,
                CVV        = checkOutInfoInput.CVV,
                TotalPrice = basket.TotalPrice,
                Order      = orderCreateInput
            };

            var responsePayment = await _paymentService.ReceivePayment(paymentInfoInput);

            if (!responsePayment)
            {
                return(new OrderSuspendViewModel()
                {
                    Error = "Ödeme alınamadı.", IsSuccessful = false
                });
            }

            await _basketService.Delete();

            return(new OrderSuspendViewModel()
            {
                IsSuccessful = true
            });
        }