Browse Source

Check OrderLines and OrderExtraFees exist when refunding

pull/146/head
gdlcf88 4 years ago
parent
commit
e9573e936f
  1. 17
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/OrderExtraFeeNotFoundException.cs
  2. 14
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/OrderLineNotFoundException.cs
  3. 17
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs
  4. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/cs.json
  5. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/en.json
  6. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/pl.json
  7. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/pt-BR.json
  8. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/sl.json
  9. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/tr.json
  10. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/vi.json
  11. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/zh-Hans.json
  12. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/zh-Hant.json
  13. 2
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/PaymentsErrorCodes.cs
  14. 79
      modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Refunds/RefundAppServiceTests.cs

17
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/OrderExtraFeeNotFoundException.cs

@ -0,0 +1,17 @@
using System;
using JetBrains.Annotations;
using Volo.Abp;
namespace EasyAbp.EShop.Payments.Refunds
{
public class OrderExtraFeeNotFoundException : BusinessException
{
public OrderExtraFeeNotFoundException(Guid orderId, [NotNull] string name, [CanBeNull] string key) : base(
PaymentsErrorCodes.OrderExtraFeeNotFound)
{
WithData(nameof(orderId), orderId);
WithData(nameof(name), name);
WithData(nameof(key), key);
}
}
}

14
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/OrderLineNotFoundException.cs

@ -0,0 +1,14 @@
using System;
using Volo.Abp;
namespace EasyAbp.EShop.Payments.Refunds
{
public class OrderLineNotFoundException : BusinessException
{
public OrderLineNotFoundException(Guid orderId, Guid orderLineId) : base(PaymentsErrorCodes.OrderLineNotFound)
{
WithData(nameof(orderId), orderId);
WithData(nameof(orderLineId), orderLineId);
}
}
}

17
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs

@ -122,14 +122,29 @@ namespace EasyAbp.EShop.Payments.Refunds
foreach (var model in refundItem.OrderLines)
{
var orderLine = order.OrderLines.Single(x => x.Id == model.OrderLineId);
var orderLine = order.OrderLines.Find(x => x.Id == model.OrderLineId);
if (orderLine is null)
{
throw new OrderLineNotFoundException(order.Id, model.OrderLineId);
}
if (orderLine.RefundedQuantity + model.Quantity > orderLine.Quantity)
{
throw new InvalidRefundQuantityException(model.Quantity);
}
}
foreach (var model in refundItem.OrderExtraFees)
{
var orderExtraFee = order.OrderExtraFees.Find(x => x.Name == model.Name && x.Key == model.Key);
if (orderExtraFee is null)
{
throw new OrderExtraFeeNotFoundException(order.Id, model.Name, model.Key);
}
}
var eto = new CreateRefundItemInput
{
PaymentItemId = paymentItem.Id,

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/cs.json

@ -13,6 +13,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "Payment ({id}) has another ongoing refund task.",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "Refund amount ({refundAmount}) is invalid for the payment (id: {paymentId}, item id: {paymentItemId}).",
"EasyAbp.EShop.Payments:OrderIdNotFound": "Cannot get valid OrderId from ExtraProperties.",
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties."
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties.",
"EasyAbp.EShop.Payments:OrderLineNotFound": "There is no such an order line. (order ID: {orderId}, order line ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "There is no such an order extra fee. (order ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/en.json

@ -14,6 +14,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "Payment ({id}) has another ongoing refund task.",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "Refund amount ({refundAmount}) is invalid for the payment (id: {paymentId}, item id: {paymentItemId}).",
"EasyAbp.EShop.Payments:OrderIdNotFound": "Cannot get valid OrderId from ExtraProperties.",
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties."
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties.",
"EasyAbp.EShop.Payments:OrderLineNotFound": "There is no such an order line. (order ID: {orderId}, order line ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "There is no such an order extra fee. (order ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/pl.json

@ -13,6 +13,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "Payment ({id}) has another ongoing refund task.",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "Refund amount ({refundAmount}) is invalid for the payment (id: {paymentId}, item id: {paymentItemId}).",
"EasyAbp.EShop.Payments:OrderIdNotFound": "Cannot get valid OrderId from ExtraProperties.",
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties."
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties.",
"EasyAbp.EShop.Payments:OrderLineNotFound": "There is no such an order line. (order ID: {orderId}, order line ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "There is no such an order extra fee. (order ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/pt-BR.json

@ -13,6 +13,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "Payment ({id}) has another ongoing refund task.",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "Refund amount ({refundAmount}) is invalid for the payment (id: {paymentId}, item id: {paymentItemId}).",
"EasyAbp.EShop.Payments:OrderIdNotFound": "Cannot get valid OrderId from ExtraProperties.",
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties."
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties.",
"EasyAbp.EShop.Payments:OrderLineNotFound": "There is no such an order line. (order ID: {orderId}, order line ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "There is no such an order extra fee. (order ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/sl.json

@ -14,6 +14,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "Payment ({id}) has another ongoing refund task.",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "Refund amount ({refundAmount}) is invalid for the payment (id: {paymentId}, item id: {paymentItemId}).",
"EasyAbp.EShop.Payments:OrderIdNotFound": "Cannot get valid OrderId from ExtraProperties.",
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties."
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties.",
"EasyAbp.EShop.Payments:OrderLineNotFound": "There is no such an order line. (order ID: {orderId}, order line ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "There is no such an order extra fee. (order ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/tr.json

@ -14,6 +14,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "Payment ({id}) has another ongoing refund task.",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "Refund amount ({refundAmount}) is invalid for the payment (id: {paymentId}, item id: {paymentItemId}).",
"EasyAbp.EShop.Payments:OrderIdNotFound": "Cannot get valid OrderId from ExtraProperties.",
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties."
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties.",
"EasyAbp.EShop.Payments:OrderLineNotFound": "There is no such an order line. (order ID: {orderId}, order line ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "There is no such an order extra fee. (order ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/vi.json

@ -13,6 +13,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "Payment ({id}) has another ongoing refund task.",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "Refund amount ({refundAmount}) is invalid for the payment (id: {paymentId}, item id: {paymentItemId}).",
"EasyAbp.EShop.Payments:OrderIdNotFound": "Cannot get valid OrderId from ExtraProperties.",
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties."
"EasyAbp.EShop.Payments:StoreIdNotFound": "Cannot get valid StoreId from ExtraProperties.",
"EasyAbp.EShop.Payments:OrderLineNotFound": "There is no such an order line. (order ID: {orderId}, order line ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "There is no such an order extra fee. (order ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/zh-Hans.json

@ -14,6 +14,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "支付({id})存在进行中的退款任务",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "退款金额({refundAmount})对于支付(id: {paymentId}, item id: {paymentItemId})不正确",
"EasyAbp.EShop.Payments:OrderIdNotFound": "无法从ExtraProperties获得有效的OrderId",
"EasyAbp.EShop.Payments:StoreIdNotFound": "无法从ExtraProperties获得有效的StoreId"
"EasyAbp.EShop.Payments:StoreIdNotFound": "无法从ExtraProperties获得有效的StoreId",
"EasyAbp.EShop.Payments:OrderLineNotFound": "不存在的订单项 (订单ID: {orderId}, 订单项ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "不存在的订单项 (订单ID: {orderId}, name: {name}, key: {key})"
}
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/Localization/Payments/zh-Hant.json

@ -14,6 +14,8 @@
"EasyAbp.EShop.Payments:AnotherRefundTaskIsOnGoing": "支付({id})存在進行中的退款任務",
"EasyAbp.EShop.Payments:InvalidRefundAmount": "退款金額({refundAmount})對於支付(id: {paymentId}, item id: {paymentItemId})不正確",
"EasyAbp.EShop.Payments:OrderIdNotFound": "無法從ExtraProperties獲得有效的OrderId",
"EasyAbp.EShop.Payments:StoreIdNotFound": "無法從ExtraProperties獲得有效的StoreId"
"EasyAbp.EShop.Payments:StoreIdNotFound": "無法從ExtraProperties獲得有效的StoreId",
"EasyAbp.EShop.Payments:OrderLineNotFound": "不存在的訂單項 (訂單ID: {orderId}, 訂單項ID: {orderLineId})",
"EasyAbp.EShop.Payments:OrderExtraFeeNotFound": "不存在的訂單項 (訂單ID: {orderId}, name: {name}, key: {key})"
}
}

2
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/PaymentsErrorCodes.cs

@ -9,5 +9,7 @@
public const string InvalidRefundAmount = "EasyAbp.EShop.Payments:InvalidRefundAmount";
public const string OrderIdNotFound = "EasyAbp.EShop.Payments:OrderIdNotFound";
public const string StoreIdNotFound = "EasyAbp.EShop.Payments:StoreIdNotFound";
public const string OrderLineNotFound = "EasyAbp.EShop.Payments:OrderLineNotFound";
public const string OrderExtraFeeNotFound = "EasyAbp.EShop.Payments:OrderExtraFeeNotFound";
}
}

79
modules/EasyAbp.EShop.Payments/test/EasyAbp.EShop.Payments.Application.Tests/Refunds/RefundAppServiceTests.cs

@ -95,7 +95,7 @@ namespace EasyAbp.EShop.Payments.Refunds
StoreId = PaymentsTestData.Store1,
OrderLines = new List<OrderLineDto>
{
new OrderLineDto
new()
{
Id = PaymentsTestData.OrderLine1,
Currency = "CNY",
@ -103,6 +103,15 @@ namespace EasyAbp.EShop.Payments.Refunds
Quantity = 1
}
},
OrderExtraFees = new List<OrderExtraFeeDto>
{
new()
{
Name = "Name",
Key = "Key",
Fee = 5m
}
},
PaymentId = PaymentsTestData.Payment1
}));
@ -299,6 +308,74 @@ namespace EasyAbp.EShop.Payments.Refunds
await _refundAppService.CreateAsync(request);
});
}
[Fact]
public async Task Should_Check_OrderLines_Exist_When_Refunding()
{
// Arrange
var request = new CreateEShopRefundInput
{
DisplayReason = "Reason",
CustomerRemark = "Customer Remark",
PaymentId = PaymentsTestData.Payment1,
StaffRemark = "StaffRemark",
RefundItems = new List<CreateEShopRefundItemInput>
{
new()
{
CustomerRemark = "CustomerRemark",
OrderId = PaymentsTestData.Order1,
StaffRemark = "StaffRemark",
OrderLines = new List<OrderLineRefundInfoModel>
{
new()
{
OrderLineId = Guid.NewGuid(),
Quantity = 1,
TotalAmount = 1m
}
}
}
}
};
}
[Fact]
public async Task Should_Check_OrderExtraFees_Exist_When_Refunding()
{
// Arrange
var request = new CreateEShopRefundInput
{
DisplayReason = "Reason",
CustomerRemark = "Customer Remark",
PaymentId = PaymentsTestData.Payment1,
StaffRemark = "StaffRemark",
RefundItems = new List<CreateEShopRefundItemInput>
{
new()
{
CustomerRemark = "CustomerRemark",
OrderId = PaymentsTestData.Order1,
StaffRemark = "StaffRemark",
OrderExtraFees = new List<OrderExtraFeeRefundInfoModel>
{
new()
{
Name = "FakeName",
Key = "FakeKey",
TotalAmount = 0.6m
}
}
}
}
};
// Act & Assert
await Should.ThrowAsync<OrderExtraFeeNotFoundException>(async () =>
{
await _refundAppService.CreateAsync(request);
});
}
[Fact]
public async Task Should_Avoid_Non_Positive_Refund_Amount()

Loading…
Cancel
Save