|
|
|
@ -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<OrderDto>(); |
|
|
|
|
|
|
|
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<string, object> {{"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<PaymentDto> UpdateAsync(Guid id, object input) |
|
|
|
|