public String TRecorrencia()
        {
            PagarMeService.DefaultApiKey = "ak_test_jbIXhrHXHOaUUNKtUVrkT9HGL60SSg";

            Subscription subscription = new Subscription
            {
                PaymentMethod      = PaymentMethod.CreditCard,
                CardNumber         = "4901720080344448",
                CardHolderName     = "Jose da Silva",
                CardExpirationDate = "1225",
                CardCvv            = "123"
            };

            subscription.Plan = PagarMeService.GetDefaultService().Plans.Find(435922);
            Customer customer = new Customer
            {
                Email          = "*****@*****.**",
                Name           = "Rick",
                DocumentNumber = "30621143049"
            };

            subscription.Customer = customer;

            subscription.Save();
            return(Convert.ToString(subscription.Id));
        }
        public void Create()
        {
            try
            {
                Recipient Recipient = new Recipient()
                {
                    BankAccount      = PagarMeService.GetDefaultService().BankAccounts.Find(14815682),
                    TransferDay      = 5,
                    TransferEnabled  = true,
                    TransferInterval = TransferInterval.Weekly
                };
                Recipient.Save();

                model = new Transaction()
                {
                    Amount             = 3100,
                    PaymentMethod      = PaymentMethod.CreditCard,
                    CardNumber         = "4242424242424242",
                    CardHolderName     = "PagarMe",
                    CardExpirationDate = "0921",
                    CardCvv            = "123",
                    Customer           = new Customer()
                    {
                        Name           = "Teste PagarMe",
                        DocumentNumber = "43591017833",
                        DocumentType   = DocumentType.Cpf,
                        Email          = "*****@*****.**",
                        Address        = new Address()
                        {
                            Zipcode      = "13223030",
                            Neighborhood = "Jardim Paulistano",
                            Street       = "Av. Brigadeiro Faria Lima",
                            StreetNumber = "1811"
                        },
                        Phone = new Phone()
                        {
                            Ddd    = "11",
                            Number = "12345678"
                        }
                    },
                    PostbackUrl = "",
                    SplitRules  = new []
                    {
                        new SplitRule()
                        {
                            Recipient           = Recipient,
                            ChargeProcessingFee = true,
                            Liable     = true,
                            Percentage = 100
                        }
                    }
                };

                model.Save();
            }
            catch (PagarMeException ex)
            {
                throw ex;
            }
        }
        public String[] TAntecipaçao()
        {
            PagarMeService.DefaultApiKey = "ak_test_jbIXhrHXHOaUUNKtUVrkT9HGL60SSg";
            var recipient        = PagarMeService.GetDefaultService().Recipients.Find("re_ck0zjmw1s007ier6eysyd3agj");
            var bulkAnticipation = new BulkAnticipation()
            {
                Timeframe       = TimeFrame.Start,
                PaymentDate     = DateTime.Today.AddDays(3),
                RequestedAmount = 5300,
                Build           = true
            };

            try
            {
                recipient.CreateAnticipation(bulkAnticipation);
                string[] retorno = new string[3];
                retorno[0] = bulkAnticipation.Id;
                retorno[1] = bulkAnticipation.Amount.ToString();
                retorno[2] = recipient.Id;
                return(retorno);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                string[] retorno = new string[2];
                retorno[0] = Convert.ToString(ex);
                retorno[1] = "";
                retorno[2] = "";
                return(retorno);
            }
        }
Ejemplo n.º 4
0
        public void FindAllTransferTest()
        {
            BankAccount bank = PagarMeTestFixture.CreateTestBankAccount();

            bank.Save();
            Recipient recipient = PagarMeTestFixture.CreateRecipient(bank);

            recipient.Save();

            Transaction transaction = PagarMeTestFixture.CreateBoletoSplitRuleTransaction(recipient);

            transaction.Save();
            transaction.Status = TransactionStatus.Paid;
            transaction.Save();

            Transfer transfer = PagarMeTestFixture.CreateTestTransfer(bank.Id, recipient.Id);

            transfer.Save();

            Transfer transferReturned = PagarMeService.GetDefaultService().Transfers.FindAll(new Transfer()).ToArray().First();

            Assert.IsTrue(transferReturned.Id.Equals(transfer.Id));
            Assert.IsTrue(transferReturned.Amount.Equals(transfer.Amount));
            Assert.IsTrue(transferReturned.DateCreated.Equals(transfer.DateCreated));
            Assert.IsTrue(transferReturned.Fee.Equals(transfer.Fee));
            Assert.IsTrue(transferReturned.Status.Equals(transfer.Status));
            Assert.IsTrue(transferReturned.Type.Equals(transfer.Type));
        }
Ejemplo n.º 5
0
        public IActionResult EstornarProduto(uint idTransacao, uint idProduto)
        {
            try
            {
                PagarMeService.DefaultApiKey = _configuration.GetValue <string>("Pagamento:DefaultApiKey");

                var produtoPedido = _reposPedido.BuscarProdutoPedido(idProduto);
                var valorEstorno  = Convert.ToInt32((produtoPedido.Valor * produtoPedido.Quantidade).ToString().Replace(".", ""));

                var transacao = PagarMeService.GetDefaultService().Transactions.Find(idTransacao.ToString());
                transacao.Refund(valorEstorno);

                produtoPedido.Situacao        = (byte)Global.Produto.Cancelado;
                produtoPedido.DataAtualizacao = DateTime.Now;

                if (_reposPedido.AtualizarProdutoPedido(produtoPedido) > 0)
                {
                    var produto = _reposProduto.Buscar(produtoPedido.IdProduto);
                    produto.Estoque += produtoPedido.Quantidade;

                    if (_reposProduto.Atualizar(produto) > 0)
                    {
                        GerarLog((byte)Global.Entidade.Pedido, (byte)Global.Acao.Editar, Convert.ToUInt32(transacao.Id));
                        return(Json(Global.Mensagem.SucessoOperacao));
                    }
                }

                return(BadRequest(Global.Mensagem.FalhaAtualizacao));
            }
            catch (Exception erro)
            {
                GerarLogErro(erro, (byte)Global.Entidade.Pedido, (byte)Global.Acao.Editar);
                return(BadRequest(Global.Mensagem.FalhaBanco));
            }
        }
        public void EstornoCartao(string transactionId)
        {
            PagarMeService.DefaultApiKey = _conf.GetValue <string>("PagarMe:APIKey");
            var transaction = PagarMeService.GetDefaultService().Transactions.Find(transactionId);

            transaction.Refund();
        }
        public String TEstornoComSplit(String Tid)
        {
            PagarMeService.DefaultApiKey = "ak_test_jbIXhrHXHOaUUNKtUVrkT9HGL60SSg";

            var transaction = PagarMeService.GetDefaultService().Transactions.Find(Tid);
            var splitRules  = new SplitRule[] {
                new SplitRule
                {
                    Id                  = transaction.SplitRules[0].Id,
                    Percentage          = transaction.SplitRules[0].Percentage,
                    RecipientId         = transaction.SplitRules[0].RecipientId,
                    ChargeProcessingFee = transaction.SplitRules[0].ChargeProcessingFee
                },
                new SplitRule
                {
                    Id                  = transaction.SplitRules[1].Id,
                    Percentage          = transaction.SplitRules[1].Percentage,
                    RecipientId         = transaction.SplitRules[1].RecipientId,
                    ChargeProcessingFee = transaction.SplitRules[1].ChargeProcessingFee
                }
            };

            try
            {
                transaction.RefundWithSplit(transaction.Amount, splitRules);
                return(" ");
            }
            catch (PagarMeException ex)
            {
                Console.WriteLine(ex.Error.Errors[0].Message);
                return(Convert.ToString(ex));
            }
        }
        public Transaction ObterTransacao(string transactionId)
        {
            PagarMeService.DefaultApiKey = _conf.GetValue <string>("PagarMe:APIKey");

            var transaction = PagarMeService.GetDefaultService().Transactions.Find(transactionId);

            return(transaction);
        }
Ejemplo n.º 9
0
        public Transaction EstornoCartaoCredito(string transactionId)
        {
            PagarMeService.DefaultApiKey = "ak_test_7VAjSBubdQj1qT3Kgc7AWluUKfiv3M";

            var transaction = PagarMeService.GetDefaultService().Transactions.Find(transactionId);

            transaction.Refund();

            return(transaction);
        }
Ejemplo n.º 10
0
        internal ModelCollection(PagarMeService service, string endpoint)
        {
            if (service == null)
            {
                service = PagarMeService.GetDefaultService();
            }

            _service  = service;
            _endpoint = endpoint;
        }
        public Transaction EstornoCartaoCredito(string TransactionId)
        {
            PagarMeService.DefaultApiKey = _configuration.GetValue <String>("Pagamento:PagarMe:ApiKey");

            var transaction = PagarMeService.GetDefaultService().Transactions.Find(TransactionId);

            transaction.Refund();

            return(transaction);
        }
Ejemplo n.º 12
0
        public String[] TPostBack()
        {
            PagarMeService.DefaultApiKey = "ak_test_jbIXhrHXHOaUUNKtUVrkT9HGL60SSg";
            var postback = PagarMeService.GetDefaultService().Transactions.Find("7341631").Postbacks.Find("po_ck368bv1v00b0vs733f9uuuc3");

            string[] retorno = new string[2];
            retorno[0] = postback.ModelId;
            retorno[1] = Convert.ToString(postback.Status);
            return(retorno);
        }
Ejemplo n.º 13
0
        public Transaction EstornoBoletoBancario(string transactionId, DadosCancelamentoBoleto boletoBancario)
        {
            PagarMeService.DefaultApiKey = _configuration.GetValue <String>("Pagamento:PagarMe:ApiKey");

            var transaction = PagarMeService.GetDefaultService().Transactions.Find(transactionId);
            var bankAccount = _mapper.Map <DadosCancelamentoBoleto, BankAccount>(boletoBancario);

            transaction.Refund(bankAccount);

            return(transaction);
        }
Ejemplo n.º 14
0
        public Transaction EstornoBoletoBancario(string transactionId, DadosCancelamentoBoleto boletoBancario)
        {
            PagarMeService.DefaultApiKey = "ak_test_7VAjSBubdQj1qT3Kgc7AWluUKfiv3M";

            var transaction = PagarMeService.GetDefaultService().Transactions.Find(transactionId);
            var bankAccount = _mapper.Map <DadosCancelamentoBoleto, BankAccount>(boletoBancario);

            transaction.Refund(bankAccount);

            return(transaction);
        }
Ejemplo n.º 15
0
        public AbstractModel(PagarMeService service)
        {
            if (service == null)
            {
                service = PagarMeService.GetDefaultService();
            }

            _service   = service;
            _keys      = new Dictionary <string, object>();
            _dirtyKeys = new Dictionary <string, object>();
        }
Ejemplo n.º 16
0
        public static void Main(string[] args)
        {
            PagarMeService.DefaultApiKey        = "ak_test_TSgC3nvXtdYnDoGKgNLIOfk3TFfkl9";
            PagarMeService.DefaultEncryptionKey = "ek_test_UT6AN4fDN3BCUgo6kxUiOq6S20dbKc";


            BankAccount b = new BankAccount();

            b.Agencia        = "0196";
            b.AgenciaDv      = "0";
            b.Conta          = "05392";
            b.ContaDv        = "0";
            b.BankCode       = "0341";
            b.DocumentNumber = "05737104141";
            b.LegalName      = "JONATHAN LIMA";
            b.Save();

            Recipient r1 = PagarMeService.GetDefaultService().Recipients.Find("re_ci76hxnym00b8dw16y3hdxb21");
            Recipient r2 = PagarMeService.GetDefaultService().Recipients.Find("re_ci7nheu0m0006n016o5sglg9t");
            Recipient r3 = new Recipient();

            r3.BankAccount      = b;
            r3.TransferEnabled  = true;
            r3.TransferInterval = TransferInterval.Weekly;
            r3.TransferDay      = 1;
            r3.Save();

            Transaction t = new Transaction();

            t.SplitRules = new[] {
                new SplitRule {
                    Recipient           = r1,
                    Percentage          = 10,
                    ChargeProcessingFee = true,
                    Liable = true
                },
                new SplitRule {
                    Recipient           = r2,
                    Percentage          = 40,
                    ChargeProcessingFee = false,
                    Liable = false
                },
                new SplitRule {
                    Recipient           = r3,
                    Percentage          = 50,
                    ChargeProcessingFee = false,
                    Liable = false
                }
            };

            t.PaymentMethod = PaymentMethod.Boleto;
            t.Amount        = 10000;
            t.Save();
        }
Ejemplo n.º 17
0
 public void Create()
 {
     try
     {
         model = new Transaction();
         IEnumerable <Transaction> trxs = PagarMeService.GetDefaultService().Transactions.FindAll(model);
         trxs  = trxs.Skip(0).Take(10);
         model = trxs.FirstOrDefault();
     }
     catch (PagarMeException ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 18
0
        public void FindPayableTest()
        {
            Transaction transaction = PagarMeTestFixture.CreateTestBoletoTransaction();

            transaction.Save();
            transaction.Status = TransactionStatus.Paid;
            transaction.Save();

            Payable payable         = transaction.Payables.FindAll(new Payable()).First();
            Payable payableReturned = PagarMeService.GetDefaultService().Payables.Find(payable.Id);

            Assert.IsTrue(payable.Id.Equals(payableReturned.Id));
            Assert.IsTrue(payable.Status.Equals(payableReturned.Status));
            Assert.IsTrue(payable.TransactionId.Equals(payableReturned.TransactionId));
        }
 public bool EstornoBoleto(string transactionId, PedidoEstornoBoleto estornoBoleto)
 {
     try
     {
         PagarMeService.DefaultApiKey = _conf.GetValue <string>("PagarMe:APIKey");
         var         transaction = PagarMeService.GetDefaultService().Transactions.Find(transactionId);
         BankAccount bankAccount = _mapper.Map <PedidoEstornoBoleto, BankAccount>(estornoBoleto);
         transaction.Refund(bankAccount);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Ejemplo n.º 20
0
        public IActionResult OnGet(string TokenTransacao, string IdPerfil)
        {
            if (HttpContext.Session.GetObjectFromJson <Usuario>("USUARIO") == null)
            {
                return(RedirectToPage("/Login"));
            }

            UsuarioLogado = HttpContext.Session.GetObjectFromJson <Usuario>("USUARIO");

            PagarMeService.DefaultApiKey        = "ak_test_1V9G2oIoRaRSMUD6rQZKI9XQgJzYMg";
            PagarMeService.DefaultEncryptionKey = "ek_test_YTEFhGJ5f814Q75R3xMKPmTmNKAtK7";

            Transaction transaction = PagarMeService.GetDefaultService().Transactions.Find(TokenTransacao);

            //transaction.Capture(transaction.Amount);


            using (PrivacyContext context = new PrivacyContext())
            {
                var usuarioPerfil = UsuarioModel.ObterUsuario(long.Parse(WebUtility.HtmlEncode(Criptography.Decrypt(IdPerfil))));

                Transacao objetoTransacao = new Transacao();

                objetoTransacao.Valor               = transaction.Amount;
                objetoTransacao.TokenPayPal         = TokenTransacao;
                objetoTransacao.TransactionIdPayPal = transaction.Tid;
                objetoTransacao.Ip = transaction.IP;
                objetoTransacao.PaymentStatusPayPal = transaction.Status.ToString();
                objetoTransacao.DataTransacao       = DateTime.Now;
                objetoTransacao.PayerIdPayPal       = transaction.Billing.Id;
                objetoTransacao.IdUsuario           = UsuarioLogado.IdUsuario;
                objetoTransacao.IdPerfil            = usuarioPerfil.IdUsuario;

                context.Transacao.Add(objetoTransacao);

                int salvou = context.SaveChanges();

                if (salvou == 1)
                {
                    //return RedirectToPage("/ProfilePhotos", new { Id = IdPerfil }); //Redirecionar para as fotos
                    return(new JsonResult(new { OK = true }, new Newtonsoft.Json.JsonSerializerSettings()
                    {
                    }));
                }
            }

            return(null);
        }
 public void Create()
 {
     try
     {
         model = new Recipient()
         {
             BankAccount      = PagarMeService.GetDefaultService().BankAccounts.Find(14815682),
             TransferDay      = 8,
             TransferEnabled  = true,
             TransferInterval = TransferInterval.Monthly
         };
         model.Save();
     }
     catch (PagarMeException ex)
     {
         throw ex;
     }
 }
        public void Create()
        {
            try {
                model = new Transaction()
                {
                    Amount             = 3100,
                    PaymentMethod      = PaymentMethod.CreditCard,
                    CardNumber         = "4242424242424242",
                    CardHolderName     = "Teste PagarMe",
                    CardExpirationDate = "0921",
                    CardCvv            = "123",
                    Customer           = new Customer()
                    {
                        Name           = "Teste PagarMe",
                        DocumentNumber = "43591017833",
                        DocumentType   = DocumentType.Cpf,
                        Email          = "*****@*****.**",
                        Address        = new Address()
                        {
                            Zipcode      = "13223030",
                            Neighborhood = "Jardim Paulistano",
                            Street       = "Av. Brigadeiro Faria Lima",
                            StreetNumber = "1811"
                        },
                        Phone = new Phone()
                        {
                            Ddd    = "11",
                            Number = "12345678"
                        }
                    },
                    PostbackUrl = "http://www.aledsz.com.br/validateRequest.php",
                    Metadata    = new AbstractModel(PagarMeService.GetDefaultService())
                    {
                        ["idProduto"] = "13933139"
                    }
                };

                model.Save();
            } catch (PagarMeException ex) {
                throw ex;
            }
        }
Ejemplo n.º 23
0
 public void Create()
 {
     try
     {
         model = new Subscription()
         {
             PaymentMethod = PaymentMethod.CreditCard,
             Plan          = PagarMeService.GetDefaultService().Plans.Find(46108),
             Card          = PagarMeService.GetDefaultService().Cards.Find("card_ciqice60200c8lb6dd033ju2c"),
             PostbackUrl   = "",
             Customer      = new Customer()
             {
                 Name           = "Teste PagarMe",
                 DocumentNumber = "12203395559",
                 DocumentType   = DocumentType.Cpf,
                 Email          = "*****@*****.**",
                 Address        = new Address()
                 {
                     Zipcode      = "13223030",
                     Neighborhood = "Jardim Paulistano",
                     Street       = "Av. Brigadeiro Faria Lima",
                     StreetNumber = "1811"
                 },
                 Phone = new Phone()
                 {
                     Ddd    = "11",
                     Number = "12345678"
                 }
             }
         };
         model.Metadata["Teste1"] = "Metadata de testes 1";
         model.Metadata["Teste2"] = "Metadata de testes 2";
         model.Save();
     }
     catch (PagarMeException ex)
     {
         throw ex;
     }
 }
Ejemplo n.º 24
0
        public void FindAllTransferTest()
        {
            BankAccount bank = PagarMeTestFixture.CreateTestBankAccount();

            bank.Save();
            Recipient recipient = PagarMeTestFixture.CreateRecipient(bank);

            recipient.Save();

            Transaction transaction = PagarMeTestFixture.CreateBoletoSplitRuleTransaction(recipient);

            transaction.Save();
            transaction.Status = TransactionStatus.Paid;
            transaction.Save();

            Transfer transfer = PagarMeTestFixture.CreateTestTransfer(bank.Id, recipient.Id);

            transfer.Save();

            var transfers = PagarMeService.GetDefaultService().Transfers.FindAll(new Transfer());

            Assert.IsTrue(transfers.Count() >= 1);
        }
Ejemplo n.º 25
0
 public static Payable returnPayable(int id)
 {
     return(PagarMeService.GetDefaultService().Payables.Find(id));
 }
        public Transaction ObterTransacao(string transactionId)
        {
            PagarMeService.DefaultApiKey = _configuration.GetValue <String>("Pagamento:PagarMe:ApiKey");

            return(PagarMeService.GetDefaultService().Transactions.Find(transactionId));
        }
Ejemplo n.º 27
0
        public static void Main(string[] args)
        {
            PagarMeService.DefaultApiKey        = "ak_test_TSgC3nvXtdYnDoGKgNLIOfk3TFfkl9";
            PagarMeService.DefaultEncryptionKey = "ek_test_UT6AN4fDN3BCUgo6kxUiOq6S20dbKc";

            try {
                BankAccount b = new BankAccount();

                b.Agencia        = "0196";
                b.AgenciaDv      = "0";
                b.Conta          = "05392";
                b.ContaDv        = "0";
                b.BankCode       = "0341";
                b.DocumentNumber = "05737104141";
                b.LegalName      = "JONATHAN LIMA";
                b.Save();

                Recipient r1 = PagarMeService.GetDefaultService().Recipients.Find("re_ci76hxnym00b8dw16y3hdxb21");
                Recipient r2 = PagarMeService.GetDefaultService().Recipients.Find("re_ci7nheu0m0006n016o5sglg9t");
                Recipient r3 = new Recipient();

                r3.BankAccount      = b;
                r3.TransferEnabled  = true;
                r3.TransferInterval = TransferInterval.Weekly;
                r3.TransferDay      = 1;
                r3.AnticipatableVolumePercentage = 80;
                r3.AutomaticAnticipationEnabled  = true;
                r3.Save();

                Subscription s = new Subscription()
                {
                    CardCvv            = "651",
                    CardExpirationDate = "0921",
                    CardHolderName     = "JONATHAN LIMA",
                    CardNumber         = "4242424242424242",
                    Customer           = PagarMeService.GetDefaultService().Customers.Find("77785"),
                    Plan = PagarMeService.GetDefaultService().Plans.Find("38187")
                };

                s.Save();

                Transaction t = new Transaction();

                t.SplitRules = new[] {
                    new SplitRule {
                        Recipient           = r1,
                        Percentage          = 10,
                        ChargeProcessingFee = true,
                        Liable = true
                    },
                    new SplitRule {
                        Recipient           = r2,
                        Percentage          = 40,
                        ChargeProcessingFee = false,
                        Liable = false
                    },
                    new SplitRule {
                        Recipient           = r3,
                        Percentage          = 50,
                        ChargeProcessingFee = false,
                        Liable = false
                    }
                };

                t.PaymentMethod = PaymentMethod.Boleto;
                t.Amount        = 10000;
                t.Save();
            } catch (PagarMeException ex) {
                foreach (var erro in ex.Error.Errors)
                {
                    Console.WriteLine(String.Format("Error: {0}", erro.Message));
                }
            }
        }
Ejemplo n.º 28
0
        public static void Main(string[] args)
        {
            PagarMeService.DefaultApiKey        = "ak_test_RBORKsHflgcrO7gISMyhatMx8UyiJY";
            PagarMeService.DefaultEncryptionKey = "ek_test_Ajej5CakM8QXGnA2lWX3AarwLWqspL";

            Transfer[] transfer = PagarMeService.GetDefaultService().Transfers.FindAll(new Transfer()).ToArray();
            Console.Write(transfer.Count());
            Console.Read();

            Recipient recipient = PagarMeService.GetDefaultService().Recipients.Find("re_ciwxxlge502jfwp6exm59a1ir");

            var x = recipient.Balance.Operations;

            var y = x.FindAll(new BalanceOperation()).First().MovementTransfer;

            Console.Write(y.Amount);

            try
            {
                BankAccount b = new BankAccount
                {
                    Agencia        = "0196",
                    AgenciaDv      = "0",
                    Conta          = "05392",
                    ContaDv        = "0",
                    BankCode       = "0341",
                    DocumentNumber = "05737104141",
                    LegalName      = "JONATHAN LIMA"
                };
                b.Save();

                Recipient r1 = PagarMeService.GetDefaultService().Recipients.Find("re_ci76hxnym00b8dw16y3hdxb21");
                Recipient r2 = PagarMeService.GetDefaultService().Recipients.Find("re_ci7nheu0m0006n016o5sglg9t");
                Recipient r3 = new Recipient
                {
                    BankAccount      = b,
                    TransferEnabled  = true,
                    TransferInterval = TransferInterval.Weekly,
                    TransferDay      = 1,
                    AnticipatableVolumePercentage = 80,
                    AutomaticAnticipationEnabled  = true
                };
                r3.Save();

                Subscription s = new Subscription()
                {
                    CardCvv            = "651",
                    CardExpirationDate = "0921",
                    CardHolderName     = "JONATHAN LIMA",
                    CardNumber         = "4242424242424242",
                    Customer           = PagarMeService.GetDefaultService().Customers.Find("77785"),
                    Plan = PagarMeService.GetDefaultService().Plans.Find("38187")
                };

                s.Save();

                Transaction t = new Transaction
                {
                    SplitRules = new[]
                    {
                        new SplitRule {
                            RecipientId         = r1.Id,
                            Percentage          = 10,
                            ChargeProcessingFee = true,
                            Liable = true
                        },
                        new SplitRule {
                            RecipientId         = r2.Id,
                            Percentage          = 40,
                            ChargeProcessingFee = false,
                            Liable = false
                        },
                        new SplitRule {
                            RecipientId         = r3.Id,
                            Percentage          = 50,
                            ChargeProcessingFee = false,
                            Liable = false
                        }
                    },

                    PaymentMethod = PaymentMethod.Boleto,
                    Amount        = 10000
                };
                t.Save();
            }
            catch (PagarMeException ex)
            {
                foreach (var erro in ex.Error.Errors)
                {
                    Console.WriteLine(String.Format("Error: {0}", erro.Message));
                }
            }
        }
Ejemplo n.º 29
0
        public Transaction ObterTransacao(string transactionId)
        {
            PagarMeService.DefaultApiKey = "ak_test_7VAjSBubdQj1qT3Kgc7AWluUKfiv3M";

            return(PagarMeService.GetDefaultService().Transactions.Find(transactionId));
        }
Ejemplo n.º 30
0
        //métodos agendados
        public void AtualizarPedidos()
        {
            PagarMeService.DefaultApiKey = _configuration.GetValue <string>("Pagamento:DefaultApiKey");

            //pedidos aguardando pagamento e em processamento
            var pedidos = _banco.Pedido.Include(p => p.Produto)
                          .Where(p => p.Situacao == (byte)Global.Pedido.Aguardando || p.Situacao == (byte)Global.Pedido.Processando)
                          .OrderBy(p => p.DataCriacao).ToList();

            foreach (var item in pedidos)
            {
                var transacao = PagarMeService.GetDefaultService().Transactions.Find(item.IdTransacao.ToString());

                if (transacao.Status == TransactionStatus.Paid)
                {
                    //pedido aprovado
                    item.Situacao        = (byte)Global.Pedido.Aprovado;
                    item.DataAtualizacao = Convert.ToDateTime(transacao.DateUpdated);

                    _banco.Pedido.Update(item);

                    foreach (var produtoPedido in item.Produto)
                    {
                        var produto = _banco.Produto.Find(produtoPedido.IdProduto);

                        if (produto.Estoque >= produtoPedido.Quantidade)
                        {
                            produto.Estoque       -= produtoPedido.Quantidade;
                            produtoPedido.Situacao = (byte)Global.Produto.Aprovado;

                            _banco.Produto.Update(produto);
                        }
                        else
                        {
                            produtoPedido.Situacao = (byte)Global.Produto.Cancelado;
                        }

                        produtoPedido.DataAtualizacao = DateTime.Now;
                        _banco.ProdutoHistorico.Update(produtoPedido);
                    }
                }
                else if (transacao.Status == TransactionStatus.Refunded)
                {
                    //pedido estornado
                    item.Situacao        = (byte)Global.Pedido.Estornado;
                    item.DataAtualizacao = Convert.ToDateTime(transacao.DateUpdated);

                    _banco.Pedido.Update(item);

                    foreach (var produtoPedido in item.Produto)
                    {
                        produtoPedido.Situacao        = (byte)Global.Produto.Cancelado;
                        produtoPedido.DataAtualizacao = DateTime.Now;

                        _banco.ProdutoHistorico.Update(produtoPedido);
                    }
                }
                else if (transacao.Status == TransactionStatus.Refused)
                {
                    //pedido recusado
                    item.Situacao        = (byte)Global.Pedido.Recusado;
                    item.DataAtualizacao = Convert.ToDateTime(transacao.DateUpdated);

                    _banco.Pedido.Update(item);

                    foreach (var produtoPedido in item.Produto)
                    {
                        produtoPedido.Situacao        = (byte)Global.Produto.Cancelado;
                        produtoPedido.DataAtualizacao = DateTime.Now;

                        _banco.ProdutoHistorico.Update(produtoPedido);
                    }
                }

                _banco.SaveChanges();
            }
        }