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) { orders.Add(await _orderAppService.GetAsync(orderId)); } var createPaymentEto = new CreatePaymentEto { TenantId = CurrentTenant.Id, UserId = CurrentUser.GetId(), PaymentMethod = input.PaymentMethod, Currency = orders.First().Currency, ExtraProperties = new Dictionary <string, object>(), PaymentItems = orders.Select(order => new CreatePaymentItemEto { ItemType = PaymentsConsts.PaymentItemType, ItemKey = order.Id.ToString(), OriginalPaymentAmount = order.TotalPrice, ExtraProperties = new Dictionary <string, object> { { "StoreId", orders.First().StoreId.ToString() } } }).ToList() }; await _payableChecker.CheckAsync(input, orders, createPaymentEto); await _distributedEventBus.PublishAsync(createPaymentEto); }
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) { orders.Add(await _orderAppService.GetAsync(orderId)); } await AuthorizationService.CheckAsync( new PaymentCreationResource { Input = input, Orders = orders }, new PaymentOperationAuthorizationRequirement(PaymentOperation.Creation) ); var paymentItems = orders.Select(order => { var eto = new CreatePaymentItemEto { ItemType = PaymentsConsts.PaymentItemType, ItemKey = order.Id.ToString(), OriginalPaymentAmount = order.ActualTotalPrice }; eto.SetProperty(nameof(PaymentItem.StoreId), order.StoreId); return(eto); }).ToList(); var createPaymentEto = new CreatePaymentEto( CurrentTenant.Id, CurrentUser.GetId(), input.PaymentMethod, orders.First().Currency, paymentItems ); input.MapExtraPropertiesTo(createPaymentEto); await _distributedEventBus.PublishAsync(createPaymentEto); }
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, createPaymentEto); } }
public virtual Task CheckAsync(CreatePaymentDto input, List <OrderDto> orders, CreatePaymentEto createPaymentEto) { foreach (var order in orders.Where(order => order.PaymentId.HasValue || order.PaidTime.HasValue)) { throw new OrderPaymentAlreadyExistsException(order.Id); } if (orders.Select(order => order.Currency).Distinct().Count() != 1) { // Todo: convert to a single currency. throw new MultiCurrencyNotSupportedException(); } return(Task.CompletedTask); }