Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

rcordeiro

Geral um pagamento com API v2

Recommended Posts

Galera,

Gosteria de uma ajuda, pois estou com o seguinte problema de integração.

Estou usando o "Tutorial da Biblioteca PagSeguro em .NET" (https://pagseguro.uol.com.br/v2/guia-de-integracao/tutorial-da-biblioteca-pagseguro-netframework.html)

 

Quando faço o registro pelo PaymentService.Register Ocorre o seguinte erro: exception HttpStatusCode: BadRequest

 

Alguém Poderiam me informar o que esta contecendo?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Também estou com o mesmo problema, ainda não consegui solucionar, quero migrar a minha loja para a nova API mas não está funcionando. Precisa setar alguma configuração no Painel que eu possa ter esquecido? As configurações de cultura estão todas setadas para UTF-8

 

Segue método de finalizar processo que estou invocando

 

   private void finalizarProcesso()
   {
       this.dtCarrinho = (DataTable)HttpContext.Current.Session["CARRINHO"];
       // Verifica se carrinho está vazio
       if (this.dtCarrinho != null && this.dtCarrinho.Rows.Count > 0)
       {
           // Inicia pagamento                
           PaymentRequest payment = new PaymentRequest();
           payment.Currency = Currency.Brl;           

           foreach (DataRow dr in this.dtCarrinho.Rows)
           {
               string nm__ext = dr["NOME"].ToString();
               if (dr["EXT"].ToString() != String.Empty) { nm__ext += "__" + dr["EXT"].ToString(); }
               //payment.Items.Add(new Item(dr["ID_PRODUTO"].ToString(), nm__ext, Convert.ToInt32(dr["QTD_VENDA"].ToString()), Convert.ToDecimal(dr["VALOR"])));                
               payment.Items.Add(new Item("01","Teste", 1, 20));
           }

           //Informações do comprador
           string[] _role = Roles.GetRolesForUser(HttpContext.Current.User.Identity.Name);
           switch (_role[0])
           {
               case "EMPRESA":
                   Empresa _empresa = new Empresa(Session["ID"].ToString());
                   if (_empresa.atualizaEmpresa(_empresa.ID_EMPRESA, _empresa.NOME, _empresa.CPF_CNPJ, _empresa.F_J, this.tbRua.Text, this.tbComplemento.Text,
                           this.tbNro.Text, this.tbBairro.Text, this.tbCidade.Text, this.ddlEstado.SelectedValue, this.tbFone.Text, _empresa.LATITUDE, _empresa.LONGITUDE, 
                           _empresa.NOTA_NIK_NET, ((float)_empresa.VALOR_FATURA), _empresa.PACOTE.ToString(), _empresa.URL, _empresa.PLANO.ToString(), 
                           _empresa.DESCRICAO, this.tbDDD.Text, this.tbCEP.Text))
                   {
                       MembershipUser usuario = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                       payment.Sender = new Sender(_empresa.NOME, usuario.Email, new Phone(_empresa.DDD, _empresa.FONE));
                   }
                   break;

               default:
                   Consumidor _consumidor = new Consumidor(HttpContext.Current.User.Identity.Name);
                   if (_consumidor.atualizaConsumidor(_consumidor.ID_CONSUMIDOR, HttpContext.Current.User.Identity.Name, this.tbNome.Text, this.tbRua.Text, this.tbNro.Text,
                           this.tbBairro.Text, this.tbCidade.Text, this.tbCEP.Text, this.ddlEstado.SelectedValue, this.tbComplemento.Text, this.tbDDD.Text, this.tbFone.Text, 
                           _consumidor.ESCOLARIDADE, _consumidor.PROFISSAO, _consumidor.DATA_NASCIMENTO, _consumidor.AVATAR, _consumidor.LATITUDE, _consumidor.LONGITUDE))
                   {
                       MembershipUser usuario = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                       payment.Sender = new Sender(_consumidor.NOME, "mauricio@emvideira.com.br", new Phone(this.tbDDD.Text, this.tbFone.Text));
                   }

                   break;
           }

           //Informações de frete
           payment.Shipping = new Shipping();
           switch(Session["FRETE"].ToString())
           {
               case "41106" :
                   payment.Shipping.ShippingType = ShippingType.Pac;
                   break;
               case "40010":
                   payment.Shipping.ShippingType = ShippingType.Sedex;
                   break;
           }

           // Informações de endereço
           payment.Shipping.Address = new Address("BRA", this.ddlEstado.SelectedValue, this.tbCidade.Text, this.tbBairro.Text, this.tbCEP.Text, this.tbRua.Text, this.tbNro.Text, this.tbComplemento.Text);
           //payment.Shipping.Address = new Address("BRA", this.ddlEstado.SelectedValue, this.tbCidade.Text, this.tbBairro.Text, this.tbCEP.Text, this.tbRua.Text, this.tbNro.Text, this.tbComplemento.Text);

           // Persiste compra e retorna id referência
           PasseLivre _passeLivre = new PasseLivre();
           payment.Reference = _passeLivre.insereVendaPasseLivre(this.dtCarrinho, HttpContext.Current.User.Identity.Name, this.tbNome.Text);

           AccountCredentials credenciais = new AccountCredentials("meu@email", "meutoken");
           Uri paymentRedirectUri = PaymentService.Register(credenciais, payment);

           Response.Redirect(paymentRedirectUri.ToString()); 
       }   
   }

Compartilhar este post


Link para o post
Compartilhar em outros sites

Ao invés de utilizar UTF-8, tente utilizar ISO-8859-1, isso evitará problemas de acentuação.

 

Ao invés de utilizar variáveis, coloque dados fixo, assim eu consigo ver o que está sendo passado.

 

Por exemplo eu não sei o que tem dentro da sessão carrinho...

 

Imagine que quem for tentar lhe ajudar, possa pegar o seu código copiar colar, e mandar executar e simular o mesmo erro seu.

 

Da forma que está ai eu não consigo testar nada...

 

Antes de mais nada... Já tentou executar o exemplo que vem junto com a biblioteca em .NET?

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.