private void LerDetalheSegmentoU(ref BoletoDTO boleto, string registro) { try { var ocorrencia = registro.Substring(15, 2); switch (ocorrencia) { case "06": // Liquidação boleto.ValorPago = Convert.ToSingle(registro.Substring(77, 15)) / 100; boleto.DataPagamento = LerData(registro.Substring(137, 8)); boleto.Status = TipoStatusBoletoEnum.Liquidado.GetDescription(); break; case "09": // Baixa boleto.DataPagamento = LerData(registro.Substring(137, 8)); boleto.Status = TipoStatusBoletoEnum.Baixado.GetDescription(); break; default: log.Info("Tipo de movimentação desconhecido."); return; } } catch (Exception ex) { throw new Exception("Erro ao ler detalhe do arquivo de RETORNO / CNAB 240 / U.", ex); } }
internal TransacaoRetornoDTO Novo(Pessoa pessoa) { var boletoDto = new BoletoDTO(); boletoDto.ChaveApi = Constante.Chave; boletoDto.Valor = 5000; boletoDto.Cliente = new ClienteDTO(); boletoDto.Cliente.Id = "45"; boletoDto.Cliente.Nome = pessoa.Nome; boletoDto.Cliente.Pais = "br"; boletoDto.Cliente.Documentos = new List <DocumentoDTO> { new DocumentoDTO { Numero = pessoa.Documento, Tipo = "cpf" } }; using (var requisicao = new HttpClient()) { var configuracao = new JsonSerializerSettings(); configuracao.NullValueHandling = NullValueHandling.Ignore; configuracao.DefaultValueHandling = DefaultValueHandling.Ignore; requisicao.BaseAddress = new Uri(Constante.UrlBase); var conteudo = new StringContent(JsonConvert.SerializeObject(boletoDto, configuracao), Encoding.UTF8, MediaTypeNames.Application.Json); var resultado = requisicao.PostAsync(Constante.Transacao, conteudo).Result; if (!resultado.IsSuccessStatusCode) { var erro = JsonConvert.DeserializeObject <RetornoErroDTO>(resultado.Content.ReadAsStringAsync().Result); throw new Exception(erro.MensagemFormatada()); } return(JsonConvert.DeserializeObject <TransacaoRetornoDTO>(resultado.Content.ReadAsStringAsync().Result)); } }
private BoletoDTO LerDetalheSegmentoP(string registro) { try { var boleto = new BoletoDTO(); boleto.NossoNumero = registro.Substring(37, 20).Trim(); var ocorrencia = registro.Substring(15, 2); switch (ocorrencia) { case "01": // Criação boleto.Status = TipoStatusBoletoEnum.EmAberto.GetDescription(); break; default: log.Info("Tipo de movimentação desconhecido."); return(null); } boleto.NossoNumero = registro.Substring(37, 20).Trim(); boleto.SeuNumero = registro.Substring(62, 15).Trim(); boleto.DataVencimento = LerData(registro.Substring(77, 8)); boleto.Valor = Convert.ToSingle(registro.Substring(85, 13)) / 100; boleto.DataEmissao = LerData(registro.Substring(109, 8)); boleto.ValorJuros = Convert.ToSingle(registro.Substring(126, 13)) / 100; return(boleto); } catch (Exception ex) { throw new Exception("Erro ao ler detalhe do arquivo de RETORNO / CNAB 240 / P.", ex); } }
private void LerDetalheSegmentoQ(ref BoletoDTO boleto, string registro) { boleto.NomeAluno = registro.Substring(33, 40).Trim(); var cpf = registro.Substring(18, 15); cpf = cpf.Substring(4); boleto.CpfAluno = $"{cpf.Substring(0, 3)}.{cpf.Substring(3, 3)}.{cpf.Substring(6, 3)}-{cpf.Substring(9, 2)}"; }
public bool AlterarStatusBoleto(BoletoDTO boleto) { log.Info($"Alteração de status do boleto nº {boleto.SeuNumero}"); var boletoSalvo = boletoRepository.BuscarBoletoPorNumero(boleto.SeuNumero); if (boletoSalvo != null) { if (boleto.Status == TipoStatusBoletoEnum.Liquidado.GetDescription()) { if (!boleto.ValorPago.HasValue) { log.Error("Para liquidação de boleto o valor pago é obrigatório."); throw new BusinessException("Para liquidação de boleto o valor pago é obrigatório."); } if (!boleto.DataPagamento.HasValue) { log.Error("Para liquidação de boleto a data do pagamento é obrigatória."); throw new BusinessException("Para liquidação de boleto a data do pagamento é obrigatória."); } boletoSalvo.TipoStatusBoletoId = (int)TipoStatusBoletoEnum.Liquidado; boletoSalvo.DataPagamento = boleto.DataPagamento; boletoSalvo.ValorPago = boleto.ValorPago; } else if (boleto.Status == TipoStatusBoletoEnum.Baixado.GetDescription()) { if (boletoSalvo.TipoStatusBoletoId == (int)TipoStatusBoletoEnum.Liquidado) { log.Info("O boleto já possui o status Liquidado, não será alterado."); return(false); } boletoSalvo.TipoStatusBoletoId = (int)TipoStatusBoletoEnum.Baixado; boletoSalvo.DataPagamento = boleto.DataPagamento; } else if (boleto.Status == TipoStatusBoletoEnum.Negativado.GetDescription()) { if (boletoSalvo.TipoStatusBoletoId == (int)TipoStatusBoletoEnum.Liquidado) { log.Info("O boleto já possui o status Liquidado, não será alterado."); return(false); } boletoSalvo.TipoStatusBoletoId = (int)TipoStatusBoletoEnum.Negativado; boletoSalvo.DataPagamento = null; } boletoRepository.SaveChanges(); return(true); } else { log.Info($"Boleto nº {boleto.SeuNumero} não encontrado."); return(false); } }
private BoletoDTO LerDetalheSegmentoT(string registro) { try { var boleto = new BoletoDTO(); boleto.SeuNumero = registro.Substring(58, 15).Trim(); return(boleto); } catch (Exception ex) { throw new Exception("Erro ao ler detalhe do arquivo de RETORNO / CNAB 240 / T.", ex); } }
public bool AlterarStatusBoleto(BoletoDTO boleto) { return(boletoService.AlterarStatusBoleto(boleto)); }
private void LerDetalheSegmentoR(ref BoletoDTO boleto, string registro) { boleto.PercentualMulta = Convert.ToSingle(registro.Substring(74, 13)) / 100; }