public async Task <JsonResult> Balance() { string asset = "CHF"; double amount = 0d; // TODO: Move to base controller string id = User.Claims.First(u => u.Type == ClaimTypes.Sid).Value; try { MerchantBalanceResponse response = await _merchantAuthServiceClient.GetBalanceAsync(id); MerchantAssetBalance assetBalance = response.Assets?.FirstOrDefault(o => o.Asset == asset); if (assetBalance != null) { amount = assetBalance.Value; } } catch (Exception exception) { await _log.WriteErrorAsync(nameof(HomeController), nameof(Balance), MerchantId, exception); } return(Json($"{amount:0.00} {asset}")); }
/// <summary> /// Gets the merchant balance. /// </summary> /// <param name="accessToken">The access token.</param> /// <param name="estateId">The estate identifier.</param> /// <param name="merchantId">The merchant identifier.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns></returns> public async Task <MerchantBalanceResponse> GetMerchantBalance(String accessToken, Guid estateId, Guid merchantId, CancellationToken cancellationToken) { MerchantBalanceResponse response = null; String requestUri = this.BuildRequestUrl($"/api/estates/{estateId}/merchants/{merchantId}/balance"); try { // Add the access token to the client headers this.HttpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); // Make the Http Call here HttpResponseMessage httpResponse = await this.HttpClient.GetAsync(requestUri, cancellationToken); // Process the response String content = await this.HandleResponse(httpResponse, cancellationToken); // call was successful so now deserialise the body to the response object response = JsonConvert.DeserializeObject <MerchantBalanceResponse>(content); } catch (Exception ex) { // An exception has occurred, add some additional information to the message Exception exception = new Exception($"Error getting balance for merchant Id {merchantId} in estate {estateId}.", ex); throw exception; } return(response); }
public void ModelFactory_MerchantBalance_NullInput_IsConverted() { MerchantBalance merchantBalanceModel = null; ModelFactory modelFactory = new ModelFactory(); MerchantBalanceResponse merchantBalanceResponse = modelFactory.ConvertFrom(merchantBalanceModel); merchantBalanceResponse.ShouldBeNull(); }
public void ModelFactory_MerchantBalance_IsConverted() { MerchantBalance merchantBalanceModel = TestData.MerchantBalanceModel; ModelFactory modelFactory = new ModelFactory(); MerchantBalanceResponse merchantBalanceResponse = modelFactory.ConvertFrom(merchantBalanceModel); merchantBalanceResponse.ShouldNotBeNull(); merchantBalanceResponse.MerchantId.ShouldBe(merchantBalanceModel.MerchantId); merchantBalanceResponse.EstateId.ShouldBe(merchantBalanceModel.EstateId); merchantBalanceResponse.AvailableBalance.ShouldBe(merchantBalanceModel.AvailableBalance); merchantBalanceResponse.Balance.ShouldBe(merchantBalanceModel.Balance); }
public async Task GivenIMakeTheFollowingManualMerchantDeposits(Table table) { foreach (TableRow tableRow in table.Rows) { EstateDetails estateDetails = this.TestingContext.GetEstateDetails(tableRow); String token = this.TestingContext.AccessToken; if (String.IsNullOrEmpty(estateDetails.AccessToken) == false) { token = estateDetails.AccessToken; } // Lookup the merchant id String merchantName = SpecflowTableHelper.GetStringRowValue(tableRow, "MerchantName"); Guid merchantId = estateDetails.GetMerchantId(merchantName); // Get current balance MerchantBalanceResponse previousMerchantBalance = await this.TestingContext.DockerHelper.EstateClient.GetMerchantBalance(token, estateDetails.EstateId, merchantId, CancellationToken.None); MakeMerchantDepositRequest makeMerchantDepositRequest = new MakeMerchantDepositRequest { DepositDateTime = SpecflowTableHelper.GetDateForDateString(SpecflowTableHelper.GetStringRowValue(tableRow, "DateTime"), DateTime.Now), Reference = SpecflowTableHelper.GetStringRowValue(tableRow, "Reference"), Amount = SpecflowTableHelper.GetDecimalValue(tableRow, "Amount") }; MakeMerchantDepositResponse makeMerchantDepositResponse = await this.TestingContext.DockerHelper.EstateClient.MakeMerchantDeposit(token, estateDetails.EstateId, merchantId, makeMerchantDepositRequest, CancellationToken.None).ConfigureAwait(false); makeMerchantDepositResponse.EstateId.ShouldBe(estateDetails.EstateId); makeMerchantDepositResponse.MerchantId.ShouldBe(merchantId); makeMerchantDepositResponse.DepositId.ShouldNotBe(Guid.Empty); this.TestingContext.Logger.LogInformation($"Deposit Reference {makeMerchantDepositRequest.Reference} made for Merchant {merchantName}"); // Check the merchant balance await Retry.For(async() => { MerchantBalanceResponse currentMerchantBalance = await this.TestingContext.DockerHelper.EstateClient.GetMerchantBalance(token, estateDetails.EstateId, merchantId, CancellationToken.None); currentMerchantBalance.AvailableBalance.ShouldBe(previousMerchantBalance.AvailableBalance + makeMerchantDepositRequest.Amount); }, TimeSpan.FromMinutes(2)); } }