public async Task <IActionResult> GetBaseAssetList() { string merchantId = this.GetUserMerchantId(); try { var iataAssets = _iataService.GetIataAssets(); var settlementAssetsResponse = await _payInternalClient.GetAvailableSettlementAssetsAsync(merchantId); var validAssets = settlementAssetsResponse.Assets.Where(x => iataAssets.ContainsKey(x)).ToList(); if (!validAssets.Any()) { return(NotFound(ErrorResponse.Create("Assets not configured for current merchant"))); } string baseAsset = await _merchantService.GetBaseAssetAsync(merchantId); var result = new List <BaseAssetItemModel>(); foreach (var asset in validAssets) { result.Add(new BaseAssetItemModel { Id = asset, Value = iataAssets[asset], IsSelected = asset == baseAsset }); } return(Ok(result)); } catch (DefaultErrorResponseException ex) { return(NotFound(ex.Error)); } catch (ErrorResponseException ex) { switch (ex.StatusCode) { case HttpStatusCode.NotFound: return(NotFound(ex.Error)); case HttpStatusCode.BadRequest: return(BadRequest(ex.Error)); default: throw; } } }
public async Task <IActionResult> GetFilterForCurrentMerchant() { var merchantId = this.GetUserMerchantId(); try { var filter = new FilterOfMerchantResponse(); IReadOnlyList <string> groupMerchants = await _merchantService.GetGroupMerchantsAsync(merchantId); var merchantsDictionary = new Dictionary <string, string>(); foreach (var groupMerchantId in groupMerchants) { var merchantName = await _merchantService.GetMerchantNameAsync(groupMerchantId); if (!string.IsNullOrEmpty(merchantName)) { merchantsDictionary.TryAdd(groupMerchantId, merchantName); } } var groupMerchantsFilterItems = new List <MerchantFilterItemModel>(); foreach (var item in merchantsDictionary.ToListOfFilterItems()) { groupMerchantsFilterItems.Add(new MerchantFilterItemModel { Id = item.Id, Value = item.Value, MerchantLogoUrl = await _merchantService.GetMerchantLogoUrlAsync(item.Id) }); } filter.GroupMerchants = groupMerchantsFilterItems; filter.BillingCategories = (await _iataService.GetIataBillingCategoriesAsync()).ToListOfFilterItems(); filter.SettlementAssets = _iataService.GetIataAssets().ToListOfFilterItems(); #region MaxRangeInBaseAsset var invoices = await _payInvoiceClient.GetByFilter(groupMerchants, new string[] { merchantId }, null, null, null, null, null); var calculatedInvoices = await CalcSettlementAmountInBaseAsset(Mapper.Map <IReadOnlyList <InvoiceResponseModel> >(invoices), merchantId); filter.MaxRangeInBaseAsset = calculatedInvoices.Any() ? Math.Ceiling(calculatedInvoices.Max(x => x.SettlementAmountInBaseAsset)) : 0; #endregion return(Ok(filter)); } catch (DefaultErrorResponseException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { return(NotFound(ex.Error)); } catch (ErrorResponseException ex) { switch (ex.StatusCode) { case HttpStatusCode.NotFound: return(NotFound(ex.Error)); case HttpStatusCode.BadRequest: return(BadRequest(ex.Error)); default: throw; } } catch (Exception ex) { _log.Error(ex, null, $"request:{new {merchantId}.ToJson()}"); throw; } }