public RetornoPagamentoDTO ExecutePOSTWebAPI(string resourceName, object classObj) { using (var client = new HttpClient()) { //Bypass SSL Certificate if you want, otherwise remove this line of code ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true; RetornoPagamentoDTO returnPagamentoDTO = new RetornoPagamentoDTO(); var retornoserealizer = Serialize.SerializeData(classObj); var httpContent = new StringContent(retornoserealizer, Encoding.UTF8, "application/xml"); var response = client.PostAsync(resourceName, httpContent).Result; var jsonString = response.Content.ReadAsStringAsync().Result; if (response.StatusCode == HttpStatusCode.OK) { returnPagamentoDTO.transaction = Deserialize.DeserializeData <RetornoPagamentoDTO.Transaction>(jsonString); return(returnPagamentoDTO); } else { var retornoErro = Deserialize.DeserializeData <DTOS.Errors>(jsonString); returnPagamentoDTO.Errors = retornoErro; } return(returnPagamentoDTO); //} //catch (Exception exp) //{ // return new ReturnPagamentoDTO(); //} } }
public async Task <RetornoPagamentoDTO> TransacaoCartaoCredito(PagamentoDTO pagamentoDTO) { RetornoPagamentoDTO result = null; try { string json = JsonConvert.SerializeObject(pagamentoDTO); var response = await _requisicao.PostRequest(json, "https://localhost:44333/api/compras/pagamento"); if (response.IsSuccessStatusCode) { var responseString = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <RetornoPagamentoDTO>(responseString); } else { result = null; } } catch (Exception e) { result = null; Console.WriteLine(e.Message); } return(result); }
public ActionResult <RetornoPagamentoDTO> Compra(PagamentoDTO pagamentoDTO) { RetornoPagamentoDTO retornoPagamento = new RetornoPagamentoDTO(); retornoPagamento.Valor = pagamentoDTO.Valor; if (pagamentoDTO.Valor > 100) { retornoPagamento.Estado = "APROVADO"; } else { retornoPagamento.Estado = "REJEITADO"; } return(retornoPagamento); }