public async Task <PagamentoResponseDto> AutorizarPagamento(PagamentoRequestDto pagamentoRequest)
        {
            PagamentoResponseDto pagamentoDto = null;

            var appSettings = _configuration.GetSection("AppSettings");
            var url         = appSettings["UrlGatewayPagamento"];

            var json          = JsonSerializer.Serialize(pagamentoRequest);
            var stringContent = new StringContent(json, Encoding.UTF8, "application/json");
            var _httpClient   = new HttpClient();
            var response      = _httpClient.PostAsync(url, stringContent).ContinueWith(http =>
            {
                if (http.Status == TaskStatus.RanToCompletion)
                {
                    var result   = http.Result.Content.ReadAsStringAsync().Result;
                    pagamentoDto = JsonSerializer.Deserialize <PagamentoResponseDto>(result,
                                                                                     new JsonSerializerOptions {
                        PropertyNameCaseInsensitive = true
                    });
                }
            });

            await response;

            return(pagamentoDto);
        }
Exemplo n.º 2
0
        public async Task <PagamentoResponseDto> AutorizarPagamento(PagamentoRequestDto pagamentorequestDto)
        {
            var pagamentoresponse = new PagamentoResponseDto
            {
                Valor  = pagamentorequestDto.Valor,
                Estado = pagamentorequestDto.Valor > 100 ? "APROVADO" : "REJEITADO"
            };

            return(pagamentoresponse);
        }
Exemplo n.º 3
0
        public async Task <ActionResult> AutorizarPagamento(PagamentoRequestDto pagamentoRequest)
        {
            try
            {
                var pagamentoResponse = await _pagamentoService.AutorizarPagamento(pagamentoRequest);

                return(Ok(pagamentoResponse));
            }
            catch
            {
                return(BadRequest("Ocorreu um erro desconhecido."));
            }
        }
Exemplo n.º 4
0
        private async Task AutorizarPagamento(CartaoDto cartaoDto, double valor)
        {
            var pagamentoSem = new PagamentoRequestDto
            {
                Cartao = cartaoDto,
                Valor  = valor
            };
            var gatewayPagamento   = new GatewayPagamento(_configuration);
            var autorizarPagamento = await gatewayPagamento.AutorizarPagamento(pagamentoSem);

            if (autorizarPagamento == null || !autorizarPagamento.Estado.Equals("APROVADO"))
            {
                throw new Exception();
            }
        }