public async Task <GenerateEGiftKeyResponse> GerarKeyEGift(GenerateEGiftKeyRequest request) { var response = new GenerateEGiftKeyResponse(); using (var httpClient = HelperBHNHttpService.ObterHttpClientBhn(_dadosBhn)) { var endpoint = HelperBHNHttpService.ObterEndPoint(this._dadosBhn.GerarKeyRota, request.IdCliente); var bhnResponse = await httpClient.GetAsync(endpoint); var responseString = bhnResponse.ConvertToString(); var log_response = string.Format("{0} {1}", bhnResponse.ToString(), responseString); response.AdicionarMensagemErro(TipoMensagem.Aplicacao, log_response); if (bhnResponse.Valido()) { var responseObject = JsonConvert.DeserializeObject <GerarKeyResponse>(responseString).Map(); response.AccountNumber = responseObject.AccountNumber; response.ActivationAccountNumber = responseObject.ActivationAccountNumber; response.BalanceResponse = responseObject.BalanceResponse; response.EntityId = responseObject.EntityId.ObterAccountId(); response.SecurityCode = responseObject.SecurityCode; return(response); } else { var erro = JsonConvert.DeserializeObject <BHNErrorResponse>(responseString.TratarErrorResponse()); throw new BHNResponseException(bhnResponse.StatusCode, erro.ErrorCode, erro.Message); } } }
public async Task <ObterDetalhesProdutoResponse> DetalhesProduto(ObterDetalhesProdutoRequest request) { var response = new ObterDetalhesProdutoResponse() { Configuracoes = new List <ConfiguracaoProdutoResponse>() }; using (var httpClient = HelperBHNHttpService.ObterHttpClientBhn(_dadosBhn)) { var endpoint = HelperBHNHttpService.ObterEndPoint(this._dadosBhn.DetalhesProdutoRota, request.IdProduto); var bhnResponse = await httpClient.GetAsync(endpoint); var responseString = bhnResponse.ConvertToString(); if (bhnResponse.Valido()) { JObject bhnObjectResponse = JObject.Parse(responseString); response.IdProduto = bhnObjectResponse["entityId"].ToString().ObterEntityId(); response.Nome = bhnObjectResponse["summary"]["productName"].ToString(); response.Preco = Convert.ToDecimal(bhnObjectResponse["details"]["activationCharacteristics"]["baseValueAmount"].ToString()); response.PrecoMaximo = Convert.ToDecimal(bhnObjectResponse["details"]["activationCharacteristics"]["maxValueAmount"].ToString()); response.ConfiguracaoPadrao = bhnObjectResponse["details"]["defaultProductConfigurationId"].ToString(); var configurations = bhnObjectResponse["details"]["productConfigurations"].Children().ToList(); foreach (JToken config in configurations) { response.Configuracoes.Add(new ConfiguracaoProdutoResponse() { Id = config["configurationId"].ToString(), Nome = config["configurationName"].ToString() }); } } else { var erro = JsonConvert.DeserializeObject <BHNErrorResponse>(responseString.TratarErrorResponse()); throw new BHNResponseException(bhnResponse.StatusCode, erro.ErrorCode, erro.Message); } } return(response); }
public async Task <ObterCatalogoResponse> ObterCatalogo(ObterCatalogoRequest request) { var response = new ObterCatalogoResponse() { DadosCatalogo = new DadosCatalogoResponse(), IdProdutos = new List <string>() }; using (var httpClient = HelperBHNHttpService.ObterHttpClientBhn(_dadosBhn)) { var endpoint = HelperBHNHttpService.ObterEndPoint(this._dadosBhn.DetalhesCatalogoRota, request.IdCatalogo); var bhnResponse = await httpClient.GetAsync(endpoint); var responseString = bhnResponse.ConvertToString(); if (bhnResponse.Valido()) { JObject bhnObjectResponse = JObject.Parse(responseString); response.DadosCatalogo = new DadosCatalogoResponse() { IdCatalogo = bhnObjectResponse["summary"]["entityId"].ToString().ObterEntityId(), Nome = bhnObjectResponse["summary"]["name"].ToString(), Versao = bhnObjectResponse["summary"]["version"].ToString(), }; var details = bhnObjectResponse["details"]["productIds"].Children().Select(s => s.ToString().ObterEntityId()).ToList(); response.IdProdutos = details; } else { var erro = JsonConvert.DeserializeObject <BHNErrorResponse>(responseString.TratarErrorResponse()); throw new BHNResponseException(bhnResponse.StatusCode, erro.ErrorCode, erro.Message); } } return(response); }