Pagseguro getPaymentMethods Error

Asked

Viewed 1,997 times

0

59001 - "Unknown web Session id"

I am implementing Transparent Pagseguro Checkout using PHP v2 API, but I always get the above error in the Javascript part. Their support is horrible, there’s nowhere else to turn.

Edited: I added the real link so that tests can be performed.

Download of the Files

Follows the code:

function cartao(){
  $(document).ready(function(){
    var senderHash;
	$.post('http://plimplimfestas.com/rafael/checkout.php', { sessao: "sessao" }, function(returnedData){
    //TESTES
    //*******************************************//
	//***** Inicializando a sessão checkout *****//		//*******************************************//
	var xml = returnedData,
	xmlDoc = $.parseXML(xml),
	$xml = $(xmlDoc),
	$title = $xml.find("id");
		
	var idSess = $title.text();
	console.log("SessionId");
    console.log(idSess);
    PagSeguroDirectPayment.setSessionId(idSess);
      
    //***************************************//
    //***** Obtendo o hash do comprador *****//
    //***************************************//
    var hashComprador = PagSeguroDirectPayment.getSenderHash();
    senderHash = hashComprador;
    //FIM TESTES
  }).done(function(){
    PagSeguroDirectPayment.getPaymentMethods({
				success: function(response){ console.log(response); },
				error: function(response){ console.log(response); },
				complete: function(response){ console.log(response); }
			});
			throw "Stop forçado.";
      //Os consoles de error e complete acima retornam o erro
      /*
      existem mais trechos, porém não passa do ponto acima
      */
      
      }).fail(function(e){
			console.error(e);
	  });
   }); //document ready
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

3 answers

2


Apparently, he’s not recognizing the Session ID used. How are you doing to get the Session ID?

The correct one, which should be done on the server side, would be something like this (example in PHP, using their SDK):

$credentials = PagSeguroConfig::getAccountCredentials();    
$idSession = PagSeguroSessionService::getSession($credentials);

Then, in JS, you receive this data. If your PHP code is bundled with JS (not recommended, but this example is for clarification purposes only), you can do something like this:

var idSess = '<?= $idSession ?>';

If this is not the case, pass the code where you get the Session ID

Note: Example link to JS:http://codepen.io/szagot/pen/RRdXVY?editors=0010

  • 1

    Add the link http://codepen.io/szagot/pen/RdXVY?editors=0010 in your reply, because without it I would still be lost haha Everything working, thanks!

  • @Jhonatanpereira - Placed ;)

1

All URL requests in the production document must contain HTTPS(SSL), except in the sandbox development phase.

-1

This really isn’t described in the documentation, sad...

After getting the session ID through the vc API you should set it in the Secure Pag lib object

PagSeguroDirectPayment.setSessionId('d2bd8672814kkkkkka67b44e872172')

then you can call the other methods quiet :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.