diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json index 84aad32a..c37a8dab 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json @@ -7,6 +7,7 @@ "Ordering:00011": "Possible values for Payment types: {0}", "Ordering:00002": "Invalid number of units", "Ordering:00003": "Invalid discount", - "Ordering:00004": "The total of order item is lower than applied discount" + "Ordering:00004": "The total of order item is lower than applied discount", + "Ordering:01001": "Order with {0} id could not be found!" } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json index 14f3eea7..8c6099ad 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json @@ -7,6 +7,7 @@ "Ordering:00011": "Muhtemel Ödeme türleri: {0}", "Ordering:00002": "Ürün adedi negatif olamaz", "Ordering:00003": "Geçersiz indirim", - "Ordering:00004": "Ürünlerin toplam bedeli, uygulanan indirimden daha az olamaz" + "Ordering:00004": "Ürünlerin toplam bedeli, uygulanan indirimden daha az olamaz", + "Ordering:01001": "{0} ID numaralı ürün bulunamadı!" } } \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs index f4ab7c19..08f9a0e0 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs @@ -1,12 +1,11 @@ -namespace EShopOnAbp.OrderingService +namespace EShopOnAbp.OrderingService; + +public static class OrderingServiceErrorCodes { - public static class OrderingServiceErrorCodes - { - public const string OrderingStatusNotFound = "Ordering:00001"; - public const string PaymentTypeNotFound = "Ordering:00011"; - public const string InvalidUnits = "Ordering:00002"; - public const string InvalidDiscount = "Ordering:00003"; - public const string InvalidTotalForDiscount = "Ordering:00004"; - - } -} + public const string OrderingStatusNotFound = "Ordering:00001"; + public const string PaymentTypeNotFound = "Ordering:00011"; + public const string InvalidUnits = "Ordering:00002"; + public const string InvalidDiscount = "Ordering:00003"; + public const string InvalidTotalForDiscount = "Ordering:00004"; + public const string OrderWithIdNotFound = "Ordering:01001"; +} \ No newline at end of file diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs index 6086847d..50e91850 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs @@ -22,6 +22,7 @@ public class Order : AggregateRoot internal Order(Guid id, Address address, Guid? buyerId = null, string paymentMethodToken = null) : base(id) { _orderStatusId = OrderStatus.Placed.Id; + OrderStatus = OrderStatus.Placed; OrderDate = DateTime.UtcNow; Address = address; BuyerId = buyerId; @@ -29,7 +30,14 @@ public class Order : AggregateRoot OrderItems = new List(); } - public void AddOrderItem(Guid productId, string productName, string productCode, decimal unitPrice, + internal Order SetOrderPaid() + { + OrderStatus = OrderStatus.Paid; + + return this; + } + + public Order AddOrderItem(Guid productId, string productName, string productCode, decimal unitPrice, decimal discount, string pictureUrl, int units = 1) { var existingOrderForProduct = OrderItems.SingleOrDefault(o => o.ProductId == productId); @@ -48,6 +56,8 @@ public class Order : AggregateRoot var orderItem = new OrderItem(productId, productName, productCode, unitPrice, discount, pictureUrl, units); OrderItems.Add(orderItem); } + + return this; } public decimal GetTotal() diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs index d5de4077..2007aca7 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Threading.Tasks; using EShopOnAbp.OrderingService.Buyers; +using Volo.Abp; using Volo.Abp.Domain.Services; using Volo.Abp.EventBus.Distributed; @@ -69,7 +70,7 @@ public class OrderManager : DomainService } var placedOrder = await _orderRepository.InsertAsync(order, true); - + // Publish Order placed event await _distributedEventBus.PublishAsync(new OrderPlacedEto { @@ -82,6 +83,21 @@ public class OrderManager : DomainService return placedOrder; } + public async Task AcceptOrderAsync(Guid orderId) + { + var order = await _orderRepository.GetAsync(orderId); + if (order == null) + { + throw new BusinessException(OrderingServiceErrorCodes.OrderWithIdNotFound) + .WithData("OrderId", orderId); + } + + //Update order.PaymentMethodToken + order.SetOrderPaid(); + + return await _orderRepository.UpdateAsync(order); + } + private BuyerEto GetBuyerEto(Buyer buyer) { return new BuyerEto() diff --git a/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs b/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs index 13c934b0..585eb993 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs @@ -9,8 +9,7 @@ using Volo.Abp.EventBus.Distributed; namespace EShopOnAbp.OrderingService.PaymentRequests { - public class PaymentRequestEventHandler : - IDistributedEventHandler, + public class PaymentRequestEventHandler : IDistributedEventHandler, ITransientDependency { private readonly IDistributedEventBus _eventBus; @@ -42,4 +41,4 @@ namespace EShopOnAbp.OrderingService.PaymentRequests }; } } -} +} \ No newline at end of file