Ejemplo n.º 1
0
        private FuncionarioModel ToModel() =>
        new FuncionarioModel
        {
            id               = funcionario?.id ?? 0,
            nome             = tbNome.Text,
            cpf              = Mascara.Remover(tbCpf.Text),
            genero           = cbGenero.SelectedIndex == 0 ? Genero.Masculino : Genero.Feminino,
            dataDeNascimento = DataUtil.Converter(tbDataNascimento.Text),

            cargo          = cargos[cbCargo.SelectedIndex],
            dataDeAdmissao = DataUtil.Converter(tbDataAdminissao.Text),
            salario        = tbSalario.Text != string.Empty ? decimal.Parse(tbSalario.Text) : 0,

            dddCel   = tbDddCel.Text.Trim(),
            celular  = tbCelular.Text,
            dddTel   = tbDddTel.Text.Trim(),
            telefone = tbTelefone.Text,
            email    = tbEmail.Text,

            endereco = ToModelEndereco(),

            usuario   = tbUsuario.Text,
            senha     = tbSenha.Password,
            senhaHash = funcionario?.senhaHash
        };
        public IActionResult Index()
        {
            var tipoFreteSelecionadoPeloUsuario = _cookie.Consultar("Carrinho.TipoFrete", false);

            if (tipoFreteSelecionadoPeloUsuario != null)
            {
                var enderecoEntrega = ObterEndereco();
                var carrinhoHash    = GerarHash(this._carrinhoCompra.Consultar());

                int cep = int.Parse(Mascara.Remover(enderecoEntrega.CEP));
                List <ProdutoItem> produtoItemCompleto = CarregarProdutoDB();
                var frete        = ObterFrete(cep.ToString());
                var total        = ObterValorTotalCompra(frete, produtoItemCompleto);
                var parcelamento = this._gerenciarPagarMe.CalcularPagamentoParcelado(total);


                ViewBag.Frete        = frete;
                ViewBag.Parcelamento = parcelamento.Select(x => new SelectListItem(
                                                               String.Format("{0} x {1} {2} - TOTAL: {3}", x.Numero, x.ValorPorParcela.ToString("C"), (x.Juros)? "c/ juros": "s/ juros", x.Valor.ToString("C")),
                                                               x.Numero.ToString()
                                                               )
                                                           ).ToList();
                ViewBag.Produtos = produtoItemCompleto;



                return(View(nameof(Index)));
            }
            TempData["MSG_E"] = Mensagem.MSG_E009;
            return(RedirectToAction("EnderecoEntrega", "CarrinhoCompra"));
        }
 private EnderecoModel ToModelEndereco() =>
 new EnderecoModel
 {
     id          = consulta?.cliente?.endereco?.id ?? 0,
     cep         = Mascara.Remover(tbCep.Text),
     cidade      = tbCidade.Text,
     uf          = cbUf.Text,
     bairro      = tbBairro.Text,
     logradouro  = tbLogradouro.Text,
     numero      = tbNumero.Text,
     complemento = tbComplemento.Text
 };
Ejemplo n.º 4
0
        //[email protected]
        //4khJa8rpP^!U

        public object GerarBoleto(decimal valor)
        {
            try
            {
                Cliente cliente = this._loginCliente.GetCliente();
                PagarMeService.DefaultApiKey        = this._configuration.GetValue <string>("Pagamento:PagarMe:ApiKey");
                PagarMeService.DefaultEncryptionKey = this._configuration.GetValue <string>("Pagamento:PagarMe:EncryptionKey");

                Transaction transaction = new Transaction();

                //Calcular o valor total
                transaction.Amount        = Convert.ToInt32(valor);
                transaction.PaymentMethod = PaymentMethod.Boleto;

                transaction.Customer = new Customer
                {
                    ExternalId = cliente.Id.ToString(),
                    Name       = cliente.Nome,
                    Type       = CustomerType.Individual,
                    Country    = "br",
                    Email      = cliente.Email,
                    Documents  = new[]
                    {
                        new Document {
                            Type   = DocumentType.Cpf,
                            Number = Mascara.Remover(cliente.CPF)
                        },
                        new Document {
                            Type   = DocumentType.Cnpj,
                            Number = "89388916000174"
                        }
                    },
                    PhoneNumbers = new string[]
                    {
                        "+55" + Mascara.Remover(cliente.Telefone),
                    },
                    Birthday = cliente.DataNasc.ToString("yyyy-MM-dd")
                };

                transaction.Save();

                return(new
                {
                    BoletoURL = transaction.BoletoUrl,
                    BarCode = transaction.BoletoBarcode,
                    Expiracao = transaction.BoletoExpirationDate,
                });
            }
            catch (Exception e)
            {
                return(new { Erro = e.Message });
            }
        }
        private void CarregarPorCPF()
        {
            var cpf     = Mascara.Remover(tbCpf.Text);
            var cliente = ClienteModel.CarregarTodos().FirstOrDefault(x => x.cpf == cpf);

            if (cliente != null)
            {
                CarregarCliente(cliente);
                consulta = new ConsultaModel {
                    cliente = cliente
                };
                carregouCliente = true;
            }
        }
        private ValorPrazoFrete ObterFrete()
        {
            var enderecoEntrega = ObterEndereco();
            int cep             = int.Parse(Mascara.Remover(enderecoEntrega.CEP));
            var tipoFreteSelecionadoPeloUsuario = _cookie.Consultar("Carrinho.TipoFrete", false);
            var carrinhoHash = GerarHash(_cookieCarrinhoCompra.Consultar());

            Frete frete = _cookieFrete.Consultar().Where(a => a.CEP == cep && a.CodCarrinho == carrinhoHash).FirstOrDefault();

            if (frete != null)
            {
                return(frete.ListaValores.Where(a => a.TipoFrete == tipoFreteSelecionadoPeloUsuario).FirstOrDefault());
            }
            return(null);
        }
        private ClienteModel ToModelCliente() =>
        new ClienteModel
        {
            id               = consulta?.cliente?.id ?? 0,
            nome             = tbNome.Text,
            cpf              = Mascara.Remover(tbCpf.Text),
            genero           = cbGenero.SelectedIndex == 0 ? Genero.Masculino : Genero.Feminino,
            dataDeNascimento = DataUtil.Converter(tbDataNascimento.Text),

            dddCel   = tbDddCel.Text.Trim(),
            celular  = tbCelular.Text,
            dddTel   = tbDddTel.Text.Trim(),
            telefone = tbTelefone.Text,
            email    = tbEmail.Text,

            endereco = ToModelEndereco()
        };
        private ValorPrazoFrete ObterFrete(string cepDestino)
        {
            var tipoFreteSelecionadoPeloUsuario = this._cookie.Consultar("Carrinho.TipoFrete", false);
            var carrinhoHash = GerarHash(this._carrinhoCompra.Consultar());

            int cep = int.Parse(Mascara.Remover(cepDestino));

            var frete = this._cookieFrete.Consultar().Where(a => a.CEP == cep && a.CodCarrinho == carrinhoHash).FirstOrDefault();

            if (frete != null)
            {
                return(frete.ListaValores.Where(x => x.TipoFrete == tipoFreteSelecionadoPeloUsuario).FirstOrDefault());
            }
            else
            {
                return(null);
            }
        }
        private ClinicaModel ToModel() =>
        new ClinicaModel
        {
            id           = clinica?.id ?? 0,
            razaoSocial  = tbRazaoSocial.Text,
            nomeFantasia = tbNomeFantasia.Text,
            ie           = Mascara.Remover(tbIE.Text),
            cnpj         = Mascara.Remover(tbCNPJ.Text),
            logo         = logo,

            dddCel   = tbDddCel.Text.Trim(),
            celular  = tbCelular.Text,
            dddTel   = tbDddTel.Text.Trim(),
            telefone = tbTelefone.Text,
            email    = tbEmail.Text,
            site     = tbSite.Text,

            endereco = ToModelEndereco()
        };
        public Transaction GerarBoleto(Aluguel aluguel)
        {
            Cliente cliente = _clienteRepository.ObterCliente(Convert.ToInt32(aluguel.AluguelClienteId));

            PagarMeService.DefaultApiKey        = "ak_test_7VAjSBubdQj1qT3Kgc7AWluUKfiv3M"; //_configuration.GetValue<string>("Pagamento:PagarMe:ApiKey");
            PagarMeService.DefaultEncryptionKey = "ek_test_KEA6ruzcJ7tTF8dEEJ6ik6rWfXfiGW"; //_configuration.GetValue<string>("Pagamento:PagarMe:EncryptionKey");
            int DaysExpire = 2;

            Transaction transaction = new Transaction();

            transaction.Amount               = Mascara.ConverterValorPagarMe(aluguel.ValorPrevisto);
            transaction.PaymentMethod        = PaymentMethod.Boleto;
            transaction.BoletoExpirationDate = DateTime.Now.AddDays(DaysExpire);

            transaction.Customer = new Customer
            {
                ExternalId = cliente.Id.ToString(),
                Name       = cliente.Nome,
                Type       = CustomerType.Individual,
                Country    = "br",
                Email      = cliente.Email,
                Documents  = new[] {
                    new Document {
                        Type   = DocumentType.Cnpj,
                        Number = Mascara.Remover(cliente.CPFCNPJ)
                    }
                },
                PhoneNumbers = new string[]
                {
                    "+55" + Mascara.Remover(cliente.Telefone)
                },
                //Birthday = Mascara.Remover(cliente.Nascimento)
            };

            Item[] itens = new Item[1];

            for (var i = 0; i < itens.Length; i++)
            {
                var item = aluguel;

                var itemA = new Item()
                {
                    Id        = item.Id.ToString(),
                    Title     = "Aluguel",
                    Quantity  = 1,
                    Tangible  = false,
                    UnitPrice = Mascara.ConverterValorPagarMe(item.ValorPrevisto)
                };


                itens[i] = itemA;
            }

            transaction.Item = itens;

            transaction.Save();

            // transaction.Customer.Gender = (cliente.Sexo == "M") ? Gender.Male : Gender.Female;

            return(transaction);
        }
 private FiltroPessoa GetFiltro() =>
 (FiltroPessoa)Enum.Parse(typeof(FiltroPessoa), Mascara.Remover((cbFiltro.SelectedItem as ComboBoxItem)?.Content.ToString().ToLower()));
        public Transaction GerarPagCartaoCredito(CartaoCredito cartao, Parcelamento parcelamento, EnderecoEntrega enderecoEntrega, ValorPrazoFrete valorFrete, List <ProdutoItem> produtos)
        {
            Cliente cliente = _loginCliente.GetCliente();

            PagarMeService.DefaultApiKey        = _configuration.GetValue <String>("Pagamento:PagarMe:ApiKey");
            PagarMeService.DefaultEncryptionKey = _configuration.GetValue <String>("Pagamento:PagarMe:EncryptionKey");

            Card card = new Card();

            card.Number         = cartao.NumeroCartao;
            card.HolderName     = cartao.NomeNoCartao;
            card.ExpirationDate = cartao.VencimentoMM + cartao.VencimentoYY;
            card.Cvv            = cartao.CodigoSeguranca;

            card.Save();

            Transaction transaction = new Transaction();

            transaction.PaymentMethod = PaymentMethod.CreditCard;

            /*
             * Não sera feito transaction.postbackurl
             * - Parâmetro importante para que seu site seja informado sobre todas as mudanças de status ocorridas no Pagar.Me.
             * URL 1: https://pagarme.zendesk.com/hc/pt-br/articles/205973476-Quando-o-POSTback-%C3%A9-enviado-
             * URL 2: https://docs.pagar.me/v1/reference#criar-transacao
             */

            transaction.Card = new Card
            {
                Id = card.Id
            };

            transaction.Customer = new Customer
            {
                ExternalId = cliente.Id.ToString(),
                Name       = cliente.Nome,
                Type       = CustomerType.Individual,
                Country    = "br",
                Email      = cliente.Email,
                Documents  = new[] {
                    new Document {
                        Type   = DocumentType.Cpf,
                        Number = Mascara.Remover(cliente.CPF)
                    }
                },
                PhoneNumbers = new string[]
                {
                    "+55" + Mascara.Remover(cliente.Telefone)
                },
                Birthday = cliente.Nascimento.ToString("yyyy-MM-dd")
            };

            transaction.Billing = new Billing
            {
                Name    = cliente.Nome,
                Address = new Address()
                {
                    Country      = "br",
                    State        = cliente.Estado,
                    City         = cliente.Cidade,
                    Neighborhood = cliente.Bairro,
                    Street       = cliente.Endereco + " " + cliente.Complemento,
                    StreetNumber = cliente.Numero,
                    Zipcode      = Mascara.Remover(cliente.CEP)
                }
            };

            var Today = DateTime.Now;
            var fee   = Convert.ToDecimal(valorFrete.Valor);

            transaction.Shipping = new Shipping
            {
                Name         = enderecoEntrega.Nome,
                Fee          = Mascara.ConverterValorPagarMe(fee),
                DeliveryDate = Today.AddDays(_configuration.GetValue <int>("Frete:DiasParaPostagem")).AddDays(valorFrete.Prazo).ToString("yyyy-MM-dd"),
                Expedited    = false,
                Address      = new Address()
                {
                    Country      = "br",
                    State        = enderecoEntrega.Estado,
                    City         = enderecoEntrega.Cidade,
                    Neighborhood = enderecoEntrega.Bairro,
                    Street       = enderecoEntrega.Endereco + " " + enderecoEntrega.Complemento,
                    StreetNumber = enderecoEntrega.Numero,
                    Zipcode      = Mascara.Remover(enderecoEntrega.CEP)
                }
            };

            Item[] itens = new Item[produtos.Count];

            for (var i = 0; i < produtos.Count; i++)
            {
                var item = produtos[i];

                var itemA = new Item()
                {
                    Id        = item.Id.ToString(),
                    Title     = item.Nome,
                    Quantity  = item.UnidadesPedidas,
                    Tangible  = true,
                    UnitPrice = Mascara.ConverterValorPagarMe(item.Valor)
                };


                itens[i] = itemA;
            }

            transaction.Item         = itens;
            transaction.Amount       = Mascara.ConverterValorPagarMe(parcelamento.Valor);
            transaction.Installments = parcelamento.Numero;

            transaction.Save();

            transaction.Customer.Gender = (cliente.Sexo == "M") ? Gender.Male : Gender.Female;
            return(transaction);
        }
Ejemplo n.º 13
0
        public Transaction GerarPagCartaoCredito(CartaoCredito cartao, Parcelamento parcelamento, EnderecoEntrega enderecoEntrega, ValorPrazoFrete valorFrete, List <ItemVendaViewModel> produtos, Usuario usuario)
        {
            Usuario cliente = usuario;

            PagarMeService.DefaultApiKey        = DefaultApiKey;
            PagarMeService.DefaultEncryptionKey = DefaultEncryptionKey;

            Card card = new Card();

            card.Number         = cartao.NumeroCartao;
            card.HolderName     = cartao.NomeNoCartao;
            card.ExpirationDate = cartao.VecimentoMM + cartao.VecimentoYY;
            card.Cvv            = cartao.CodigoSeguranca;

            card.Save();

            Transaction transaction = new Transaction();

            transaction.PaymentMethod = PaymentMethod.CreditCard;
            transaction.Card          = new Card
            {
                Id = card.Id
            };

            transaction.Customer = new Customer
            {
                ExternalId = cliente.Id.ToString(),
                Name       = cliente.Nome,
                Type       = CustomerType.Individual,
                Country    = "br",
                Email      = cliente.Email,
                Documents  = new[] {
                    new Document {
                        Type   = DocumentType.Cpf,
                        Number = Mascara.Remover(cliente.CPFCNPJ)
                    }
                },
                PhoneNumbers = new string[]
                {
                    "+55" + Mascara.Remover(cliente.Telefone)
                },
                Birthday = cliente.Nascimento.ToString("yyyy-MM-dd")
            };

            transaction.Billing = new Billing
            {
                Name    = cliente.Nome,
                Address = new Address()
                {
                    Country      = "br",
                    State        = enderecoEntrega.Estado,
                    City         = enderecoEntrega.Cidade,
                    Neighborhood = enderecoEntrega.Bairro,
                    Street       = enderecoEntrega.Endereco + " " + enderecoEntrega.Complemento,
                    StreetNumber = enderecoEntrega.Numero,
                    Zipcode      = Mascara.Remover(enderecoEntrega.CEP)
                }
            };

            var Today = DateTime.Now;
            var fee   = Convert.ToDecimal(valorFrete.Valor);

            transaction.Shipping = new Shipping
            {
                Name         = enderecoEntrega.Nome,
                Fee          = Mascara.ConverterValorPagarMe(fee),
                DeliveryDate = Today.AddDays(DiasNaEmpresa).AddDays(valorFrete.Prazo).ToString("yyyy-MM-dd"),
                Expedited    = false,
                Address      = new Address()
                {
                    Country      = "br",
                    State        = enderecoEntrega.Estado,
                    City         = enderecoEntrega.Cidade,
                    Neighborhood = enderecoEntrega.Bairro,
                    Street       = enderecoEntrega.Endereco + " " + enderecoEntrega.Complemento,
                    StreetNumber = enderecoEntrega.Numero,
                    Zipcode      = Mascara.Remover(enderecoEntrega.CEP)
                }
            };

            Item[] itens = new Item[produtos.Count];

            for (var i = 0; i < produtos.Count; i++)
            {
                var item = produtos[i];
                itens[i] = new Item()
                {
                    Id        = item.Produto.ID.ToString(),
                    Title     = item.Produto.Nome,
                    Quantity  = item.Quantidade,
                    Tangible  = true,
                    UnitPrice = Mascara.ConverterValorPagarMe(item.Produto.Valor),
                };
            }

            transaction.Item         = itens;
            transaction.Amount       = Mascara.ConverterValorPagarMe(parcelamento.Valor);
            transaction.Installments = parcelamento.Numero;

            transaction.Save();

            transaction.Customer.Gender = (cliente.Sexo == Enums.Sexo.Masculino) ? Gender.Male : Gender.Female;
            return(transaction);
        }
Ejemplo n.º 14
0
        public object GerarPagCartaoCredito(CartaoCredito cartao, Parcelamento parcelamento, EnderecoEntrega enderecoEntrega, ValorPrazoFrete frete, List <ProdutoItem> produtos)
        {
            Cliente cliente = this._loginCliente.GetCliente();

            PagarMeService.DefaultApiKey        = this._configuration.GetValue <string>("Pagamento:PagarMe:ApiKey");
            PagarMeService.DefaultEncryptionKey = this._configuration.GetValue <string>("Pagamento:PagarMe:EncryptionKey");

            Card card = new Card();

            card.Number         = cartao.NumeroCartao;
            card.HolderName     = cartao.NomeNoCartao;
            card.ExpirationDate = cartao.VencimentoMM + cartao.VencimentoYY;
            card.Cvv            = cartao.CodigoSeguranca;
            card.Save();

            Transaction transaction = new Transaction();

            transaction.Amount = 2100;
            transaction.Card   = new Card
            {
                Id = card.Id
            };

            transaction.Customer = new Customer
            {
                ExternalId = cliente.Id.ToString(),
                Name       = cliente.Nome,
                Type       = CustomerType.Individual,
                Country    = "br",
                Email      = cliente.Email,
                Documents  = new[]
                {
                    new Document {
                        Type   = DocumentType.Cpf,
                        Number = Mascara.Remover(cliente.CPF)
                    },
                    new Document {
                        Type   = DocumentType.Cnpj,
                        Number = "89388916000174"
                    }
                },
                PhoneNumbers = new string[]
                {
                    "+55" + Mascara.Remover(cliente.Telefone),
                },
                Birthday = cliente.DataNasc.ToString("yyyy-MM-dd")
            };

            transaction.Billing = new Billing
            {
                Name    = cliente.Nome,
                Address = new Address()
                {
                    Country      = "br",
                    State        = cliente.Estado,
                    City         = cliente.Cidade,
                    Neighborhood = cliente.Bairro,
                    Street       = cliente.Endereco + " " + cliente.Complemento,
                    StreetNumber = cliente.Numero,
                    Zipcode      = Mascara.Remover(cliente.CEP)
                }
            };

            var Today = DateTime.Now;

            // Converter corretamente o valor para a API do pagar.me
            transaction.Shipping = new Shipping
            {
                Name         = enderecoEntrega.Nome,
                Fee          = Mascara.ConverterValorPagarMe(Convert.ToDecimal(frete.Valor)),
                DeliveryDate = Today.AddDays(this._configuration.GetValue <int>("Frete:DiasPreparo")).AddDays(frete.Prazo).ToString("yyyy-MM-dd"),
                Expedited    = false,
                Address      = new Address()
                {
                    Country      = "br",
                    State        = enderecoEntrega.Estado,
                    City         = enderecoEntrega.Cidade,
                    Neighborhood = enderecoEntrega.Bairro,
                    Street       = enderecoEntrega.Endereco + " " + enderecoEntrega.Complemento,
                    StreetNumber = enderecoEntrega.Numero,
                    Zipcode      = Mascara.Remover(enderecoEntrega.CEP)
                }
            };

            Item[] itens = new Item[produtos.Count];

            // Converter corretamente o valor para a API do pagar.me
            for (var i = 0; i < produtos.Count; i++)
            {
                var item  = produtos[i];
                var itemA = new Item()
                {
                    Id        = item.Id.ToString(),
                    Title     = item.Nome,
                    Quantity  = item.QuantidadeProdutoCarrinho,
                    Tangible  = true,
                    UnitPrice = Mascara.ConverterValorPagarMe(item.Valor)
                };

                itens[i] = itemA;
            }

            transaction.Item         = itens;
            transaction.Amount       = Mascara.ConverterValorPagarMe(parcelamento.Valor);
            transaction.Installments = parcelamento.Numero;
            transaction.Save();
            return(new { TransactionId = transaction.Id });
        }
        public Transaction GerarPagCartaoCredito(CartaoCredito cartao, Aluguel aluguel, Parcelamento parcela)
        {
            Cliente   cliente   = _clienteRepository.ObterCliente(Convert.ToInt32(aluguel.AluguelMotoristaId));
            Motorista motorista = _motoristaRepository.ObterMotorista(Convert.ToInt32(aluguel.AluguelMotoristaId));


            PagarMeService.DefaultApiKey        = "ak_test_7VAjSBubdQj1qT3Kgc7AWluUKfiv3M"; //_configuration.GetValue<string>("Pagamento:PagarMe:ApiKey");
            PagarMeService.DefaultEncryptionKey = "ek_test_KEA6ruzcJ7tTF8dEEJ6ik6rWfXfiGW"; //_configuration.GetValue<string>("Pagamento:PagarMe:EncryptionKey");


            Card card = new Card();

            card.Number         = cartao.NumeroCartao;
            card.HolderName     = cartao.NomeNoCartao;
            card.ExpirationDate = cartao.VecimentoMM + cartao.VecimentoYY;
            card.Cvv            = cartao.CodigoSeguranca;

            card.Save();

            Transaction transaction = new Transaction();

            transaction.Amount        = Mascara.ConverterValorPagarMe(aluguel.ValorPrevisto);
            transaction.PaymentMethod = PaymentMethod.CreditCard;

            /*
             * Transaction.postbackurl
             * - Parâmetro importante para que seu site seja informado sobre todas as mudanças de status ocorridas no Pagar.Me.
             * URL 1: https://pagarme.zendesk.com/hc/pt-br/articles/205973476-Quando-o-POSTback-%C3%A9-enviado-
             * URL 2: https://docs.pagar.me/v1/reference#criar-transacao
             */

            transaction.Card = new Card
            {
                Id = card.Id
            };

            transaction.Customer = new Customer
            {
                ExternalId = cliente.Id.ToString(),
                Name       = cliente.Nome,
                Type       = CustomerType.Individual,
                Country    = "br",
                Email      = cliente.Email,
                Documents  = new[] {
                    new Document {
                        Type   = DocumentType.Cpf,
                        Number = Mascara.Remover(cliente.CPFCNPJ)
                    }
                },
                PhoneNumbers = new string[]
                {
                    "+55" + Mascara.Remover(cliente.Telefone)
                },
                Birthday = Mascara.Remover(cliente.Nascimento)
            };

            transaction.Billing = new Billing
            {
                Name    = cliente.Nome,
                Address = new Address()
                {
                    Country      = "br",
                    State        = cliente.Estado,
                    City         = cliente.Cidade,
                    Neighborhood = cliente.Bairro,
                    Street       = cliente.Endereco + " " + cliente.Complemento,
                    StreetNumber = cliente.Numero,
                    Zipcode      = Mascara.Remover(cliente.CEP)
                }
            };


            Item[] itens = new Item[1];

            for (var i = 0; i < itens.Length; i++)
            {
                var item = aluguel;

                var itemA = new Item()
                {
                    Id        = item.Id.ToString(),
                    Title     = "Aluguel",
                    Quantity  = 1,
                    Tangible  = false,
                    UnitPrice = Mascara.ConverterValorPagarMe(item.ValorPrevisto)
                };


                itens[i] = itemA;
            }

            transaction.Item = itens;

            transaction.Installments = parcela.Numero;

            transaction.Save();

            transaction.Customer.Gender = (motorista.Sexo == "M") ? Gender.Male : Gender.Female;
            return(transaction);
        }
Ejemplo n.º 16
0
 private FiltroPessoa GetFiltro() =>
 (FiltroPessoa)Enum.Parse(typeof(FiltroPessoa), Mascara.Remover(cbFiltro.Text.ToLower()));
        public Transaction GerarBoleto(decimal valor, List <ProdutoItem> produtos, EnderecoEntrega enderecoEntrega, ValorPrazoFrete valorFrete)
        {
            Cliente cliente = _loginCliente.GetCliente();

            PagarMeService.DefaultApiKey        = _configuration.GetValue <String>("Pagamento:PagarMe:ApiKey");
            PagarMeService.DefaultEncryptionKey = _configuration.GetValue <String>("Pagamento:PagarMe:EncryptionKey");
            int DaysExpire = _configuration.GetValue <int>("Pagamento:PagarMe:BoletoDiaExpiracao");

            Transaction transaction = new Transaction();

            transaction.Amount               = Mascara.ConverterValorPagarMe(valor);
            transaction.PaymentMethod        = PaymentMethod.Boleto;
            transaction.BoletoExpirationDate = DateTime.Now.AddDays(DaysExpire);
            transaction.Customer             = new Customer
            {
                ExternalId = cliente.Id.ToString(),
                Name       = cliente.Nome,
                Type       = CustomerType.Individual,
                Country    = "br",
                Email      = cliente.Email,
                Documents  = new[] {
                    new Document {
                        Type   = DocumentType.Cpf,
                        Number = Mascara.Remover(cliente.CPF)
                    }
                },
                PhoneNumbers = new string[]
                {
                    "+55" + Mascara.Remover(cliente.Telefone)
                },
                Birthday = cliente.Nascimento.ToString("yyyy-MM-dd")
            };

            var Today = DateTime.Now;
            var fee   = Convert.ToDecimal(valorFrete.Valor);

            transaction.Shipping = new Shipping
            {
                Name         = enderecoEntrega.Nome,
                Fee          = Mascara.ConverterValorPagarMe(fee),
                DeliveryDate = Today.AddDays(_configuration.GetValue <int>("Frete:DiasNaEmpresa")).AddDays(valorFrete.Prazo).ToString("yyyy-MM-dd"),
                Expedited    = false,
                Address      = new Address()
                {
                    Country      = "br",
                    State        = enderecoEntrega.Estado,
                    City         = enderecoEntrega.Cidade,
                    Neighborhood = enderecoEntrega.Bairro,
                    Street       = enderecoEntrega.Endereco + " " + enderecoEntrega.Complemento,
                    StreetNumber = enderecoEntrega.Numero,
                    Zipcode      = Mascara.Remover(enderecoEntrega.CEP)
                }
            };

            Item[] itens = new Item[produtos.Count];

            for (var i = 0; i < produtos.Count; i++)
            {
                var item = produtos[i];

                var itemA = new Item()
                {
                    Id        = item.Id.ToString(),
                    Title     = item.Nome,
                    Quantity  = item.UnidadesPedidas,
                    Tangible  = true,
                    UnitPrice = Mascara.ConverterValorPagarMe(item.Valor)
                };


                itens[i] = itemA;
            }

            transaction.Item = itens;

            transaction.Save();

            transaction.Customer.Gender = (cliente.Sexo == "M") ? Gender.Male : Gender.Female;
            return(transaction);
        }