Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        public async Task <DesfazimentoEGiftResponse> DesfazimentoEGift(DesfazimentoEGiftRequest request)
        {
            var response = new DesfazimentoEGiftResponse();

            using (var httpClient = HelperBHNHttpService.ObterHttpClientBhn(_dadosBhn))
            {
                var formData = new
                {
                    reversalEGiftRequestId = request.RequisicaoId
                };

                var endpoint   = httpClient.BaseAddress + this._dadosBhn.DesfazimentoRota;
                var bhnRequest = new HttpRequestMessage(HttpMethod.Post, endpoint);

                using (var content = new StringContent(JsonConvert.SerializeObject(formData), Encoding.UTF8, "application/json"))
                {
                    bhnRequest.Content = content;
                    var bhnResponse = await httpClient.SendAsync(bhnRequest);

                    var responseString = bhnResponse.ConvertToString();

                    if (bhnResponse.Valido())
                    {
                        var responseObject = JsonConvert.DeserializeObject <DesfazimentoEGiftResponse>(responseString);
                        return(responseObject);
                    }
                    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);
        }
Beispiel #4
0
        public async Task <VersaoCatalogoResponse> VerificarVersao(VersaoCatalogoRequest request)
        {
            var response = new VersaoCatalogoResponse()
            {
                Catalogos = new List <DadosCatalogoResponse>()
            };

            using (var httpClient = HelperBHNHttpService.ObterHttpClientBhn(_dadosBhn))
            {
                var endpoint    = this._dadosBhn.VersaoCatalogoRota;
                var bhnResponse = await httpClient.GetAsync(endpoint);

                var responseString = bhnResponse.ConvertToString();

                if (bhnResponse.Valido())
                {
                    JObject bhnObjectResponse = JObject.Parse(responseString);
                    var     results           = bhnObjectResponse["results"].Children().ToList();

                    foreach (JToken result in results)
                    {
                        response.Catalogos.Add(new DadosCatalogoResponse()
                        {
                            IdCatalogo = result["entityId"].ToString().ObterEntityId(),
                            Nome       = result["name"].ToString(),
                            Versao     = result["version"].ToString(),
                        });
                    }

                    response.Total = response.Catalogos.Count;

                    return(response);
                }
                else
                {
                    var erro = JsonConvert.DeserializeObject <BHNErrorResponse>(responseString.TratarErrorResponse());
                    throw new BHNResponseException(bhnResponse.StatusCode, erro.ErrorCode, erro.Message);
                }
            }
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        public async Task <GenerateEGiftHashResponse> GerarHashEGift(GenerateEGiftHashRequest request)
        {
            var response = new GenerateEGiftHashResponse();

            using (var httpClient = HelperBHNHttpService.ObterHttpClientBhn(_dadosBhn))
            {
                var formData = new
                {
                    //giftFrom = "",
                    //giftTo = "",
                    //giftMessage = "",
                    //notes = "",
                    giftAmount = request.Preco,
                    //purchaserId = this._dadosBhn.VendedorId,
                    //recipientId = this._dadosBhn.VendedorId,
                    retrievalReferenceNumber = request.NumeroPedido,
                    productConfigurationId   = request.ProductConfigutationId
                };

                var endpoint   = httpClient.BaseAddress + this._dadosBhn.GerarHashRota;
                var bhnRequest = new HttpRequestMessage(HttpMethod.Post, endpoint);
                bhnRequest.Headers.Add("requestId", request.RequisicaoId);

                if (request.TentativasAnteriores > 0)
                {
                    bhnRequest.Headers.Add("previousAttempts", request.TentativasAnteriores.ToString());
                }

                using (var content = new StringContent(JsonConvert.SerializeObject(formData), Encoding.UTF8, "application/json"))
                {
                    bhnRequest.Content = content;

                    var log_request = string.Format("{0} {1}", bhnRequest.ToString(), bhnRequest.Content.ReadAsStringAsync().Result);

                    var bhnResponse = await httpClient.SendAsync(bhnRequest);

                    var responseString = bhnResponse.ConvertToString();

                    var log_response = string.Format("{0} {1}", bhnResponse.ToString(), responseString);

                    response.AdicionarMensagemErro(TipoMensagem.Aplicacao, log_request);
                    response.AdicionarMensagemErro(TipoMensagem.Aplicacao, log_response);

                    if (bhnResponse.Valido())
                    {
                        var responseObject = JObject.Parse(responseString);
                        response.EntityId      = responseObject["entityId"].ToString().ObterEntityId();
                        response.AccountId     = responseObject["accountId"].ToString().ObterAccountId();
                        response.Status        = responseObject["status"].ToString();
                        response.ActivationUrl = string.Format(this._dadosBhn.TemplateActivationSpot, response.EntityId);

                        return(response);
                    }
                    else
                    {
                        var erro = JsonConvert.DeserializeObject <BHNErrorResponse>(responseString.TratarErrorResponse());
                        throw new BHNResponseException(bhnResponse.StatusCode, erro.ErrorCode, erro.Message);
                    }
                }
            }
        }