public async Task <PartnerPaymentRequestDetailsResponse> FormatAsync(PaymentDetailsResponseModel ppResponseModel) { if (ppResponseModel == null) { throw new ArgumentNullException(nameof(ppResponseModel)); } #region Tasks var partnerTask = _partnerManagementClient.Partners.GetByIdAsync(Guid.Parse(ppResponseModel.PartnerId)); var customersBalanceTask = _pbfClient.CustomersApi.GetBalanceAsync(Guid.Parse(ppResponseModel.CustomerId)); var totalBillInBaseCurrencyTask = _currencyConverter.GetCurrencyAmountInBaseCurrencyAsync( ppResponseModel.TotalBillAmount, ppResponseModel.Currency, ppResponseModel.CustomerId, ppResponseModel.PartnerId); var totalBillInTokenTask = _currencyConverter.GetCurrencyAmountInTokensAsync( ppResponseModel.TotalBillAmount, ppResponseModel.Currency, ppResponseModel.CustomerId, ppResponseModel.PartnerId); await Task.WhenAll(partnerTask, customersBalanceTask, totalBillInBaseCurrencyTask, totalBillInTokenTask); #endregion #region Task results var partner = partnerTask.Result; var customersBalance = customersBalanceTask.Result; var totalBillInBaseCurrency = totalBillInBaseCurrencyTask.Result; var totalBillInToken = totalBillInTokenTask.Result; #endregion var paymentInfo = string.Empty; if (!string.IsNullOrEmpty(ppResponseModel.PartnerMessageId)) { var partnerMessageResponse = await _partnersIntegrationClient.MessagesApi.GetMessageAsync(ppResponseModel.PartnerMessageId); if (partnerMessageResponse == null) { _log.Error(null, "Could not find partner message", new { ppResponseModel.CustomerId, ppResponseModel.PaymentRequestId, ppResponseModel.PartnerMessageId }); } else { paymentInfo = partnerMessageResponse.Message; } } return(new PartnerPaymentRequestDetailsResponse { PaymentRequestId = ppResponseModel.PaymentRequestId, Date = ppResponseModel.Timestamp, Status = ppResponseModel.Status.ConvertToPublicStatus().ToString(), CurrencyCode = _currencyConverter.GetBaseCurrencyCode(), LocationId = ppResponseModel.LocationId, LocationName = partner.GetLocationName(ppResponseModel.LocationId), PartnerId = ppResponseModel.PartnerId, PartnerName = partner?.Name, WalletBalance = customersBalance.Total.ToDisplayString(), PaymentInfo = paymentInfo, LastUpdatedDate = ppResponseModel.LastUpdatedTimestamp, TokensToFiatConversionRate = ppResponseModel.TokensToFiatConversionRate, TotalInCurrency = decimal.Parse(totalBillInBaseCurrency.ToString()), TotalInToken = totalBillInToken.ToDisplayString(), SendingAmountInToken = ppResponseModel.TokensSendingAmount.ToDisplayString(), CustomerActionExpirationTimestamp = ppResponseModel.CustomerActionExpirationTimestamp, CustomerActionExpirationTimeLeftInSeconds = ppResponseModel.CustomerActionExpirationTimeLeftInSeconds, RequestedAmountInTokens = ppResponseModel.TokensAmount.ToDisplayString() }); }