Browse Source

Improved OrderPaymentChecker

pull/49/head
gdlcf88 6 years ago
parent
commit
efb229e552
  1. 2
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/IOrderPaymentChecker.cs
  2. 25
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentChecker.cs
  3. 2
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCompletedEventHandler.cs
  4. 2
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCreatedEventHandler.cs

2
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/IOrderPaymentChecker.cs

@ -5,6 +5,6 @@ namespace EasyAbp.EShop.Orders.Orders
{ {
public interface IOrderPaymentChecker public interface IOrderPaymentChecker
{ {
Task<bool> IsValidPaymentAsync(Order order, PaymentEto paymentEto); Task<bool> IsValidPaymentAsync(Order order, PaymentEto payment, PaymentItemEto paymentItem);
} }
} }

25
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentChecker.cs

@ -8,12 +8,27 @@ namespace EasyAbp.EShop.Orders.Orders
{ {
public class OrderPaymentChecker : IOrderPaymentChecker, ITransientDependency public class OrderPaymentChecker : IOrderPaymentChecker, ITransientDependency
{ {
public Task<bool> IsValidPaymentAsync(Order order, PaymentEto paymentEto) public virtual async Task<bool> IsValidPaymentAsync(Order order, PaymentEto payment, PaymentItemEto paymentItem)
{ {
return Task.FromResult( return await IsStoreIdCorrectAsync(order, payment) &&
Guid.TryParse(paymentEto.GetProperty<string>("StoreId"), out var paymentStoreId) && await IsPaymentPriceCorrectAsync(order, paymentItem) &&
order.StoreId == paymentStoreId await IsUserAllowedToPayAsync(order, payment);
); }
protected virtual Task<bool> IsStoreIdCorrectAsync(Order order, PaymentEto payment)
{
return Task.FromResult(Guid.TryParse(payment.GetProperty<string>("StoreId"), out var paymentStoreId) &&
order.StoreId == paymentStoreId);
}
protected virtual Task<bool> IsPaymentPriceCorrectAsync(Order order, PaymentItemEto paymentItem)
{
return Task.FromResult(order.TotalPrice == paymentItem.OriginalPaymentAmount);
}
protected virtual Task<bool> IsUserAllowedToPayAsync(Order order, PaymentEto payment)
{
return Task.FromResult(order.CustomerUserId == payment.UserId);
} }
} }
} }

2
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCompletedEventHandler.cs

@ -43,7 +43,7 @@ namespace EasyAbp.EShop.Orders.Orders
var order = await _orderRepository.FindAsync(item.ItemKey); var order = await _orderRepository.FindAsync(item.ItemKey);
if (order == null || order.PaidTime.HasValue || if (order == null || order.PaidTime.HasValue ||
!await _orderPaymentChecker.IsValidPaymentAsync(order, eventData.Entity)) !await _orderPaymentChecker.IsValidPaymentAsync(order, eventData.Entity, item))
{ {
continue; continue;
} }

2
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCreatedEventHandler.cs

@ -34,7 +34,7 @@ namespace EasyAbp.EShop.Orders.Orders
var order = await _orderRepository.FindAsync(item.ItemKey); var order = await _orderRepository.FindAsync(item.ItemKey);
if (order == null || order.PaymentId.HasValue || if (order == null || order.PaymentId.HasValue ||
!await _orderPaymentChecker.IsValidPaymentAsync(order, eventData.Entity)) !await _orderPaymentChecker.IsValidPaymentAsync(order, eventData.Entity, item))
{ {
continue; continue;
} }

Loading…
Cancel
Save