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 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);
        }
        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);
        }
        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);
        }
Exemple #5
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);
        }
Exemple #6
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 });
        }