Exemplo n.º 1
0
        private Boleto CriarRetornoBoleto(XDocument xml)
        {
            var codigoBanco    = xml.Descendants("codBanco")?.FirstOrDefault()?.Value;
            var codigoConvenio = xml.Descendants("codConv")?.FirstOrDefault()?.Value;

            var convenio = new Convenio(int.Parse(codigoBanco), int.Parse(codigoConvenio));

            #region Pagador

            var tipoDocumento   = int.Parse(xml.Descendants("tpDoc")?.FirstOrDefault()?.Value);
            var numeroDocumento = xml.Descendants("numDoc")?.FirstOrDefault()?.Value;
            var nome            = xml.Descendants("nome")?.FirstOrDefault()?.Value;
            var endereco        = xml.Descendants("ender")?.FirstOrDefault()?.Value;
            var bairro          = xml.Descendants("bairro")?.FirstOrDefault()?.Value;
            var cidade          = xml.Descendants("cidade")?.FirstOrDefault()?.Value;
            var uf  = xml.Descendants("uf")?.FirstOrDefault()?.Value;
            var cep = xml.Descendants("cep")?.FirstOrDefault()?.Value;

            if (tipoDocumento == 1)
            {
                numeroDocumento = numeroDocumento?.Substring(4, 11);
            }

            #endregion

            #region Titulo

            var dataEmissao        = StringParaData(xml.Descendants("dtEmissao")?.FirstOrDefault()?.Value);
            var dataLimiteDesconto = StringParaData(xml.Descendants("dtLimiDesc")?.FirstOrDefault()?.Value);
            var dataVencimento     = StringParaData(xml.Descendants("dtVencto")?.FirstOrDefault()?.Value);
            var especie            = (Especie)int.Parse(xml.Descendants("especie")?.FirstOrDefault()?.Value);
            var nossoNumero        = xml.Descendants("nossoNumero")?.FirstOrDefault()?.Value;
            var juros         = StringParaDouble(xml.Descendants("pcJuro")?.FirstOrDefault()?.Value);
            var multa         = StringParaDouble(xml.Descendants("pcMulta")?.FirstOrDefault()?.Value);
            var baixarApos    = int.Parse(xml.Descendants("qtDiasBaixa")?.FirstOrDefault()?.Value);
            var multaApos     = int.Parse(xml.Descendants("qtDiasMulta")?.FirstOrDefault()?.Value);
            var protestarApos = int.Parse(xml.Descendants("qtDiasProtesto")?.FirstOrDefault()?.Value);
            var quantidadePagamentosPossiveis = int.Parse(xml.Descendants("qtdParciais")?.FirstOrDefault()?.Value);
            var seuNumero        = xml.Descendants("seuNumero")?.FirstOrDefault()?.Value;
            var tipoPagamento    = (TipoPagamento)int.Parse(xml.Descendants("tipoPagto")?.FirstOrDefault()?.Value);
            var tipoValor        = (TipoValor)int.Parse(xml.Descendants("tipoValor")?.FirstOrDefault()?.Value);
            var tipoDesconto     = (TipoDesconto)int.Parse(xml.Descendants("tpDesc")?.FirstOrDefault()?.Value);
            var tipoProtesto     = (TipoProtesto)int.Parse(xml.Descendants("tpProtesto")?.FirstOrDefault()?.Value);
            var percentualMaximo = StringParaDouble(xml.Descendants("valorMaximo")?.FirstOrDefault()?.Value);
            var percentualMinimo = StringParaDouble(xml.Descendants("valorMinimo")?.FirstOrDefault()?.Value);
            var valorAbatimento  = StringParaDouble(xml.Descendants("vlAbatimento")?.FirstOrDefault()?.Value);
            var valorDesconto    = StringParaDouble(xml.Descendants("vlDesc")?.FirstOrDefault()?.Value);
            var valor            = StringParaDouble(xml.Descendants("vlNominal")?.FirstOrDefault()?.Value);

            #endregion

            var pagador    = new Pagador(numeroDocumento, nome, endereco, bairro, cidade, uf, cep);
            var instrucoes = new InstrucoesDoTitulo(multa, multaApos, juros, tipoDesconto, valorDesconto, dataLimiteDesconto, valorAbatimento, tipoProtesto, protestarApos, baixarApos, tipoPagamento, quantidadePagamentosPossiveis, tipoValor, percentualMinimo, percentualMaximo);
            var titulo     = new Titulo(valor, especie, nossoNumero, seuNumero, dataVencimento.Value, dataEmissao.Value, "", instrucoes, false);

            return(new Boleto(convenio, pagador, titulo));
        }
Exemplo n.º 2
0
        private XElement[] SerializarSonda(Convenio convenio)
        {
            var dados = new List <XElement>();

            dados.Add(SerializarEntry("CONVENIO.COD-BANCO", convenio.CodigoBanco));
            dados.Add(SerializarEntry("CONVENIO.COD-CONVENIO", convenio.CodigoConvenio));

            return(dados.ToArray());
        }
Exemplo n.º 3
0
        private string GerarTicketParaSondagem(Convenio convenio, string nsu, DateTime dataNsu)
        {
            var tiquet = CriarTicket(SerializarSonda(convenio));

            var resposta = EnviarRequisicao(tiquet, TicketEndpoint);

            var retCode = int.Parse(resposta.Descendants("retCode").FirstOrDefault()?.Value);

            if (retCode == 0)
            {
                return(resposta.Descendants("ticket")?.FirstOrDefault()?.Value);
            }

            throw new NetBoletoSantanderException(retCode);
        }
Exemplo n.º 4
0
        public (Boleto, RetornoTitulo) SondarBoleto(Convenio convenio, string nsu, DateTime dataNsu)
        {
            if (string.IsNullOrEmpty(nsu))
            {
                throw new ArgumentException("Valor não pode ser null ou vazio.", nameof(nsu));
            }

            nsu = Ambiente == Ambiente.Teste ? $"TST{nsu}" : nsu;

            var ticket = GerarTicketParaSondagem(convenio, nsu, dataNsu);

            var resposta = EnviarRequisicao(SerializarEnvelopeEnvio(false, ticket, nsu, dataNsu), CobrancaEndpoint);

            var retornoTitulo = CriarRetornoTitulo(resposta);
            var boleto        = CriarRetornoBoleto(resposta);

            return(boleto, retornoTitulo);
        }