Exemplo n.º 1
0
        public async Task <InvoiceIataSpecificData> GetIataSpecificDataAsync(string invoiceId)
        {
            var invoiceIataSpecificData = await _invoiceIataSpecificDataCache.GetOrAddAsync
                                          (
                $"InvoiceIataSpecificData-{invoiceId}",
                async x => {
                try
                {
                    var response = await _iataApiClient.GetInvoiceByIdAsync(invoiceId);

                    return(new InvoiceIataSpecificData
                    {
                        IsIataInvoice = true,
                        IataInvoiceDate = response.Date.ToString("yyyy-MM-dd"),
                        SettlementMonthPeriod = response.SettlementMonthPeriod
                    });
                }
                catch (ErrorResponseException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
                {
                    return(new InvoiceIataSpecificData {
                        IsIataInvoice = false
                    });
                }
            },
                DateTime.UtcNow.AddYears(1)
                                          );

            return(invoiceIataSpecificData.IsIataInvoice ? invoiceIataSpecificData : null);
        }
Exemplo n.º 2
0
        private async Task <IReadOnlyDictionary <string, BlockchainType> > GetAssetsNetworkAsync()
        {
            var result = await _assetsNetworkCache.GetOrAddAsync
                         (
                "AssetsNetworkCache",
                async _ => {
                try
                {
                    IEnumerable <AssetGeneralSettingsResponse> response =
                        await _payInternalClient.GetAssetGeneralSettingsAsync();

                    return(response.ToDictionary(x => x.AssetDisplayId, x => x.Network));
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                    return(null);
                }
            },
                // cache for a small period in order to foreach in memory on assets if any asset has not yet cached
                TimeSpan.FromSeconds(1)
                         );

            return(result ?? new Dictionary <string, BlockchainType>());
        }
 private Task <string> GetCachedCustomerWalletAddressAsync(string customerId)
 {
     return(_customerWalletsCache.GetOrAddAsync(
                customerId,
                GetCustomerWalletAddressAsync,
                _customerWalletsCacheExpirationPeriod));
 }
        private Task <IEnumerable <VolatilityModel> > GetCachedValueAsync(string key, Func <Task <IEnumerable <VolatilityModel> > > factory)
        {
            if (_settings.ExpirationTimeUTC.HasValue)
            {
                DateTimeOffset expiration = DateTime.UtcNow.Date.Add(_settings.ExpirationTimeUTC.Value.TimeOfDay);
                if (expiration <= DateTime.UtcNow)
                {
                    expiration = expiration.AddDays(1);
                }
                return(_memoryCache.GetOrAddAsync(key, k => factory(), expiration));
            }

            if (_settings.CachePeriod.HasValue)
            {
                return(_memoryCache.GetOrAddAsync(key, k => factory(), _settings.CachePeriod.Value));
            }

            return(_memoryCache.GetOrAddAsync(key, k => factory(), TimeSpan.FromHours(CacheHours)));
        }
Exemplo n.º 5
0
        public async Task <string> GetMerchantNameAsync(string merchantId)
        {
            var merchantName = await _merchantNamesCache.GetOrAddAsync
                               (
                $"MerchantName-{merchantId}",
                async x => {
                var merchant = await _payMerchantClient.Api.GetByIdAsync(merchantId);
                return(merchant.DisplayName);
            },
                _cacheExpirationPeriods.MerchantName
                               );

            return(merchantName);
        }
Exemplo n.º 6
0
        public async Task <string> GetMerchantLogoUrlAsync(string merchantId)
        {
            var merchantLogoUrl = await _merchantLogoUrlsCache.GetOrAddAsync
                                  (
                $"MerchantLogoUrl-{merchantId}",
                async x => {
                try
                {
                    return(await _payInternalClient.GetMerchantLogoUrl(merchantId));
                }
                catch (DefaultErrorResponseException ex) when(ex.StatusCode == HttpStatusCode.NotFound)
                {
                    return(_merchantSettings.MerchantDefaultLogoUrl);
                }
            },
                _cacheExpirationPeriods.MerchantLogoUrl
                                  );

            return(merchantLogoUrl);
        }
Exemplo n.º 7
0
        public async Task <IReadOnlyDictionary <string, string> > GetIataBillingCategoriesAsync()
        {
            var iataBillingCategories = await _iataBillingCategories.GetOrAddAsync
                                        (
                "IataBillingCategories",
                async x => {
                try
                {
                    IReadOnlyList <string> response = await _iataApiClient.GetBillingCategoriesAsync();
                    return(response);
                }
                catch (ErrorResponseException)
                {
                    return(new List <string>());
                }
            },
                _cacheExpirationPeriodsSettings.IataBillingCategories
                                        );

            return(iataBillingCategories?.ToDictionary(x => x, x => x));
        }
Exemplo n.º 8
0
        public async Task <BlockchainType> GetAssetNetworkAsync(string assetId)
        {
            var result = await _assetBlockchainTypeCache.GetOrAddAsync
                         (
                $"AssetBlockchainTypeCache-{assetId}",
                async _ =>
            {
                try
                {
                    var assetsNetwork = await GetAssetsNetworkAsync();

                    return(assetsNetwork.TryGetValue(assetId, out var network) ? new Tuple <BlockchainType>(network) : new Tuple <BlockchainType>(BlockchainType.None));
                }
                catch (Exception ex)
                {
                    _log.Error(ex);
                    return(null);
                }
            }
                         );

            return(result?.Item1 ?? BlockchainType.None);
        }
        public async Task <IReadOnlyList <HistoryItem> > GetHistoryAsync(string merchantId, string invoiceId)
        {
            IReadOnlyList <HistoryItemModel> history = await _payInvoiceClient.GetInvoiceHistoryAsync(invoiceId);

            history = history
                      .GroupBy(o => o.Status)
                      .Where(o => !_excludeStatusesFromHistory.Contains(o.Key))
                      .SelectMany(o => _getOnlyFirstStatusesFromHistory.Contains(o.Key)
                    ? new List <HistoryItemModel> {
                o.OrderBy(s => s.Date).First()
            }
                    : o.ToList())
                      .OrderBy(o => o.Date)
                      .ToList();

            var items = new List <HistoryItem>();

            foreach (HistoryItemModel item in history)
            {
                var authorFullName = string.Empty;

                if (!string.IsNullOrEmpty(item.ModifiedById))
                {
                    authorFullName = await _employeeFullNameCache.GetOrAddAsync
                                     (
                        $"EmployeeFullNameCache-{item.ModifiedById}",
                        async _ => {
                        try
                        {
                            var employee = await _payInvoiceClient.GetEmployeeAsync(item.ModifiedById);
                            return(employee != null ? $"{employee.FirstName} {employee.LastName}" : string.Empty);
                        }
                        catch (Exception ex)
                        {
                            _log.Error(ex);
                            return(null);
                        }
                    }
                                     );
                }

                Asset historySettlementAsset = await _lykkeAssetsResolver.TryGetAssetAsync(item.SettlementAssetId);

                Asset historyPeymentAsset = await _lykkeAssetsResolver.TryGetAssetAsync(item.PaymentAssetId);

                items.Add(new HistoryItem
                {
                    AuthorFullName        = authorFullName,
                    Status                = item.Status,
                    PaymentAmount         = item.PaymentAmount,
                    SettlementAmount      = item.SettlementAmount,
                    PaidAmount            = item.PaidAmount,
                    PaymentAsset          = historyPeymentAsset,
                    SettlementAsset       = historySettlementAsset,
                    ExchangeRate          = item.ExchangeRate,
                    SourceWalletAddresses = item.SourceWalletAddresses,
                    RefundWalletAddress   = item.RefundWalletAddress,
                    RefundAmount          = item.RefundAmount,
                    DueDate               = item.DueDate,
                    PaidDate              = item.PaidDate,
                    Date = item.Date
                });
            }

            return(items);
        }