public List <Parcelamento> CalcularPagamentoParcelado(decimal valor)
        {
            List <Parcelamento> lista = new List <Parcelamento>();


            int     maxParcelamento     = 12; // _configuration.GetValue<int>("Pagamento:PagarMe:MaxParcelas");
            int     parcelaPagaVendedor = 3;  //_configuration.GetValue<int>("Pagamento:PagarMe:ParcelaPagaVendedor");
            decimal juros = 5;                //_configuration.GetValue<decimal>("Pagamento:PagarMe:Juros");

            for (int i = 1; i <= maxParcelamento; i++)
            {
                Parcelamento parcelamento = new Parcelamento();
                parcelamento.Numero = i;

                if (i > parcelaPagaVendedor)
                {
                    //Juros - i = (4-3 - parcelaPagaVendedor) + 5%
                    int     quantidadeParcelasComJuros = i - parcelaPagaVendedor;
                    decimal valorDoJuros = valor * juros / 100;

                    parcelamento.Valor           = quantidadeParcelasComJuros * valorDoJuros + valor;
                    parcelamento.ValorPorParcela = parcelamento.Valor / parcelamento.Numero;
                    parcelamento.Juros           = true;
                }
                else
                {
                    parcelamento.Valor           = valor;
                    parcelamento.ValorPorParcela = parcelamento.Valor / parcelamento.Numero;
                    parcelamento.Juros           = false;
                }
                lista.Add(parcelamento);
            }

            return(lista);
        }
        public IActionResult Index([FromForm] IndexViewModel indexViewModel)
        {
            if (ModelState.IsValid)
            {
                EnderecoEntrega    enderecoEntrega = ObterEndereco();
                ValorPrazoFrete    frete           = ObterFrete();
                List <ProdutoItem> produtos        = CarregarProdutoDB();
                Parcelamento       parcela         = BuscarParcelamento(produtos, indexViewModel.Parcelamento.Numero);

                try
                {
                    Transaction transaction = _gerenciarPagarMe.GerarPagCartaoCredito(indexViewModel.CartaoCredito, parcela, enderecoEntrega, frete, produtos);
                    Pedido      pedido      = ProcessarPedido(produtos, transaction);

                    return(new RedirectToActionResult("Index", "Pedido", new { id = pedido.Id }));
                }
                catch (PagarMeException e)
                {
                    _logger.LogError(e, "PagamentoController > Index ");
                    TempData["MSG_E"] = MontarMensagensDeErro(e);

                    return(Index());
                }
            }
            else
            {
                return(Index());
            }
        }
        public IActionResult Pagamento([FromForm] PagamentoViewModel pagamento)
        {
            if (ModelState.IsValid)
            {
                Parcelamento parcela = BuscarParcelamento(pagamento.Aluguel, pagamento.Parcelamento.Numero);
                try
                {
                    Transaction transacao = _pagar.GerarPagCartaoCredito(pagamento.CartaoCredito, pagamento.Aluguel, parcela);
                    ProcessarPedido(transacao, pagamento.Aluguel);
                    TempData["MSG_S"] = Mensagem.MSG_S001;
                    return(RedirectToAction(nameof(Index)));
                }
                catch (PagarMeException e)
                {
                    _logger.LogError(e, "PagamentoController > Index");
                    TempData["MSG_S"] = MontarMensagensDeErro(e);

                    return(RedirectToAction(nameof(Index)));
                }
            }
            else
            {
                return(View());
            }
        }
Esempio n. 4
0
        public List <Parcelamento> CalcularPagamentoParcelado(decimal valor)
        {
            List <Parcelamento> lista = new List <Parcelamento>();

            int     maxParcelamento     = MaxParcelas;
            int     parcelaPagaVendedor = ParcelaPagaVendedor;
            decimal juros = Juros;

            for (int i = 1; i <= maxParcelamento; i++)
            {
                Parcelamento parcelamento = new Parcelamento();
                parcelamento.Numero = i;

                if (i > parcelaPagaVendedor)
                {
                    //Juros - i = (4-3 - parcelaPagaVendedor) + 5%
                    int     quantidadeParcelasComJuros = i - parcelaPagaVendedor;
                    decimal valorDoJuros = valor * juros / 100;

                    parcelamento.Valor           = quantidadeParcelasComJuros * valorDoJuros + valor;
                    parcelamento.ValorPorParcela = parcelamento.Valor / parcelamento.Numero;
                    parcelamento.Juros           = true;
                }
                else
                {
                    parcelamento.Valor           = valor;
                    parcelamento.ValorPorParcela = parcelamento.Valor / parcelamento.Numero;
                    parcelamento.Juros           = false;
                }
                lista.Add(parcelamento);
            }

            return(lista);
        }
Esempio n. 5
0
        public List <Parcelamento> CalcularPagamentoParcelado(decimal valor)
        {
            List <Parcelamento> lista = new List <Parcelamento>();

            int     numParcelas      = this._configuration.GetValue <int>("Pagamento:PagarMe:MaxParcelas");
            int     parcelasVendedor = this._configuration.GetValue <int>("Pagamento:PagarMe:ParcelasVendedor");
            decimal Juros            = this._configuration.GetValue <decimal>("Pagamento:PagarMe:Juros");

            for (int i = 1; i <= numParcelas; i++)
            {
                Parcelamento parcelamento = new Parcelamento();
                parcelamento.Numero = i;

                if (i > parcelasVendedor)
                {
                    //Juros i = 4 - 5%
                    int     qtdParcelasComJuros = i - parcelasVendedor;
                    decimal valorDoJuros        = valor * 5 / 100;

                    parcelamento.Valor           = qtdParcelasComJuros * valorDoJuros + valor;
                    parcelamento.ValorPorParcela = parcelamento.Valor / parcelamento.Numero;
                    parcelamento.Juros           = true;
                }
                else
                {
                    parcelamento.Valor           = valor;
                    parcelamento.ValorPorParcela = parcelamento.Valor / parcelamento.Numero;
                    parcelamento.Juros           = false;
                }

                lista.Add(parcelamento);
            }
            return(lista);
        }
Esempio n. 6
0
        public ActionResult EditParcelamento(ParcelamentoViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Parcelamento parcelamento = Mapper.Map <ParcelamentoViewModel, Parcelamento>(viewModel);
                parcelamento.FormaPag = FormaPag.Cartao;
                parcelamento.PessoaId = pessoaUsuarioAPL.SelecionarById(User.Identity.GetUserId()).Id;
                despesasAPL.Alterar(parcelamento);
            }

            return(Redirect(Request.UrlReferrer.ToString()));
        }
        public async Task <IActionResult> CriarVenda([FromBody] PagamentoViewModel pagamento, [FromHeader] string authorization)
        {
            var usuario = await _tokenService.ExtractUsuarioToken(authorization);

            if (usuario is null)
            {
                return(BadRequest(""));
            }

            try
            {
                _carrinhoCompras.ItensCarrinho = await _carrinhoCompras.TodosItemsCarrinho();


                if (_carrinhoCompras.ItensCarrinho.Count.Equals(0))
                {
                    ModelState.AddModelError("", "Carro Vazio");
                }

                if (ModelState.IsValid)
                {
                    Parcelamento parcela     = _servico.BuscarParcelamento(await _carrinhoCompras.TotalCompra(), pagamento.CartaoDeCredito.QuantidadeParcelas);
                    Transaction  transaction = _pagarMe.GerarPagCartaoCredito(pagamento.CartaoDeCredito, parcela, await _entregaRepository.EnderecoEntregaUsuario(usuario.Id), pagamento.FreteValor, _carrinhoCompras.ItensCarrinho, usuario);
                    var          pedido      = await _servico.ProcessarPedido(_carrinhoCompras.ItensCarrinho, transaction);

                    var venda = await _vendaRepository.CriarVenda((double)(await _carrinhoCompras.TotalCompra()), _carrinhoCompras.ItensCarrinho, pedido, usuario);

                    await _movimentacaoRepository.MovimentarEstoqueVenda(venda, StatusMovimentacao.SAIDA, TipoMovimentacao.VENDA);

                    _carrinhoCompras.LimparCarrinho();
                }
                return(Ok(true));
            }
            catch (PagarMeException ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.Error));
            }
        }
        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);
        }
        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);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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 });
        }