Browse Source

updated order manager with order completion progress

still missing payment token update
pull/53/head
Galip Tolga Erdem 5 years ago
parent
commit
e1423bef46
  1. 3
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/en.json
  2. 3
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/Localization/OrderingService/tr.json
  3. 21
      services/ordering/src/EShopOnAbp.OrderingService.Domain.Shared/OrderingServiceErrorCodes.cs
  4. 12
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs
  5. 18
      services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/OrderManager.cs
  6. 5
      services/ordering/src/EShopOnAbp.OrderingService.Domain/PaymentRequests/PaymentRequestEventHandler.cs

3
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!"
}
}

3
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ı!"
}
}

21
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";
}

12
services/ordering/src/EShopOnAbp.OrderingService.Domain/Orders/Order.cs

@ -22,6 +22,7 @@ public class Order : AggregateRoot<Guid>
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<Guid>
OrderItems = new List<OrderItem>();
}
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<Guid>
var orderItem = new OrderItem(productId, productName, productCode, unitPrice, discount, pictureUrl, units);
OrderItems.Add(orderItem);
}
return this;
}
public decimal GetTotal()

18
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<Order> 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()

5
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<PaymentRequestCompletedEto>,
public class PaymentRequestEventHandler : IDistributedEventHandler<PaymentRequestCompletedEto>,
ITransientDependency
{
private readonly IDistributedEventBus _eventBus;
@ -42,4 +41,4 @@ namespace EShopOnAbp.OrderingService.PaymentRequests
};
}
}
}
}
Loading…
Cancel
Save