Browse Source

Payment should accept cross-store items

Close #83
pull/87/head 0.9.0
gdlcf88 6 years ago
parent
commit
be299086cc
  1. 2
      common.props
  2. 2
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp.EShop.Orders.Domain.csproj
  3. 7
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentChecker.cs
  4. 12
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCompletedEventHandler.cs
  5. 2
      modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp/EShop/Orders/Orders/OrderPaymentCreatedEventHandler.cs
  6. 2
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissionDefinitionProvider.cs
  7. 2
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissions.cs
  8. 2
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/GetPaymentListDto.cs
  9. 2
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/PaymentDto.cs
  10. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/PaymentItemDto.cs
  11. 2
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Refunds/Dtos/GetRefundListDto.cs
  12. 11
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/BasicPayableCheckProvider.cs
  13. 3
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/IPayableCheckProvider.cs
  14. 3
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/IPayableChecker.cs
  15. 6
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PayableChecker.cs
  16. 36
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs
  17. 16
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Refunds/RefundAppService.cs
  18. 2
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp.EShop.Payments.Domain.csproj
  19. 7
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/Payment.cs
  20. 16
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentItem.cs
  21. 34
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs
  22. 4
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/PaymentsDomainAutoMapperProfile.cs
  23. 11
      modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/StoreIdNotFoundException.cs
  24. 4
      samples/EShopSample/aspnet-core/src/EShopSample.Application.Contracts/EShopSample.Application.Contracts.csproj
  25. 4
      samples/EShopSample/aspnet-core/src/EShopSample.Application/EShopSample.Application.csproj
  26. 4
      samples/EShopSample/aspnet-core/src/EShopSample.Domain.Shared/EShopSample.Domain.Shared.csproj
  27. 4
      samples/EShopSample/aspnet-core/src/EShopSample.Domain/EShopSample.Domain.csproj
  28. 3864
      samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20200804190805_MovedStoreIdFromPaymentToPaymentItem.Designer.cs
  29. 43
      samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20200804190805_MovedStoreIdFromPaymentToPaymentItem.cs
  30. 10
      samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/EShopSampleMigrationsDbContextModelSnapshot.cs
  31. 4
      samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore/EShopSample.EntityFrameworkCore.csproj
  32. 4
      samples/EShopSample/aspnet-core/src/EShopSample.HttpApi.Client/EShopSample.HttpApi.Client.csproj
  33. 4
      samples/EShopSample/aspnet-core/src/EShopSample.HttpApi/EShopSample.HttpApi.csproj
  34. 4
      samples/EShopSample/aspnet-core/src/EShopSample.Web/EShopSample.Web.csproj

2
common.props

@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<Version>0.8.6</Version>
<Version>0.9.0</Version>
<NoWarn>$(NoWarn);CS1591</NoWarn>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>EasyAbp Team</Authors>

2
modules/EasyAbp.EShop.Orders/src/EasyAbp.EShop.Orders.Domain/EasyAbp.EShop.Orders.Domain.csproj

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.Domain.Shared" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.Domain.Shared" Version="0.6.4" />
<PackageReference Include="Volo.Abp.AutoMapper" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="3.0.4" />
<ProjectReference Include="..\..\..\EasyAbp.EShop.Payments\src\EasyAbp.EShop.Payments.Domain.Shared\EasyAbp.EShop.Payments.Domain.Shared.csproj" />

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

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.PaymentService.Payments;
using Volo.Abp.Data;
@ -11,15 +10,15 @@ namespace EasyAbp.EShop.Orders.Orders
{
public virtual async Task<bool> IsValidPaymentAsync(Order order, PaymentEto payment, PaymentItemEto paymentItem)
{
return await IsStoreIdCorrectAsync(order, payment) &&
return await IsStoreIdCorrectAsync(order, paymentItem) &&
await IsPaymentPriceCorrectAsync(order, paymentItem) &&
await IsUserAllowedToPayAsync(order, payment);
}
protected virtual Task<bool> IsStoreIdCorrectAsync(Order order, PaymentEto payment)
protected virtual Task<bool> IsStoreIdCorrectAsync(Order order, PaymentItemEto paymentItem)
{
return Task.FromResult(
Guid.TryParse(payment.ExtraProperties.GetOrDefault("StoreId")?.ToString(), out var paymentStoreId) &&
Guid.TryParse(paymentItem.GetProperty<string>("StoreId"), out var paymentStoreId) &&
order.StoreId == paymentStoreId);
}

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

@ -17,6 +17,7 @@ namespace EasyAbp.EShop.Orders.Orders
private readonly IClock _clock;
private readonly ICurrentTenant _currentTenant;
private readonly IObjectMapper _objectMapper;
private readonly IUnitOfWorkManager _unitOfWorkManager;
private readonly IOrderPaymentChecker _orderPaymentChecker;
private readonly IDistributedEventBus _distributedEventBus;
private readonly IOrderRepository _orderRepository;
@ -25,6 +26,7 @@ namespace EasyAbp.EShop.Orders.Orders
IClock clock,
ICurrentTenant currentTenant,
IObjectMapper objectMapper,
IUnitOfWorkManager unitOfWorkManager,
IOrderPaymentChecker orderPaymentChecker,
IDistributedEventBus distributedEventBus,
IOrderRepository orderRepository)
@ -32,12 +34,12 @@ namespace EasyAbp.EShop.Orders.Orders
_clock = clock;
_currentTenant = currentTenant;
_objectMapper = objectMapper;
_unitOfWorkManager = unitOfWorkManager;
_orderPaymentChecker = orderPaymentChecker;
_distributedEventBus = distributedEventBus;
_orderRepository = orderRepository;
}
[UnitOfWork(true)]
public virtual async Task HandleEventAsync(PaymentCompletedEto eventData)
{
var payment = eventData.Payment;
@ -49,6 +51,8 @@ namespace EasyAbp.EShop.Orders.Orders
using var currentTenant = _currentTenant.Change(payment.TenantId);
using var uow = _unitOfWorkManager.Begin(isTransactional: true);
foreach (var item in payment.PaymentItems.Where(item => item.ItemType == PaymentsConsts.PaymentItemType))
{
var order = await _orderRepository.GetAsync(item.ItemKey);
@ -69,13 +73,15 @@ namespace EasyAbp.EShop.Orders.Orders
await _orderRepository.UpdateAsync(order, true);
await _distributedEventBus.PublishAsync(new OrderPaidEto
uow.OnCompleted(async () => await _distributedEventBus.PublishAsync(new OrderPaidEto
{
Order = _objectMapper.Map<Order, OrderEto>(order),
PaymentId = payment.Id,
PaymentItemId = item.Id
});
}));
}
await uow.CompleteAsync();
}
}
}

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

@ -36,11 +36,13 @@ namespace EasyAbp.EShop.Orders.Orders
if (order.PaymentId.HasValue || order.OrderStatus != OrderStatus.Pending)
{
// Todo: should cancel the payment?
throw new OrderIsInWrongStageException(order.Id);
}
if (!await _orderPaymentChecker.IsValidPaymentAsync(order, eventData.Entity, item))
{
// Todo: should cancel the payment?
throw new OrderPaymentInvalidException(eventData.Entity.Id, item.ItemKey);
}

2
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissionDefinitionProvider.cs

@ -12,12 +12,10 @@ 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"));
}

2
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Authorization/PaymentsPermissions.cs

@ -15,7 +15,6 @@ namespace EasyAbp.EShop.Payments.Authorization
{
public const string Default = GroupName + ".Payment";
public const string Manage = Default + ".Manage";
public const string CrossStore = Default + ".CrossStore";
public const string Create = Default + ".Create";
}
@ -24,7 +23,6 @@ namespace EasyAbp.EShop.Payments.Authorization
{
public const string Default = GroupName + ".Refund";
public const string Manage = Default + ".Manage";
public const string CrossStore = Default + ".CrossStore";
public const string Create = Default + ".Create";
}

2
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/GetPaymentListDto.cs

@ -5,8 +5,6 @@ namespace EasyAbp.EShop.Payments.Payments.Dtos
{
public class GetPaymentListDto : PagedAndSortedResultRequestDto
{
public Guid? StoreId { get; set; }
public Guid? UserId { get; set; }
}
}

2
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/PaymentDto.cs

@ -6,8 +6,6 @@ namespace EasyAbp.EShop.Payments.Payments.Dtos
{
public class PaymentDto : ExtensibleFullAuditedEntityDto<Guid>
{
public Guid? StoreId { get; set; }
public Guid UserId { get; set; }
public string PaymentMethod { get; set; }

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Payments/Dtos/PaymentItemDto.cs

@ -4,8 +4,10 @@ using Volo.Abp.Application.Dtos;
namespace EasyAbp.EShop.Payments.Payments.Dtos
{
public class PaymentItemDto : FullAuditedEntityDto<Guid>
public class PaymentItemDto : ExtensibleFullAuditedEntityDto<Guid>
{
public Guid StoreId { get; set; }
public string ItemType { get; set; }
public Guid ItemKey { get; set; }

2
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application.Contracts/EasyAbp/EShop/Payments/Refunds/Dtos/GetRefundListDto.cs

@ -5,8 +5,6 @@ namespace EasyAbp.EShop.Payments.Refunds.Dtos
{
public class GetRefundListDto : PagedAndSortedResultRequestDto
{
public Guid? StoreId { get; set; }
public Guid? UserId { get; set; }
}
}

11
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/BasicPayableCheckProvider.cs

@ -10,8 +10,7 @@ namespace EasyAbp.EShop.Payments.Payments
{
public class BasicPayableCheckProvider : IPayableCheckProvider, ITransientDependency
{
public virtual Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders,
Dictionary<string, object> paymentExtraProperties)
public virtual Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto)
{
foreach (var order in orders.Where(order => order.PaymentId.HasValue || order.PaidTime.HasValue))
{
@ -23,10 +22,10 @@ namespace EasyAbp.EShop.Payments.Payments
throw new MultiCurrencyNotSupportedException();
}
if (orders.Select(order => order.StoreId).Distinct().Count() != 1)
{
throw new MultiStorePaymentNotSupportedException();
}
// if (orders.Select(order => order.StoreId).Distinct().Count() != 1)
// {
// throw new MultiStorePaymentNotSupportedException();
// }
return Task.CompletedTask;
}

3
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/IPayableCheckProvider.cs

@ -2,11 +2,12 @@
using System.Threading.Tasks;
using EasyAbp.EShop.Orders.Orders.Dtos;
using EasyAbp.EShop.Payments.Payments.Dtos;
using EasyAbp.PaymentService.Payments;
namespace EasyAbp.EShop.Payments.Payments
{
public interface IPayableCheckProvider
{
Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, Dictionary<string, object> paymentExtraProperties);
Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto);
}
}

3
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/IPayableChecker.cs

@ -3,11 +3,12 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.EShop.Orders.Orders.Dtos;
using EasyAbp.EShop.Payments.Payments.Dtos;
using EasyAbp.PaymentService.Payments;
namespace EasyAbp.EShop.Payments.Payments
{
public interface IPayableChecker
{
Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, Dictionary<string, object> paymentExtraProperties);
Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto);
}
}

6
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PayableChecker.cs

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Threading.Tasks;
using EasyAbp.EShop.Orders.Orders.Dtos;
using EasyAbp.EShop.Payments.Payments.Dtos;
using EasyAbp.PaymentService.Payments;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.DependencyInjection;
@ -18,14 +19,13 @@ namespace EasyAbp.EShop.Payments.Payments
}
public virtual async Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders,
Dictionary<string, object> paymentExtraProperties)
public virtual async Task CheckAsync(CreatePaymentDto input, List<OrderDto> orders, CreatePaymentEto createPaymentEto)
{
var providers = _serviceProvider.GetServices<IPayableCheckProvider>();
foreach (var provider in providers)
{
await provider.CheckAsync(input, orders, paymentExtraProperties);
await provider.CheckAsync(input, orders, createPaymentEto);
}
}
}

36
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Application/EasyAbp/EShop/Payments/Payments/PaymentAppService.cs

@ -48,8 +48,6 @@ namespace EasyAbp.EShop.Payments.Payments
if (payment.UserId != CurrentUser.GetId())
{
await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.Manage);
// Todo: Check if current user is an admin of the store.
}
return payment;
@ -59,9 +57,9 @@ namespace EasyAbp.EShop.Payments.Payments
{
var query = base.CreateFilteredQuery(input);
if (input.StoreId.HasValue)
if (input.UserId.HasValue)
{
query = query.Where(x => x.StoreId == input.StoreId.Value);
query = query.Where(x => x.UserId == input.UserId.Value);
}
return query;
@ -72,15 +70,6 @@ namespace EasyAbp.EShop.Payments.Payments
if (input.UserId != CurrentUser.GetId())
{
await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.Manage);
if (input.StoreId.HasValue)
{
// Todo: Check if current user is an admin of the store.
}
else
{
await AuthorizationService.CheckAsync(PaymentsPermissions.Payments.CrossStore);
}
}
return await base.GetListAsync(input);
@ -89,6 +78,8 @@ namespace EasyAbp.EShop.Payments.Payments
[Authorize(PaymentsPermissions.Payments.Create)]
public virtual async Task CreateAsync(CreatePaymentDto input)
{
// Todo: should avoid duplicate creations. (concurrent lock)
var orders = new List<OrderDto>();
foreach (var orderId in input.OrderIds)
@ -96,27 +87,26 @@ namespace EasyAbp.EShop.Payments.Payments
orders.Add(await _orderAppService.GetAsync(orderId));
}
var extraProperties = new Dictionary<string, object> {{"StoreId", orders.First().StoreId}};
await _payableChecker.CheckAsync(input, orders, extraProperties);
// Todo: should avoid duplicate creations.
await _distributedEventBus.PublishAsync(new CreatePaymentEto
var createPaymentEto = new CreatePaymentEto
{
TenantId = CurrentTenant.Id,
UserId = CurrentUser.GetId(),
PaymentMethod = input.PaymentMethod,
Currency = orders.First().Currency,
ExtraProperties = extraProperties,
ExtraProperties = new Dictionary<string, object>(),
PaymentItems = orders.Select(order => new CreatePaymentItemEto
{
ItemType = PaymentsConsts.PaymentItemType,
ItemKey = order.Id,
Currency = order.Currency,
OriginalPaymentAmount = order.TotalPrice
OriginalPaymentAmount = order.TotalPrice,
ExtraProperties = new Dictionary<string, object> {{"StoreId", orders.First().StoreId.ToString()}}
}).ToList()
});
};
await _payableChecker.CheckAsync(input, orders, createPaymentEto);
await _distributedEventBus.PublishAsync(createPaymentEto);
}
}
}

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

@ -39,8 +39,6 @@ namespace EasyAbp.EShop.Payments.Refunds
if (payment.UserId != CurrentUser.GetId())
{
await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.Manage);
// Todo: Check if current user is an admin of the store.
}
return refund;
@ -50,11 +48,6 @@ namespace EasyAbp.EShop.Payments.Refunds
{
var query = input.UserId.HasValue ? _repository.GetQueryableByUserId(input.UserId.Value) : _repository;
if (input.StoreId.HasValue)
{
query = query.Where(x => x.StoreId == input.StoreId.Value);
}
return query;
}
@ -63,15 +56,6 @@ namespace EasyAbp.EShop.Payments.Refunds
if (input.UserId != CurrentUser.GetId())
{
await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.Manage);
if (input.StoreId.HasValue)
{
// Todo: Check if current user is an admin of the store.
}
else
{
await AuthorizationService.CheckAsync(PaymentsPermissions.Refunds.CrossStore);
}
}
return await base.GetListAsync(input);

2
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp.EShop.Payments.Domain.csproj

@ -8,7 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.Domain.Shared" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.Domain.Shared" Version="0.6.4" />
<PackageReference Include="Volo.Abp.AutoMapper" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Ddd.Domain" Version="3.0.4" />
<ProjectReference Include="..\..\..\EasyAbp.EShop.Stores\src\EasyAbp.EShop.Stores.Domain.Shared\EasyAbp.EShop.Stores.Domain.Shared.csproj" />

7
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/Payment.cs

@ -45,17 +45,10 @@ namespace EasyAbp.EShop.Payments.Payments
#endregion
public virtual Guid? StoreId { get; protected set; }
private Payment()
{
}
public void SetStoreId(Guid? storeId)
{
StoreId = storeId;
}
public void SetPaymentItems(List<PaymentItem> paymentItems)
{

16
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentItem.cs

@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using EasyAbp.EShop.Stores.Stores;
using EasyAbp.PaymentService.Payments;
using JetBrains.Annotations;
using Volo.Abp.Data;
using Volo.Abp.Domain.Entities.Auditing;
namespace EasyAbp.EShop.Payments.Payments
{
public class PaymentItem : FullAuditedEntity<Guid>, IPaymentItem
public class PaymentItem : FullAuditedEntity<Guid>, IPaymentItem, IHasExtraProperties, IMultiStore
{
#region Base properties
@ -26,12 +29,21 @@ namespace EasyAbp.EShop.Payments.Payments
public virtual decimal RefundAmount { get; protected set; }
public virtual decimal PendingRefundAmount { get; protected set; }
public virtual Dictionary<string, object> ExtraProperties { get; protected set; }
#endregion
public virtual Guid StoreId { get; protected set; }
public void SetStoreId(Guid storeId)
{
StoreId = storeId;
}
private PaymentItem()
{
ExtraProperties = new Dictionary<string, object>();
}
}
}

34
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/Payments/PaymentSynchronizer.cs

@ -47,30 +47,34 @@ namespace EasyAbp.EShop.Payments.Payments
{
_objectMapper.Map(eventData.Entity, payment);
foreach (var item in eventData.Entity.PaymentItems)
foreach (var etoItem in eventData.Entity.PaymentItems)
{
var find = payment.PaymentItems.FirstOrDefault(i => i.Id == item.Id);
var item = payment.PaymentItems.FirstOrDefault(i => i.Id == etoItem.Id);
if (find == null)
if (item == null)
{
payment.PaymentItems.Add(_objectMapper.Map<PaymentItemEto, PaymentItem>(item));
if (!Guid.TryParse(etoItem.GetProperty<string>("StoreId"), out var storeId))
{
throw new StoreIdNotFoundException();
}
item = _objectMapper.Map<PaymentItemEto, PaymentItem>(etoItem);
item.SetStoreId(storeId);
payment.PaymentItems.Add(item);
}
else
{
_objectMapper.Map(item, find);
_objectMapper.Map(etoItem, item);
}
var etoPaymentItemIds = eventData.Entity.PaymentItems.Select(i => i.Id).ToList();
payment.PaymentItems.RemoveAll(i => !etoPaymentItemIds.Contains(i.Id));
}
var etoPaymentItemIds = eventData.Entity.PaymentItems.Select(i => i.Id).ToList();
payment.PaymentItems.RemoveAll(i => !etoPaymentItemIds.Contains(i.Id));
}
if (Guid.TryParse(eventData.Entity.GetProperty<string>("StoreId"), out var storeId))
{
payment.SetStoreId(storeId);
}
await _paymentRepository.UpdateAsync(payment, true);
}

4
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/PaymentsDomainAutoMapperProfile.cs

@ -14,9 +14,9 @@ namespace EasyAbp.EShop.Payments
* into multiple profile classes for a better organization. */
CreateMap<PaymentEto, Payment>(MemberList.Source)
.Ignore(x => x.StoreId)
.Ignore(x => x.PaymentItems);
CreateMap<PaymentItemEto, PaymentItem>(MemberList.Source);
CreateMap<PaymentItemEto, PaymentItem>(MemberList.Source)
.Ignore(x => x.StoreId);
}
}
}

11
modules/EasyAbp.EShop.Payments/src/EasyAbp.EShop.Payments.Domain/EasyAbp/EShop/Payments/StoreIdNotFoundException.cs

@ -0,0 +1,11 @@
using Volo.Abp;
namespace EasyAbp.EShop.Payments
{
public class StoreIdNotFoundException : BusinessException
{
public StoreIdNotFoundException() : base(message: $"Cannot get valid StoreId from ExtraProperties.")
{
}
}
}

4
samples/EShopSample/aspnet-core/src/EShopSample.Application.Contracts/EShopSample.Application.Contracts.csproj

@ -14,8 +14,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.Application.Contracts" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Application.Contracts" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.Application.Contracts" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Application.Contracts" Version="0.6.4" />
<PackageReference Include="Volo.Abp.ObjectExtending" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Account.Application.Contracts" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Identity.Application.Contracts" Version="3.0.4" />

4
samples/EShopSample/aspnet-core/src/EShopSample.Application/EShopSample.Application.csproj

@ -15,8 +15,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.Application" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Application" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.Application" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Application" Version="0.6.4" />
<PackageReference Include="Volo.Abp.Account.Application" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Identity.Application" Version="3.0.4" />
<PackageReference Include="Volo.Abp.PermissionManagement.Application" Version="3.0.4" />

4
samples/EShopSample/aspnet-core/src/EShopSample.Domain.Shared/EShopSample.Domain.Shared.csproj

@ -9,8 +9,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.Domain.Shared" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Domain.Shared" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.Domain.Shared" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Domain.Shared" Version="0.6.4" />
<PackageReference Include="Volo.Abp.Identity.Domain.Shared" Version="3.0.4" />
<PackageReference Include="Volo.Abp.IdentityServer.Domain.Shared" Version="3.0.4" />
<PackageReference Include="Volo.Abp.BackgroundJobs.Domain.Shared" Version="3.0.4" />

4
samples/EShopSample/aspnet-core/src/EShopSample.Domain/EShopSample.Domain.csproj

@ -14,8 +14,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.Domain" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Domain" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.Domain" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Domain" Version="0.6.4" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.DataAnnotations" Version="2.2.0" />
<PackageReference Include="Volo.Abp.Identity.Domain" Version="3.0.4" />
<PackageReference Include="Volo.Abp.PermissionManagement.Domain.Identity" Version="3.0.4" />

3864
samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20200804190805_MovedStoreIdFromPaymentToPaymentItem.Designer.cs

File diff suppressed because it is too large

43
samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/20200804190805_MovedStoreIdFromPaymentToPaymentItem.cs

@ -0,0 +1,43 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace EShopSample.Migrations
{
public partial class MovedStoreIdFromPaymentToPaymentItem : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "StoreId",
table: "EShopPaymentsPayments");
migrationBuilder.AddColumn<string>(
name: "ExtraProperties",
table: "PaymentServicePaymentItems",
nullable: true);
migrationBuilder.AddColumn<Guid>(
name: "StoreId",
table: "EShopPaymentsPaymentItems",
nullable: false,
defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ExtraProperties",
table: "PaymentServicePaymentItems");
migrationBuilder.DropColumn(
name: "StoreId",
table: "EShopPaymentsPaymentItems");
migrationBuilder.AddColumn<Guid>(
name: "StoreId",
table: "EShopPaymentsPayments",
type: "uniqueidentifier",
nullable: true);
}
}
}

10
samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore.DbMigrations/Migrations/EShopSampleMigrationsDbContextModelSnapshot.cs

@ -301,9 +301,6 @@ namespace EShopSample.Migrations
b.Property<decimal>("RefundAmount")
.HasColumnType("decimal(20,8)");
b.Property<Guid?>("StoreId")
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("TenantId")
.HasColumnName("TenantId")
.HasColumnType("uniqueidentifier");
@ -379,6 +376,9 @@ namespace EShopSample.Migrations
b.Property<decimal>("RefundAmount")
.HasColumnType("decimal(20,8)");
b.Property<Guid>("StoreId")
.HasColumnType("uniqueidentifier");
b.HasKey("Id");
b.HasIndex("PaymentId");
@ -1523,6 +1523,10 @@ namespace EShopSample.Migrations
.HasColumnName("DeletionTime")
.HasColumnType("datetime2");
b.Property<string>("ExtraProperties")
.HasColumnName("ExtraProperties")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.ValueGeneratedOnAdd()
.HasColumnName("IsDeleted")

4
samples/EShopSample/aspnet-core/src/EShopSample.EntityFrameworkCore/EShopSample.EntityFrameworkCore.csproj

@ -11,8 +11,8 @@
<ProjectReference Include="..\..\..\..\..\integration\EasyAbp.EShop\src\EasyAbp.EShop.EntityFrameworkCore\EasyAbp.EShop.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\..\..\..\plugins\Baskets\src\EasyAbp.EShop.Plugins.Baskets.EntityFrameworkCore\EasyAbp.EShop.Plugins.Baskets.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\EShopSample.Domain\EShopSample.Domain.csproj" />
<PackageReference Include="EasyAbp.PaymentService.EntityFrameworkCore" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.EntityFrameworkCore" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.EntityFrameworkCore" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.EntityFrameworkCore" Version="0.6.4" />
<PackageReference Include="Volo.Abp.EntityFrameworkCore.SqlServer" Version="3.0.4" />
<PackageReference Include="Volo.Abp.PermissionManagement.EntityFrameworkCore" Version="3.0.4" />
<PackageReference Include="Volo.Abp.SettingManagement.EntityFrameworkCore" Version="3.0.4" />

4
samples/EShopSample/aspnet-core/src/EShopSample.HttpApi.Client/EShopSample.HttpApi.Client.csproj

@ -14,8 +14,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.HttpApi.Client" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.HttpApi.Client" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.HttpApi.Client" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.HttpApi.Client" Version="0.6.4" />
<PackageReference Include="Volo.Abp.Account.HttpApi.Client" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Identity.HttpApi.Client" Version="3.0.4" />
<PackageReference Include="Volo.Abp.PermissionManagement.HttpApi.Client" Version="3.0.4" />

4
samples/EShopSample/aspnet-core/src/EShopSample.HttpApi/EShopSample.HttpApi.csproj

@ -14,8 +14,8 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="EasyAbp.PaymentService.HttpApi" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.HttpApi" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.HttpApi" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.HttpApi" Version="0.6.4" />
<PackageReference Include="Volo.Abp.Account.HttpApi" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Identity.HttpApi" Version="3.0.4" />
<PackageReference Include="Volo.Abp.PermissionManagement.HttpApi" Version="3.0.4" />

4
samples/EShopSample/aspnet-core/src/EShopSample.Web/EShopSample.Web.csproj

@ -46,8 +46,8 @@
<ProjectReference Include="..\EShopSample.Application\EShopSample.Application.csproj" />
<ProjectReference Include="..\EShopSample.HttpApi\EShopSample.HttpApi.csproj" />
<ProjectReference Include="..\EShopSample.EntityFrameworkCore.DbMigrations\EShopSample.EntityFrameworkCore.DbMigrations.csproj" />
<PackageReference Include="EasyAbp.PaymentService.Web" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Web" Version="0.6.2" />
<PackageReference Include="EasyAbp.PaymentService.Web" Version="0.6.4" />
<PackageReference Include="EasyAbp.PaymentService.WeChatPay.Web" Version="0.6.4" />
<PackageReference Include="Volo.Abp.AspNetCore.Mvc.UI.Theme.Basic" Version="3.0.4" />
<PackageReference Include="Volo.Abp.Autofac" Version="3.0.4" />
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="3.0.4" />

Loading…
Cancel
Save