public async Task <OrderModel> CreateOrderAsync(OrderParams orderParams) { if (orderParams.PaymentMethod == PaymentContants.PayPal) { var order = OrderModel.FromParams(orderParams); order.Seller = await usersRepository.GetUserPrivateAsync(order.SellerId); order.PaymentReceiver = order.Seller.PayPalEmail; order.Currency = order.Seller.PayPalCurrency; order.Status = PaymentContants.PendingStatus; foreach (var itemParams in orderParams.Items) { var item = OrderItemModel.FromParams(itemParams); item.Product = await productsRepository.GetProductAsync(item.ProductId, order.BuyerId); if (item.Product == null) { return(null); } if (order.SellerId != item.Product.SellerId) { return(null); } if (item.Product.Customer != null) { return(null); } item.ProductName = item.Product.Name; item.Price = item.Product.Price; order.TotalPrice += item.Price; order.Items.Add(item); } order = await ordersRepository.AddOrderAsync(order); payPalService.PayPalPayment(order, orderParams.BaseUrl); await ordersRepository.UpdateOrderPaymentUrlAsync(order); return(order); } return(null); }