예제 #1
0
파일: Program.cs 프로젝트: rrispoli/dotnet
        static void Main(string[] args)
        {
            // TODO: Substitute the parameters below with your credentials
            //AccountCredentials credentials = new AccountCredentials("*****@*****.**", "your_token_here");
            AccountCredentials credentials = PagSeguroConfiguration.Credentials;

            try
            {

                // Instantiate a new payment request
                PaymentRequest payment = new PaymentRequest();

                // Sets the currency
                payment.Currency = Currency.Brl;

                // Add an item for this payment request
                payment.Items.Add(new Item("0001", "Notebook Prata", 1, 2430.00m));

                // Add another item for this payment request
                payment.Items.Add(new Item("0002", "Notebook Rosa", 2, 150.99m));

                // Sets a reference code for this payment request, it is useful to identify this payment in future notifications.
                payment.Reference = "REF1234";

                // Sets shipping information for this payment request
                payment.Shipping = new Shipping();
                payment.Shipping.ShippingType = ShippingType.Sedex;

                //Passando valor para ShippingCost
                payment.Shipping.Cost = 10.00m;

                payment.Shipping.Address = new Address(
                    "BRA",
                    "SP",
                    "Sao Paulo",
                    "Jardim Paulistano",
                    "01452002",
                    "Av. Brig. Faria Lima",
                    "1384",
                    "5o andar"
                );

                // Sets your customer information.
                payment.Sender = new Sender(
                    "Joao Comprador",
                    "*****@*****.**",
                    new Phone("11", "56273440")
                );

                // Sets the url used by PagSeguro for redirect user after ends checkout process
                payment.RedirectUri = new Uri("http://www.lojamodelo.com.br");

                // Add checkout metadata information
                payment.AddMetaData(MetaDataItemKeys.GetItemKeyByDescription("CPF do passageiro"), "123.456.789-09", 1);
                payment.AddMetaData("PASSENGER_PASSPORT", "23456", 1);

                // Another way to set checkout parameters
                payment.AddParameter("senderBirthday", "07/05/1980");
                payment.AddIndexedParameter("itemColor", "verde", 1);
                payment.AddIndexedParameter("itemId", "0003", 3);
                payment.AddIndexedParameter("itemDescription", "Mouse", 3);
                payment.AddIndexedParameter("itemQuantity", "1", 3);
                payment.AddIndexedParameter("itemAmount", "200.00", 3);

                SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), "12345678909");
                payment.Sender.Documents.Add(senderCPF);

                // Sets the preApproval informations
                payment.PreApproval = new PreApproval();
                var now = DateTime.Now;

                // Only works with Manual
                payment.PreApproval.Charge = Charge.Manual;

                payment.PreApproval.Name = "Seguro contra roubo do Notebook";
                payment.PreApproval.AmountPerPayment = 100.00m;
                payment.PreApproval.MaxAmountPerPeriod = 100.00m;
                payment.PreApproval.Details = string.Format("Todo dia {0} será cobrado o valor de {1} referente ao seguro contra roubo do Notebook.", now.Day, payment.PreApproval.AmountPerPayment.ToString("C2"));
                payment.PreApproval.Period = Period.Monthly;
                payment.PreApproval.DayOfMonth = now.Day;
                payment.PreApproval.InitialDate = now;
                payment.PreApproval.FinalDate = now.AddMonths(6);
                payment.PreApproval.MaxTotalAmount = 600.00m;
                payment.PreApproval.MaxPaymentsPerPeriod = 1;

                payment.ReviewUri = new Uri("http://www.lojamodelo.com.br/revisao");

                Uri paymentRedirectUri = payment.Register(credentials);

                Console.WriteLine("URL do pagamento : " + paymentRedirectUri);
                Console.ReadKey();
            }
            catch (PagSeguroServiceException exception)
            {
                if (exception.StatusCode == HttpStatusCode.Unauthorized)
                {
                    Console.WriteLine("Unauthorized: please verify if the credentials used in the web service call are correct.\n");
                }
                Console.ReadKey();
            }
        }
        public ActionResult FinalizarCompra(string pedidoId) {
            try
            {
                Response.AppendHeader("Access-Control-Allow-Origin", "https://sandbox.pagseguro.uol.com.br");

                var session = Session["autenticacao"] as SessionAutenticacaoClient;
                var sessionCarrinho = Session["carrinho"] as SessionCarrinho;

                if (session == null) {

                    return RedirectToAction("Index", "Login", new { actionRedirect = "index", controllerRedirect = "Carrinho" });
                }

                if (pedidoId.Length > 10) {

                    AccountCredentials cred = PagSeguroConfiguration.Credentials(true);

                    Transaction transaction = TransactionSearchService.SearchByCode(
                        cred,
                        pedidoId,
                        false
                    );

                    var pedidoTransaction = db.Pedido.Find(Int32.Parse(transaction.Reference));
                    pedidoTransaction.PagseguroId = pedidoId;

                    db.SaveChanges();

                    return RedirectToAction("Index", "Home");
                }

                var pedido = db.Pedido.Find(Int32.Parse(pedidoId));
                var pedidoItens = db.PedidoItem.Where(x => x.Pedido.Id == pedido.Id).ToList();

                PaymentRequest payment = new PaymentRequest();
                payment.Currency = Currency.Brl;
          

                foreach (var carrinhoProduto in sessionCarrinho.ProdutosCarrinho) {
                    payment.Items.Add(new Item(
                        carrinhoProduto.Produto.Id.ToString(), 
                        carrinhoProduto.Produto.Descricao, 
                        carrinhoProduto.Quantidade, 
                        carrinhoProduto.Produto.Preco
                        )
                    );
                }

                payment.Shipping = new Shipping();
                payment.Shipping.ShippingType = sessionCarrinho.isSedex == true ? ShippingType.Sedex : ShippingType.Pac;

                var cidade = db.Cidade.Where(x => x.Id == sessionCarrinho.Endereco.cCidade).FirstOrDefault();
                var estado = db.Estado.Where(x => x.Id == cidade.cEstado).FirstOrDefault();
                cidade.Estado = estado;

                sessionCarrinho.Endereco.Cidade = cidade;

                payment.Shipping.Address = new Address(
                    "BRA", 
                    sessionCarrinho.Endereco.Cidade.Estado.Abreviacao,
                    sessionCarrinho.Endereco.Cidade.Descricao,
                    sessionCarrinho.Endereco.Bairro,
                    sessionCarrinho.Endereco.Cep,
                    sessionCarrinho.Endereco.Logradoruro,
                    sessionCarrinho.Endereco.Numero,
                    sessionCarrinho.Endereco.Complementro
                    
                );

                payment.Reference = pedido.Id.ToString();
            
                var url = String.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Request.Url.AbsolutePath);

                payment.RedirectUri = new Uri(url);
                payment.MaxAge = 172800;
                payment.MaxUses = 15;
                payment.Shipping.Cost = sessionCarrinho.Frete;

                /* AccountCredentials credentials = new AccountCredentials (
                     "*****@*****.**",
                     "5A207A1660254D41B4C393C19B3D09DC"
                 );*/

                AccountCredentials credentials = PagSeguroConfiguration.Credentials(true);

                Uri paymentRedirectUri = payment.Register(credentials);

                Session.Remove("carrinho");
                
                Response.Redirect(paymentRedirectUri.ToString());

                
                return View();
            }
            catch(PagSeguroServiceException ex) {
                throw;
            }
        }
예제 #3
0
파일: Program.cs 프로젝트: Japle/dotnet
        static void RegisterExample()
        {
            PaymentRequest paymentRequest = new PaymentRequest();
            // Preencher propriedades da requisição do pagamento aqui

            bool isSandbox = false;

            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox);

            // Criando o código de requisição de pagamento
            // e obtendo a URL da página de pagamento
            // do PagSeguro
            Uri paymentRedirectUri = paymentRequest.Register(credentials);

            //Response.Redirect(paymentRedirectUri.ToString());
        }
예제 #4
0
파일: Program.cs 프로젝트: narugo/dotnet
        static void RegisterExample()
        {
            PaymentRequest paymentRequest = new PaymentRequest();
            // Preencher propriedades da requisição do pagamento aqui

            // Inicializando credenciais
            AccountCredentials credentials =
                new AccountCredentials(
                    "*****@*****.**",
                    "95112EE828D94278BD394E91C4388F20");

            // Criando o código de requisição de pagamento
            // e obtendo a URL da página de pagamento
            // do PagSeguro
            Uri paymentRedirectUri = paymentRequest.Register(credentials);

            //Response.Redirect(paymentRedirectUri.ToString());
        }
예제 #5
0
파일: Program.cs 프로젝트: Japle/dotnet
        static void Main(string[] args)
        {
            bool isSandbox = true;

            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            try
            {

                AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox);

                // Instantiate a new payment request
                PaymentRequest payment = new PaymentRequest();

                // Sets the currency
                payment.Currency = Currency.Brl;

                // Add an item for this payment request
                payment.Items.Add(new Item("0001", "Notebook Prata", 1, 2430.00m));

                // Add another item for this payment request
                payment.Items.Add(new Item("0002", "Notebook Rosa", 2, 150.99m));

                // Sets a reference code for this payment request, it is useful to identify this payment in future notifications.
                payment.Reference = "REF1234";

                // Sets shipping information for this payment request
                payment.Shipping = new Shipping();
                payment.Shipping.ShippingType = ShippingType.Sedex;

                //Passando valor para ShippingCost
                payment.Shipping.Cost = 10.00m;

                payment.Shipping.Address = new Address(
                    "BRA",
                    "SP",
                    "Sao Paulo",
                    "Jardim Paulistano",
                    "01452002",
                    "Av. Brig. Faria Lima",
                    "1384",
                    "5o andar"
                );

                // Sets your customer information.
                payment.Sender = new Sender(
                    "Joao Comprador",
                    "*****@*****.**",
                    new Phone("11", "56273440")
                );

                // Sets the url used by PagSeguro for redirect user after ends checkout process
                payment.RedirectUri = new Uri("http://www.lojamodelo.com.br");

                // Add checkout metadata information
                payment.AddMetaData(MetaDataItemKeys.GetItemKeyByDescription("CPF do passageiro"), "123.456.789-09", 1);
                payment.AddMetaData("PASSENGER_PASSPORT", "23456", 1);

                // Another way to set checkout parameters
                payment.AddParameter("senderBirthday", "07/05/1980");
                payment.AddIndexedParameter("itemColor", "verde", 1);
                payment.AddIndexedParameter("itemId", "0003", 3);
                payment.AddIndexedParameter("itemDescription", "Mouse", 3);
                payment.AddIndexedParameter("itemQuantity", "1", 3);
                payment.AddIndexedParameter("itemAmount", "200.00", 3);

                SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), "12345678909");
                payment.Sender.Documents.Add(senderCPF);

                Uri paymentRedirectUri = payment.Register(credentials);

                Console.WriteLine("URL do pagamento : " + paymentRedirectUri);
                Console.ReadKey();
            }
            catch (PagSeguroServiceException exception)
            {
                Console.WriteLine(exception.Message + "\n");

                foreach (ServiceError element in exception.Errors)
                {
                    Console.WriteLine(element + "\n");
                }
                Console.ReadKey();
            }
        }
예제 #6
0
        public void Pay()
        {
            const bool isSandbox = true;

               // EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            var credentials = PagSeguroConfiguration.Credentials(isSandbox);

            // Instanciar uma nova requisição de pagamento
            var payment = new PaymentRequest { Currency = Currency.Brl };

            // Adicionar produtos
            payment.Items.Add(new Item("0001", "Orçamento", 1, 20.00m));

            // Código que identifica o pagamento
            payment.Reference = "REF1234";

            //// Informações de entrega
            //payment.Shipping = new Shipping
            //{
            //    ShippingType = ShippingType.Sedex,
            //    Cost = 10.00m,
            //    Address = new Address(
            //        "BRA",
            //        "SP",
            //        "Sao Paulo",
            //        "Jardim Paulistano",
            //        "01452002",
            //        "Av. Brig. Faria Lima",
            //        "1384",
            //        "5o andar"
            //        )
            //};

            // Informações do remetente
            payment.Sender = new Sender(
                "Joao Comprador",
                "*****@*****.**",
                new Phone("11", "56273440")
            );

            // URL a redirecionar o usuário após pagamento
            payment.RedirectUri = new Uri("http://www.agilizaorcamento.com.br");

            // Informações extras para identificar o pagamento.
            // Essas informações são livres para adicionar o que for necessário.
            //payment.AddMetaData(MetaDataItemKeys.GetItemKeyByDescription("CPF do passageiro"), "123.456.789-09", 1);
            //payment.AddMetaData("PASSENGER_PASSPORT", "23456", 1);

            //// Outra forma de definir os parâmetros de pagamento.
            //payment.AddParameter("senderBirthday", "07/05/1980");
            //payment.AddIndexedParameter("itemColor", "verde", 1);
            //payment.AddIndexedParameter("itemId", "0003", 3);
            //payment.AddIndexedParameter("itemDescription", "Mouse", 3);
            //payment.AddIndexedParameter("itemQuantity", "1", 3);
            //payment.AddIndexedParameter("itemAmount", "200.00", 3);

            //var senderCpf = new SenderDocument(Documents.GetDocumentByType("CPF"), "03078690164");
            //payment.Sender.Documents.Add(senderCpf);

            var paymentRedirectUri = payment.Register(credentials);
        }