Пример #1
0
        public async Task <IActionResult> ResolveAssetsByMerchant(string merchantId,
                                                                  [FromQuery] AssetAvailabilityType type)
        {
            IMerchant merchant = await _merchantService.GetAsync(merchantId);

            if (merchant == null)
            {
                return(NotFound(ErrorResponse.Create("Couldn't find merchant")));
            }

            try
            {
                IReadOnlyList <string> resolvedAssets = await _assetsAvailabilityService.ResolveAsync(merchantId, type);

                return(Ok(new AvailableAssetsResponseModel {
                    Assets = resolvedAssets
                }));
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(MerchantsController), nameof(ResolveAssetsByMerchant), new
                {
                    merchantId,
                    type
                }.ToJson(), ex);

                throw;
            }
        }
        public async Task <IReadOnlyList <string> > ResolveAsync(string merchantId, AssetAvailabilityType type)
        {
            IAssetMerchantSettings personalSettings = await _assetMerchantSettingsRepository.GetAsync(merchantId);

            string personalAllowed;

            switch (type)
            {
            case AssetAvailabilityType.Payment:
                personalAllowed = personalSettings?.PaymentAssets;
                break;

            case AssetAvailabilityType.Settlement:
                personalAllowed = personalSettings?.SettlementAssets;
                break;

            default:
                throw new Exception("Unexpected asset availability type");
            }

            IEnumerable <string> generalAllowed = (await _assetGeneralSettingsRepository.GetAsync(type)).Select(x => x.AssetId);

            if (string.IsNullOrEmpty(personalAllowed))
            {
                return(generalAllowed.ToList());
            }

            IEnumerable <string> resolved =
                personalAllowed.Split(AssetsSeparator).Where(x => generalAllowed.Contains(x));

            return(resolved.ToList());
        }
Пример #3
0
        //todo: move to private
        public async Task <IReadOnlyList <string> > ResolveAsync(string merchantId, AssetAvailabilityType type)
        {
            IAssetAvailabilityByMerchant personal = await _assetPersonalAvailabilityRepository.GetAsync(merchantId);

            string allowedAssets;

            switch (type)
            {
            case AssetAvailabilityType.Payment:
                allowedAssets = personal?.PaymentAssets ?? _assetsAvailabilitySettings.PaymentAssets;
                break;

            case AssetAvailabilityType.Settlement:
                allowedAssets = personal?.SettlementAssets ?? _assetsAvailabilitySettings.SettlementAssets;
                break;

            default:
                throw new Exception("Unexpected asset availability type");
            }

            IEnumerable <string> generalAllowed =
                (await _assetGeneralAvailabilityRepository.GetAsync(type)).Select(x => x.AssetId);

            IEnumerable <string> resolved = allowedAssets.Split(AssetsSeparator).Where(x => generalAllowed.Contains(x));

            return(resolved.ToList());
        }
Пример #4
0
        public async Task <IActionResult> GetGeneralAssetsSettings([FromQuery] AssetAvailabilityType type)
        {
            try
            {
                IReadOnlyList <IAssetAvailability> assets = await _assetsAvailabilityService.GetGeneralByTypeAsync(type);

                return(Ok(new AvailableAssetsResponseModel {
                    Assets = assets.Select(x => x.AssetId).ToList()
                }));
            }
            catch (Exception ex)
            {
                await _log.WriteErrorAsync(nameof(AssetsController), nameof(GetGeneralAssetsSettings), ex);

                throw;
            }
        }
Пример #5
0
        public async Task <IReadOnlyList <IAssetAvailability> > GetAsync(AssetAvailabilityType availability)
        {
            IList <AssetAvailabilityEntity> result = await _tableStorage.GetDataAsync(a =>
            {
                switch (availability)
                {
                case AssetAvailabilityType.Payment:
                    return(a.PaymentAvailable);

                case AssetAvailabilityType.Settlement:
                    return(a.SettlementAvailable);

                default:
                    throw new Exception($"Unexpected asset availability type {availability.ToString()}");
                }
            });

            return(result.ToList());
        }
Пример #6
0
        public async Task <IAssetAvailability> SetAsync(string assetId, AssetAvailabilityType availability, bool value)
        {
            string partitionKey = AssetAvailabilityEntity.ByAsset.GeneratePartitionKey(assetId);
            string rowKey       = AssetAvailabilityEntity.ByAsset.GenerateRowKey(assetId);

            AssetAvailabilityEntity exItem = await _tableStorage.GetDataAsync(partitionKey, rowKey);

            if (exItem != null)
            {
                AssetAvailabilityEntity merged = await _tableStorage.MergeAsync(partitionKey, rowKey, item =>
                {
                    switch (availability)
                    {
                    case AssetAvailabilityType.Payment:
                        item.PaymentAvailable = value;
                        break;

                    case AssetAvailabilityType.Settlement:
                        item.SettlementAvailable = value;
                        break;

                    default:
                        throw new Exception($"Unexpected asset availability type {availability.ToString()}");
                    }

                    return(item);
                });

                return(merged);
            }

            var newItem = AssetAvailabilityEntity.ByAsset.Create(new AssetAvailability
            {
                AssetId             = assetId,
                PaymentAvailable    = availability == AssetAvailabilityType.Payment && value,
                SettlementAvailable = availability == AssetAvailabilityType.Settlement && value
            });

            await _tableStorage.InsertAsync(newItem);

            return(newItem);
        }
 public async Task <IReadOnlyList <IAssetGeneralSettings> > GetGeneralAsync(AssetAvailabilityType type)
 {
     return(await _assetGeneralSettingsRepository.GetAsync(type));
 }
Пример #8
0
 public Task <AvailableAssetsResponse> ResolveAvailableAssetsAsync(string merchantId, AssetAvailabilityType type)
 {
     return(_runner.RunWithDefaultErrorHandlingAsync(() => _merchantsApi.GetAvailableAssetsAsync(merchantId, type)));
 }
Пример #9
0
 public Task <AvailableAssetsResponse> GetGeneralAvailableAssetsAsync(AssetAvailabilityType type)
 {
     return(_runner.RunWithDefaultErrorHandlingAsync(() => _assetsApi.GetGeneralAvailableAssetsAsync(type)));
 }
Пример #10
0
 public async Task <IAssetAvailability> SetGeneralAsync(string assetId, AssetAvailabilityType type, bool value)
 {
     return(await _assetGeneralAvailabilityRepository.SetAsync(assetId, type, value));
 }