From 55441ef2cdbb6b58f21b6d2ed8353423dcac5cb8 Mon Sep 17 00:00:00 2001 From: gdlcf88 Date: Thu, 4 Jun 2020 19:27:54 +0800 Subject: [PATCH] Close #41: Support the new payment creation design --- integration/EasyAbp.EShop/common.props | 2 +- modules/EasyAbp.EShop.Baskets/common.props | 2 +- modules/EasyAbp.EShop.Orders/common.props | 2 +- .../EShop/Orders/Orders/Dtos/OrderDto.cs | 2 + .../EasyAbp.EShop.Orders.Domain.csproj | 3 +- .../Orders/Orders/OrderPaymentChecker.cs | 6 +- .../OrderPaymentCompletedEventHandler.cs | 3 +- .../Orders/OrderPaymentCreatedEventHandler.cs | 5 +- .../Orders/OrderPaymentInvalidException.cs | 13 ++++ modules/EasyAbp.EShop.Payments/common.props | 2 +- .../PaymentsPermissionDefinitionProvider.cs | 2 + .../Authorization/PaymentsPermissions.cs | 2 + .../Payments/Dtos/CreatePaymentDto.cs | 33 ++++++++++ .../Payments/Payments/IPaymentAppService.cs | 3 +- .../OrderPaymentAlreadyExistsException.cs | 13 ++++ .../MultiStorePaymentNotSupportedException.cs | 12 ++++ .../Payments/Payments/PaymentAppService.cs | 62 ++++++++++++++++++- .../EasyAbp/EShop/Payments/PaymentsConsts.cs | 7 +++ .../EasyAbp.EShop.Payments.Domain.csproj | 2 +- .../Payments/Payments/IPaymentSynchronizer.cs | 7 +++ .../Payments/Payments/PaymentSynchronizer.cs | 32 +++++++--- modules/EasyAbp.EShop.Products/common.props | 2 +- modules/EasyAbp.EShop.Stores/common.props | 2 +- .../EShopSample.Application.Contracts.csproj | 4 +- .../EShopSample.Application.csproj | 4 +- .../EShopSample.Domain.Shared.csproj | 4 +- .../EShopSample.Domain.csproj | 4 +- .../EShopSample.EntityFrameworkCore.csproj | 4 +- .../EShopSample.HttpApi.Client.csproj | 4 +- .../EShopSample.HttpApi.csproj | 4 +- .../EShopSample.Web/EShopSample.Web.csproj | 4 +- 31 files changed, 211 insertions(+), 40 deletions(-) create mode 100644 modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentInvalidException.cs create mode 100644 modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/CreatePaymentDto.cs create mode 100644 modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/OrderPaymentAlreadyExistsException.cs create mode 100644 modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/MultiStorePaymentNotSupportedException.cs create mode 100644 modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/PaymentsConsts.cs create mode 100644 modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/IPaymentSynchronizer.cs diff --git a/integration/EasyAbp.EShop/common.props b/integration/EasyAbp.EShop/common.props index 8dc36126..4e0e2da0 100644 --- a/integration/EasyAbp.EShop/common.props +++ b/integration/EasyAbp.EShop/common.props @@ -1,7 +1,7 @@ latest - 0.2.1 + 0.2.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Baskets/common.props b/modules/EasyAbp.EShop.Baskets/common.props index 8dc36126..4e0e2da0 100644 --- a/modules/EasyAbp.EShop.Baskets/common.props +++ b/modules/EasyAbp.EShop.Baskets/common.props @@ -1,7 +1,7 @@ latest - 0.2.1 + 0.2.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Orders/common.props b/modules/EasyAbp.EShop.Orders/common.props index 8dc36126..4e0e2da0 100644 --- a/modules/EasyAbp.EShop.Orders/common.props +++ b/modules/EasyAbp.EShop.Orders/common.props @@ -1,7 +1,7 @@ latest - 0.2.1 + 0.2.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application.Contracts/EasyAbp/EShop/Orders/Orders/Dtos/OrderDto.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application.Contracts/EasyAbp/EShop/Orders/Orders/Dtos/OrderDto.cs index afec4764..2767ee82 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application.Contracts/EasyAbp/EShop/Orders/Orders/Dtos/OrderDto.cs +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Application.Contracts/EasyAbp/EShop/Orders/Orders/Dtos/OrderDto.cs @@ -26,6 +26,8 @@ namespace EasyAbp.EShop.Orders.Orders.Dtos public string StaffRemark { get; set; } + public Guid? PaymentId { get; set; } + public DateTime? PaidTime { get; set; } public DateTime? CompletionTime { get; set; } diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp.EShop.Orders.Domain.csproj b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp.EShop.Orders.Domain.csproj index 1587a0bd..fd3b36af 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp.EShop.Orders.Domain.csproj +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp.EShop.Orders.Domain.csproj @@ -8,9 +8,10 @@ - + + diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentChecker.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentChecker.cs index ce65496e..3a6f6530 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentChecker.cs +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentChecker.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using EasyAbp.PaymentService.Payments; using Volo.Abp.Data; @@ -17,8 +18,9 @@ namespace EasyAbp.EShop.Orders.Orders protected virtual Task IsStoreIdCorrectAsync(Order order, PaymentEto payment) { - return Task.FromResult(Guid.TryParse(payment.GetProperty("StoreId"), out var paymentStoreId) && - order.StoreId == paymentStoreId); + return Task.FromResult( + Guid.TryParse(payment.ExtraProperties.GetOrDefault("StoreId")?.ToString(), out var paymentStoreId) && + order.StoreId == paymentStoreId); } protected virtual Task IsPaymentPriceCorrectAsync(Order order, PaymentItemEto paymentItem) diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCompletedEventHandler.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCompletedEventHandler.cs index 67e67ea6..5402b703 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCompletedEventHandler.cs +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCompletedEventHandler.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using EasyAbp.EShop.Payments; using EasyAbp.PaymentService.Payments; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events.Distributed; @@ -38,7 +39,7 @@ namespace EasyAbp.EShop.Orders.Orders using var currentTenant = _currentTenant.Change(eventData.Entity.TenantId); - foreach (var item in eventData.Entity.PaymentItems.Where(item => item.ItemType == "EasyAbpEShopOrder")) + foreach (var item in eventData.Entity.PaymentItems.Where(item => item.ItemType == PaymentsConsts.PaymentItemType)) { var order = await _orderRepository.FindAsync(item.ItemKey); diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCreatedEventHandler.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCreatedEventHandler.cs index d7a55b39..cef3a7ab 100644 --- a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCreatedEventHandler.cs +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCreatedEventHandler.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Threading.Tasks; +using EasyAbp.EShop.Payments; using EasyAbp.PaymentService.Payments; using Volo.Abp.DependencyInjection; using Volo.Abp.Domain.Entities.Events.Distributed; @@ -29,14 +30,14 @@ namespace EasyAbp.EShop.Orders.Orders { using var currentTenant = _currentTenant.Change(eventData.Entity.TenantId); - foreach (var item in eventData.Entity.PaymentItems.Where(item => item.ItemType == "EasyAbpEShopOrder")) + foreach (var item in eventData.Entity.PaymentItems.Where(item => item.ItemType == PaymentsConsts.PaymentItemType)) { var order = await _orderRepository.FindAsync(item.ItemKey); if (order == null || order.PaymentId.HasValue || !await _orderPaymentChecker.IsValidPaymentAsync(order, eventData.Entity, item)) { - continue; + throw new OrderPaymentInvalidException(eventData.Entity.Id, item.ItemKey); } order.SetPaymentId(eventData.Entity.Id); diff --git a/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentInvalidException.cs b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentInvalidException.cs new file mode 100644 index 00000000..9f82003a --- /dev/null +++ b/modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentInvalidException.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp; + +namespace EasyAbp.EShop.Orders.Orders +{ + public class OrderPaymentInvalidException : BusinessException + { + public OrderPaymentInvalidException(Guid paymentId, Guid orderId) + : base(message: $"The payment {paymentId} has invalid configurations for the order {orderId}.") + { + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/common.props b/modules/EasyAbp.EShop.Payments/common.props index 8dc36126..4e0e2da0 100644 --- a/modules/EasyAbp.EShop.Payments/common.props +++ b/modules/EasyAbp.EShop.Payments/common.props @@ -1,7 +1,7 @@ latest - 0.2.1 + 0.2.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissionDefinitionProvider.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissionDefinitionProvider.cs index 47b49554..c2dda41a 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissionDefinitionProvider.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissionDefinitionProvider.cs @@ -13,10 +13,12 @@ namespace EasyAbp.EShop.Payments.Authorization var paymentPermission = moduleGroup.AddPermission(PaymentsPermissions.Payments.Default, L("Permission:Payments")); paymentPermission.AddChild(PaymentsPermissions.Payments.Manage, L("Permission:Manage")); paymentPermission.AddChild(PaymentsPermissions.Payments.CrossStore, L("Permission:CrossStore")); + paymentPermission.AddChild(PaymentsPermissions.Payments.Create, L("Permission:Create")); var refundPermission = moduleGroup.AddPermission(PaymentsPermissions.Refunds.Default, L("Permission:Refunds")); refundPermission.AddChild(PaymentsPermissions.Refunds.Manage, L("Permission:Manage")); refundPermission.AddChild(PaymentsPermissions.Refunds.CrossStore, L("Permission:CrossStore")); + refundPermission.AddChild(PaymentsPermissions.Refunds.Create, L("Permission:Create")); } private static LocalizableString L(string name) diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissions.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissions.cs index 5a6250bc..e7492715 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissions.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissions.cs @@ -16,6 +16,7 @@ namespace EasyAbp.EShop.Payments.Authorization public const string Default = GroupName + ".Payments"; public const string Manage = Default + ".Manage"; public const string CrossStore = Default + ".CrossStore"; + public const string Create = Default + ".Create"; } @@ -24,6 +25,7 @@ namespace EasyAbp.EShop.Payments.Authorization public const string Default = GroupName + ".Refunds"; public const string Manage = Default + ".Manage"; public const string CrossStore = Default + ".CrossStore"; + public const string Create = Default + ".Create"; } } diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/CreatePaymentDto.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/CreatePaymentDto.cs new file mode 100644 index 00000000..f23f7a89 --- /dev/null +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/CreatePaymentDto.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; + +namespace EasyAbp.EShop.Payments.Payments.Dtos +{ + public class CreatePaymentDto : IValidatableObject + { + public string PaymentMethod { get; set; } + + public List OrderIds { get; set; } + + public IEnumerable Validate(ValidationContext validationContext) + { + if (OrderIds.Count == 0) + { + yield return new ValidationResult( + "OrderIds is empty.", + new[] {"OrderIds"} + ); + } + + if (OrderIds.Distinct().Count() != OrderIds.Count) + { + yield return new ValidationResult( + "OrderIds should be distinct.", + new[] {"OrderIds"} + ); + } + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/IPaymentAppService.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/IPaymentAppService.cs index a88cfcfd..4fa0032a 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/IPaymentAppService.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/IPaymentAppService.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using EasyAbp.EShop.Payments.Payments.Dtos; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; @@ -13,6 +14,6 @@ namespace EasyAbp.EShop.Payments.Payments object, object> { - + Task CreateAsync(CreatePaymentDto input); } } \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/OrderPaymentAlreadyExistsException.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/OrderPaymentAlreadyExistsException.cs new file mode 100644 index 00000000..913c6735 --- /dev/null +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/OrderPaymentAlreadyExistsException.cs @@ -0,0 +1,13 @@ +using System; +using Volo.Abp; + +namespace EasyAbp.EShop.Payments.Payments +{ + public class OrderPaymentAlreadyExistsException : BusinessException + { + public OrderPaymentAlreadyExistsException(Guid orderId) + : base(message: $"The order {orderId}'s payment is already exists.") + { + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/MultiStorePaymentNotSupportedException.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/MultiStorePaymentNotSupportedException.cs new file mode 100644 index 00000000..9b3e7ed7 --- /dev/null +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/MultiStorePaymentNotSupportedException.cs @@ -0,0 +1,12 @@ +using Volo.Abp; + +namespace EasyAbp.EShop.Payments.Payments +{ + public class MultiStorePaymentNotSupportedException : BusinessException + { + public MultiStorePaymentNotSupportedException() : base(message: $"Should create payments for each store.") + { + + } + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs index 13a68c1a..426ad754 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs @@ -1,13 +1,18 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using EasyAbp.EShop.Orders.Orders; +using EasyAbp.EShop.Orders.Orders.Dtos; using EasyAbp.EShop.Payments.Authorization; using EasyAbp.EShop.Payments.Payments; using EasyAbp.EShop.Payments.Payments.Dtos; +using EasyAbp.PaymentService.Payments; using Microsoft.AspNetCore.Authorization; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +using Volo.Abp.EventBus.Distributed; using Volo.Abp.Users; namespace EasyAbp.EShop.Payments.Payments @@ -19,10 +24,17 @@ namespace EasyAbp.EShop.Payments.Payments protected override string GetPolicyName { get; set; } = PaymentsPermissions.Payments.Default; protected override string GetListPolicyName { get; set; } = PaymentsPermissions.Payments.Default; + private readonly IDistributedEventBus _distributedEventBus; + private readonly IOrderAppService _orderAppService; private readonly IPaymentRepository _repository; - public PaymentAppService(IPaymentRepository repository) : base(repository) + public PaymentAppService( + IDistributedEventBus distributedEventBus, + IOrderAppService orderAppService, + IPaymentRepository repository) : base(repository) { + _distributedEventBus = distributedEventBus; + _orderAppService = orderAppService; _repository = repository; } @@ -76,6 +88,54 @@ namespace EasyAbp.EShop.Payments.Payments { throw new NotSupportedException(); } + + [Authorize(PaymentsPermissions.Payments.Create)] + public async Task CreateAsync(CreatePaymentDto input) + { + var orders = new List(); + + foreach (var orderId in input.OrderIds) + { + var order = await _orderAppService.GetAsync(orderId); + + orders.Add(order); + + if (order.PaymentId.HasValue || order.PaidTime.HasValue) + { + throw new OrderPaymentAlreadyExistsException(orderId); + } + } + + if (orders.Select(order => order.Currency).Distinct().Count() != 1) + { + throw new MultiCurrencyNotSupportedException(); + } + + if (orders.Select(order => order.StoreId).Distinct().Count() != 1) + { + throw new MultiStorePaymentNotSupportedException(); + } + + // Todo: should avoid duplicate creations. + + var extraProperties = new Dictionary {{"StoreId", orders.First().StoreId}}; + + await _distributedEventBus.PublishAsync(new CreatePaymentEto + { + TenantId = CurrentTenant.Id, + UserId = CurrentUser.GetId(), + PaymentMethod = input.PaymentMethod, + Currency = orders.First().Currency, + ExtraProperties = extraProperties, + PaymentItems = orders.Select(order => new CreatePaymentItemEto + { + ItemType = PaymentsConsts.PaymentItemType, + ItemKey = order.Id, + Currency = order.Currency, + OriginalPaymentAmount = order.TotalPrice + }).ToList() + }); + } [RemoteService(false)] public override Task UpdateAsync(Guid id, object input) diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/PaymentsConsts.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/PaymentsConsts.cs new file mode 100644 index 00000000..4cf2fd5d --- /dev/null +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain.Shared/EasyAbp/EShop/Payments/PaymentsConsts.cs @@ -0,0 +1,7 @@ +namespace EasyAbp.EShop.Payments +{ + public static class PaymentsConsts + { + public const string PaymentItemType = "EasyAbpEShopOrder"; + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp.EShop.Payments.Domain.csproj b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp.EShop.Payments.Domain.csproj index 1fae6d0c..2a922706 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp.EShop.Payments.Domain.csproj +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp.EShop.Payments.Domain.csproj @@ -8,7 +8,7 @@ - + diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/IPaymentSynchronizer.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/IPaymentSynchronizer.cs new file mode 100644 index 00000000..6922eb0f --- /dev/null +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/IPaymentSynchronizer.cs @@ -0,0 +1,7 @@ +namespace EasyAbp.EShop.Payments.Payments +{ + public interface IPaymentSynchronizer + { + + } +} \ No newline at end of file diff --git a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs index e6111b53..fca4ed55 100644 --- a/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs +++ b/modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs @@ -12,6 +12,8 @@ namespace EasyAbp.EShop.Payments.Payments { public class PaymentSynchronizer : IDistributedEventHandler>, + IDistributedEventHandler>, + IPaymentSynchronizer, ITransientDependency { private readonly IObjectMapper _objectMapper; @@ -26,27 +28,39 @@ namespace EasyAbp.EShop.Payments.Payments } [UnitOfWork(true)] - public async Task HandleEventAsync(EntityUpdatedEto eventData) + public virtual async Task HandleEventAsync(EntityUpdatedEto eventData) { var payment = await _paymentRepository.FindAsync(eventData.Entity.Id); if (payment == null) { payment = _objectMapper.Map(eventData.Entity); - - if (Guid.TryParse(eventData.Entity.GetProperty("StoreId"), out var storeId)) - { - payment.SetStoreId(storeId); - } - + await _paymentRepository.InsertAsync(payment, true); } else { _objectMapper.Map(eventData.Entity, payment); - - await _paymentRepository.UpdateAsync(payment, true); } + + if (Guid.TryParse(eventData.Entity.GetProperty("StoreId"), out var storeId)) + { + payment.SetStoreId(storeId); + } + + await _paymentRepository.UpdateAsync(payment, true); + } + + public virtual async Task HandleEventAsync(EntityDeletedEto eventData) + { + var payment = await _paymentRepository.FindAsync(eventData.Entity.Id); + + if (payment == null) + { + return; + } + + await _paymentRepository.DeleteAsync(payment, true); } } } diff --git a/modules/EasyAbp.EShop.Products/common.props b/modules/EasyAbp.EShop.Products/common.props index 8dc36126..4e0e2da0 100644 --- a/modules/EasyAbp.EShop.Products/common.props +++ b/modules/EasyAbp.EShop.Products/common.props @@ -1,7 +1,7 @@ latest - 0.2.1 + 0.2.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/modules/EasyAbp.EShop.Stores/common.props b/modules/EasyAbp.EShop.Stores/common.props index 8dc36126..4e0e2da0 100644 --- a/modules/EasyAbp.EShop.Stores/common.props +++ b/modules/EasyAbp.EShop.Stores/common.props @@ -1,7 +1,7 @@ latest - 0.2.1 + 0.2.2 $(NoWarn);CS1591 true EasyAbp Team diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.Application.Contracts/EShopSample.Application.Contracts.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.Application.Contracts/EShopSample.Application.Contracts.csproj index edf2bcc7..26e22cba 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.Application.Contracts/EShopSample.Application.Contracts.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.Application.Contracts/EShopSample.Application.Contracts.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.Application/EShopSample.Application.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.Application/EShopSample.Application.csproj index 43cd3e3b..16889bc7 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.Application/EShopSample.Application.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.Application/EShopSample.Application.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.Domain.Shared/EShopSample.Domain.Shared.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.Domain.Shared/EShopSample.Domain.Shared.csproj index e9ec9b0c..15f227b8 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.Domain.Shared/EShopSample.Domain.Shared.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.Domain.Shared/EShopSample.Domain.Shared.csproj @@ -8,8 +8,8 @@ - - + + diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.Domain/EShopSample.Domain.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.Domain/EShopSample.Domain.csproj index 0e2e4038..8785d2f6 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.Domain/EShopSample.Domain.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.Domain/EShopSample.Domain.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore/EShopSample.EntityFrameworkCore.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore/EShopSample.EntityFrameworkCore.csproj index 6d8e132d..e830aaed 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore/EShopSample.EntityFrameworkCore.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore/EShopSample.EntityFrameworkCore.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi.Client/EShopSample.HttpApi.Client.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi.Client/EShopSample.HttpApi.Client.csproj index ae833a00..c650c478 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi.Client/EShopSample.HttpApi.Client.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi.Client/EShopSample.HttpApi.Client.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi/EShopSample.HttpApi.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi/EShopSample.HttpApi.csproj index a72613e8..7a4bea03 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi/EShopSample.HttpApi.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.HttpApi/EShopSample.HttpApi.csproj @@ -13,8 +13,8 @@ - - + + diff --git a/samples/EShopSample/aspnet-core/src/EShopSample.Web/EShopSample.Web.csproj b/samples/EShopSample/aspnet-core/src/EShopSample.Web/EShopSample.Web.csproj index 3fecf969..88394217 100644 --- a/samples/EShopSample/aspnet-core/src/EShopSample.Web/EShopSample.Web.csproj +++ b/samples/EShopSample/aspnet-core/src/EShopSample.Web/EShopSample.Web.csproj @@ -45,8 +45,8 @@ - - + +