Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        // envia email para gestores avisando sobre nova entrega
        EnviarEmail();

        //dados da solicitação
        string  chkvalorstr = Request.QueryString["v1"];
        decimal chkvalor    = Convert.ToDecimal(chkvalorstr);

        Session["OSId"] = Request.QueryString["v2"];

        bool isSandbox = true;

        EnvironmentConfiguration.ChangeEnvironment(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", "Servico de Motoboy", 1, chkvalor));

        // Sets a reference code for this payment request, it is useful to identify this payment in future notifications.
        payment.Reference = "Cli_" + Session["UserID"].ToString();

        payment.AddParameter("shippingAddressRequired", "false");


        // Sets the url used by PagSeguro for redirect user after ends checkout process
        payment.RedirectUri = new Uri("http://logvai01.azurewebsites.net/RedirectRetorno.aspx");

        // Add and remove groups and payment methods
        List <string> accept = new List <string>();

        accept.Add(ListPaymentMethodNames.DebitoItau);
        payment.AcceptPaymentMethodConfig(ListPaymentMethodGroups.CreditCard, accept);

        try
        {
            //faz requisição de check-out e aguarda retorno com link para pagamento
            AccountCredentials credentials = new AccountCredentials("*****@*****.**", "C1BF7C4BE89A481A8C215B3275F41973");
            Uri    paymentRedirectUri      = payment.Register(credentials);
            string urlpagam = paymentRedirectUri.ToString();

            //encaminha usuário para pagina de pagamento (ambiente pagseguro)
            Response.Write("<script>self.parent.location.href='" + urlpagam + "';</script>");
        }
        catch (PagSeguroServiceException exception)
        {
            Response.Write("<script>alert('Tente Novamente! Motivo: " + exception.Message + "');</script>");
        }
    }
        private static void Main(string[] args)
        {
            //Use global configuration
            //PagSeguroConfiguration.UrlXmlConfiguration = "../../../../../Configuration/PagSeguroConfig.xml";

            bool isSandbox = false;

            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            // Instantiate a new payment request
            PaymentRequest payment = new PaymentRequest
            {
                // Sets the currency
                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
            {
                ShippingType = ShippingType.Sedex,

                //Passando valor para ShippingCost
                Cost = 10.00m,

                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")
                );

            SenderDocument document = new SenderDocument(Documents.GetDocumentByType("CPF"), "12345678909");

            payment.Sender.Documents.Add(document);

            // 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);

            // Add discount per payment method
            payment.AddPaymentMethodConfig(PaymentMethodConfigKeys.DiscountPercent, 50.00, PaymentMethodGroup.CreditCard);

            // Add installment without addition per payment method
            payment.AddPaymentMethodConfig(PaymentMethodConfigKeys.MaxInstallmentsNoInterest, 6, PaymentMethodGroup.CreditCard);

            // Add installment limit per payment method
            payment.AddPaymentMethodConfig(PaymentMethodConfigKeys.MaxInstallmentsLimit, 8, PaymentMethodGroup.CreditCard);

            // Add and remove groups and payment methods
            List <string> accept = new List <string>
            {
                ListPaymentMethodNames.DebitoItau,
                ListPaymentMethodNames.DebitoHSBC
            };

            payment.AcceptPaymentMethodConfig(ListPaymentMethodGroups.CreditCard, accept);

            List <string> exclude = new List <string>
            {
                ListPaymentMethodNames.Boleto
            };

            payment.ExcludePaymentMethodConfig(ListPaymentMethodGroups.Boleto, exclude);

            try
            {
                /// Create new account credentials
                /// This configuration let you set your credentials from your ".cs" file.
                AccountCredentials credentials = new AccountCredentials("*****@*****.**", "256422BF9E66458CA3FE41189AD1C94A");

                /// @todo with you want to get credentials from xml config file uncommend the line below and comment the line above.
                //AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox);

                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();
            }
        }
Beispiel #3
0
        protected void LinkButtonHistorico_Click1(object sender, EventArgs e)
        {
            /// EXERCICIO:
            /// Conclua a integração com o PagSeguro

            /// EXERCICIO:
            /// Implemente a integração com o Paypal

            //Use global configuration
            PagSeguroConfiguration.UrlXmlConfiguration = "PagSeguroConfig.xml";

            bool isSandbox = false;

            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

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

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

            List <VendaDetalheDTO> ListaVenda = VendaAtual.ListaVendaDetalhe;

            foreach (VendaDetalheDTO objVenda in ListaVenda)
            {
                payment.Items.Add(new Item(objVenda.Produto.CodigoInterno.ToString(), objVenda.Produto.Nome, 1, objVenda.Produto.ValorVenda.Value));
            }

            // 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")
                );

            SenderDocument document = new SenderDocument(Documents.GetDocumentByType("CPF"), "12345678909");

            payment.Sender.Documents.Add(document);

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

            // Add installment without addition per payment method
            payment.AddPaymentMethodConfig(PaymentMethodConfigKeys.MaxInstallmentsNoInterest, 6, PaymentMethodGroup.CreditCard);

            // Add and remove groups and payment methods
            List <string> accept = new List <string>();

            accept.Add(ListPaymentMethodNames.DebitoItau);
            accept.Add(ListPaymentMethodNames.DebitoHSBC);
            payment.AcceptPaymentMethodConfig(ListPaymentMethodGroups.CreditCard, accept);

            List <string> exclude = new List <string>();

            exclude.Add(ListPaymentMethodNames.Boleto);
            payment.ExcludePaymentMethodConfig(ListPaymentMethodGroups.Boleto, exclude);

            try
            {
                /// Create new account credentials
                /// This configuration let you set your credentials from your ".cs" file.
                AccountCredentials credentials = new AccountCredentials("*****@*****.**", "01D9sdfg5446s5d4g6sd5f4gA48F");

                /// @todo with you want to get credentials from xml config file uncommend the line below and comment the line above.
                //AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox);

                Uri paymentRedirectUri = payment.Register(credentials);

                Response.Redirect(paymentRedirectUri.ToString());

                //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();
            }
        }
        public string CriarPagamento(PagSeguroModel pagSeguro)
        {
            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

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

            var itemParam = new ParameterItem("encoding", "UTF-8");

            payment.Parameter.Items.Add(itemParam);

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

            foreach (var item in pagSeguro.produtos)
            {
                // Add an item for this payment request
                payment.Items.Add(new Item(item.id, RemoverAcentos(item.descricao), item.qtde, item.unitario));
            }
            // Sets a reference code for this payment request, it is useful to identify this payment in future notifications.
            payment.Reference = pagSeguro.paymontReference;

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

            //Passando valor para ShippingCost
            payment.Shipping.Cost = pagSeguro.shippingCost;

            payment.Shipping.Address = new Address(pagSeguro.enderecoEntrega.pais, pagSeguro.enderecoEntrega.estado,
                                                   pagSeguro.enderecoEntrega.cidade, pagSeguro.enderecoEntrega.bairro, pagSeguro.enderecoEntrega.cep,
                                                   pagSeguro.enderecoEntrega.endereco, pagSeguro.enderecoEntrega.numero, pagSeguro.enderecoEntrega.complemento);

            // Sets your customer information.
            payment.Sender = new Sender(pagSeguro.cliente.nome, pagSeguro.cliente.email, new Phone(pagSeguro.cliente.ddd, pagSeguro.cliente.telefone));

            SenderDocument document = new SenderDocument(Documents.GetDocumentByType("CPF"), pagSeguro.cliente.documento);

            payment.Sender.Documents.Add(document);

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

            // Add checkout metadata information
            //payment.AddMetaData(MetaDataItemKeys.GetItemKeyByDescription("CPF do passageiro"), "086.111.629-19", 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);

            // Add discount per payment method
            //payment.AddPaymentMethodConfig(PaymentMethodConfigKeys.DiscountPercent, 5.00, PaymentMethodGroup.CreditCard);

            // Add installment without addition per payment method
            //payment.AddPaymentMethodConfig(PaymentMethodConfigKeys.MaxInstallmentsNoInterest, 6, PaymentMethodGroup.CreditCard);

            // Add installment limit per payment method
            //payment.AddPaymentMethodConfig(PaymentMethodConfigKeys.MaxInstallmentsLimit, 8, PaymentMethodGroup.CreditCard);

            // Add and remove groups and payment methods
            List <string> accept = new List <string>();

            accept.Add(ListPaymentMethodNames.DebitoBradesco);
            accept.Add(ListPaymentMethodNames.DebitoBancoDoBrasil);
            accept.Add(ListPaymentMethodNames.Boleto);
            payment.AcceptPaymentMethodConfig(ListPaymentMethodGroups.CreditCard, accept);

            //List<string> exclude = new List<string>();
            //exclude.Add(ListPaymentMethodNames.Boleto);
            //payment.ExcludePaymentMethodConfig(ListPaymentMethodGroups.Boleto, exclude);

            try
            {
                /// Create new account credentials
                /// This configuration let you set your credentials from your ".cs" file.
                //AccountCredentials credentials = new AccountCredentials("*****@*****.**", "B8F8E56F7F1F4D658427A25683472131");

                /// @todo with you want to get credentials from xml config file uncommend the line below and comment the line above.
                AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox);

                Uri paymentRedirectUri = payment.Register(credentials);

                return(paymentRedirectUri.AbsoluteUri);
            }
            catch
            {
                throw;
            }
        }