//[ActionName("PostItau")]
        public BoletoOut PostItau(BoletoIn boletoIn)
        {
            GeradorItau geradorItau = new GeradorItau();
            var         boletoOut   = new BoletoOut();

            try
            {
                string MsgError = Validacao.ValidarGeral(boletoIn);
                if (!string.IsNullOrEmpty(MsgError))
                {
                    boletoOut.Sucesso  = false;
                    boletoOut.Mensagem = MsgError;
                    return(boletoOut);
                }

                //geradorItau.GerarBoletoTeste(boletoIn);
                geradorItau.GerarBoleto(boletoIn);
                boletoOut.Sucesso = true;
                return(boletoOut);
            }
            catch (Exception ex)
            {
                boletoOut.Sucesso = false;
                //boletoOut.Mensagem = "Falha Desconhecida: ";
                boletoOut.Mensagem = "Falha na Geração do Boleto: " + ex.Message;
                return(boletoOut);
            }
        }
Пример #2
0
        public BoletoOut GerarBoleto(BoletoIn boletoIn)
        {
            DateTime           vencimento = Convert.ToDateTime(boletoIn.Vencimento);
            Instrucao_Bradesco item       = new Instrucao_Bradesco(9, 5);

            Cedente cedente = new Cedente(boletoIn.Cedente.CNPJ, boletoIn.Cedente.Nome,
                                          boletoIn.Cedente.Agencia, boletoIn.Cedente.DigitoAgencia, boletoIn.Cedente.Conta, boletoIn.Cedente.DigitoConta);

            cedente.Codigo   = boletoIn.Cedente.Codigo;
            cedente.Convenio = 9;

            //Carteiras
            BoletoNet.Boleto b = new BoletoNet.Boleto(vencimento,
                                                      Convert.ToDecimal(boletoIn.Valor), "09", boletoIn.Numero, cedente);

            b.ValorMulta      = 0.10m;
            b.ValorCobrado    = 1.10m;
            b.NumeroDocumento = boletoIn.Numero;
            //b.DataVencimento = new DateTime(2015, 09, 12);

            b.Sacado = new Sacado(boletoIn.Sacado.CNPJ, boletoIn.Sacado.Nome);
            b.Sacado.Endereco.End    = boletoIn.Sacado.Endereco;
            b.Sacado.Endereco.Bairro = boletoIn.Sacado.Bairro;
            b.Sacado.Endereco.Cidade = boletoIn.Sacado.Cidade;
            b.Sacado.Endereco.CEP    = boletoIn.Sacado.CEP;
            b.Sacado.Endereco.UF     = boletoIn.Sacado.UF;

            item.Descricao += " após " + item.QuantidadeDias.ToString() + " dias corridos do vencimento.";
            b.Instrucoes.Add(item); //"Não Receber após o vencimento");

            var boletoBancario = new BoletoBancario();

            boletoBancario.CodigoBanco = 237;
            boletoBancario.MostrarContraApresentacaoNaDataVencimento = true;

            boletoBancario.Boleto = b;
            boletoBancario.Boleto.Valida();

            BoletoOut boletoOut = new BoletoOut();

            try
            {
                boletoOut.Boleto = ConvertBase64(SaveBoletoPDF(boletoBancario.MontaBytesPDF()));
                //boletoOut.Remessa = ConvertBase64(GerarRemessa(b.Cedente, boletoBancario.Boleto));
                return(boletoOut);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }