Ejemplo n.º 1
0
        public IActionResult Atualizar(int id)
        {
            var motorista = _motoristaRepository.ObterMotorista(id);

            CarregarDados();

            return(View(motorista));
        }
        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);
        }