Pagseguro does not redirect customer after payment

Asked

Viewed 3,857 times

5

After payment, the customer should be redirected to the thank you page I set up, but that’s not what happens.

See, I took an API, I just needed to set up 2 files, among them are: PaymentPagseguro.php and PagSeguroConfig.php.

The customer pays, I get the payment, it’s all right, the problem is that it is not directed to page that I set up in this file PaymentPagseguro.php, exactly on this piece of code:

$paymentRequest->setRedirectUrl("https://meusite.com/obrigado.php");

Note that, I get some errors in the console (not visible to the client) regarding the application of Pagseguro, but I never suspected because everything works normally, only the redirection that does not work.

But look, the errors that occur on the console:

  1. At the opening of the page:

    (2) Blocked loading of merged active content "http://clicklogger.rm.uol.com.br/qkw_crossdomain.html?appender=&prd=32&grouping=&referrer=https%3A//www.slimpatchbr.com/buy.php

    This must occur because my site is https, but I don’t believe it is the problem..

  2. When I fill out my email and click Forward:

    GET https://dna.uol.com.br/service/sample/conn?id=64ef863649064183a7e740d6a2ae259c&sess=&_=1427674714416 403 Forbidden 60ms


    GET https://dna.uol.com.br/service/sample/conn?id=64ef863649064183a7e740d6a2ae259c&sess=&_=1427674714513 403 Forbidden 42ms

  3. When I finish the payment and click on close

    Typeerror: this.callback is Undefined ... Token=this.token;},catchCommunicationException:Function(){if(window.location.tos...

Well, more details, ask, for me is a big problem, because on the thank page I have conversion pixels that are not being activated.

  • If someone wants to go deeper into the problems of the log, I can indicate the page where I sell my products(and there where he buys too).

3 answers

5

Follow the steps to deal with the issue:

  1. Access the Pagseguro control panel.

  2. In the left menu, Integrations option, Redirect Page, A. Fixed redirect page.

  3. Enter the URL in the "Set redirect page:" field and click "Enable".

  4. In the left menu, Integrations option, Transaction Notification, enter the URL in the "Set URL to receive notifications:" field and click "Enable".

  5. In the left menu, Integrations, Automatic Data Return option, enter the URL in the "Set URL to receive notifications:" field and click "Enable".

Using the new API?

  • 2

    The redirect URL is not fixed, because I use an API and I set up the page on it. Nor could it be fixed, since in the same account Pagseguro meets 2 different websites (2 different redirection pages). And as it says there: "You can also set a dynamic redirect page via API. Using this feature, the fixed redirect page if filled will no longer work."... The automatic return of data has already been completed, the problem is not notifications, but that the client is not redirected to the thank page, defined in the API. Thanks for the help!!

5


I believe you’re using the v2, as you did not inform as configured, I will only assume the answer as to documentation

In PHP we should call the class PagSeguroPaymentRequest

$paymentRequest = new PagSeguroPaymentRequest();

To add an item or more:

$paymentRequest->addItem('0001', 'Notebook', 1, 2430.00);  
$paymentRequest->addItem('0002', 'Mochila',  1, 150.99);

Informing the buyer’s address as well as freight type:

$sedexCode = PagSeguroShippingType::getCodeByType('SEDEX');  
$paymentRequest->setShippingType($sedexCode);  
$paymentRequest->setShippingAddress(  
  '01452002',  
  'Av. Brig. Faria Lima',
  '1384',
  'apto. 114',
  'Jardim Paulistano',
  'São Paulo',
  'SP',
  'BRA'
);

If you already have the buyer’s details, you can inform them to facilitate the payment flow. This way they will not need to inform them again.

$paymentRequest->setSender(  
  'João Comprador',  
  '[email protected]',  
  '11',  
  '56273440',  
  'CPF',  
  '156.009.442-76'  
); 

Defining the currency to be used in the payment.

$paymentRequest->setCurrency("BRL"); 

Defining additional information, which can be used by your system after the payment flow in Pagseguro, I believe the problem can be here.

// Referenciando a transação do PagSeguro em seu sistema
$paymentRequest->setReference("REF123");  
  
// URL para onde o comprador será redirecionado (GET) após o fluxo de pagamento  
$paymentRequest->setRedirectUrl("https://exemplo.com/obrigado.php");  
  
// URL para onde serão enviadas notificações (POST) indicando alterações no status da transação  
$paymentRequest->addParameter('notificationURL', 'http://www.lojamodelo.com.br/nas');

It is possible to add parameters/information in the checkout request that, although already implemented in the API, are not yet available as methods in the library.

$paymentRequest->addParameter('senderBornDate', '07/05/1981');

Finally you must register the request in the Pagseguro system. The return of the Register method, by default, will be the URL that should be used to redirect the buyer to the payment screen in Pagseguro.

The way to redirect the buyer to make the payment on Pagseguro after the return of the call to the Register method depends on the implementation of your system.

try {
  $credentials = PagSeguroConfig::getAccountCredentials();
  $checkoutUrl = $paymentRequest->register($credentials); 
} catch (PagSeguroServiceException $e) {
    die($e->getMessage());
}

At this point we should use the $checkoutUrl, should look something like:

try {
    $credentials = PagSeguroConfig::getAccountCredentials();
    $checkoutUrl = $paymentRequest->register($credentials);

    echo '<h2>Criando requisição de pagamento</h2>',
        '<p>URL do pagamento: <strong>', $checkoutUrl,'</strong></p>',
        '<p>',

        //Mostra link para pagamento
        '<a title="URL do pagamento" href="', $checkoutUrl,'">',
        'Ir para URL do pagamento.</a></p>';

} catch (PagSeguroServiceException $e) {
    die($e->getMessage());
}

If the use of PagSeguroConfig::getAccountCredentials not working is probably because there is something wrong with the data from Pagseguroconfig.php, but you can try "manually" to check the situation:

$credentials = new PagSeguroAccountCredentials("[email protected]",
    "E231B2C9BCC8474DA2E260B6C8CF60D3");

$url = $paymentRequest->register($credentials);

E231B2C9BCC8474DA2E260B6C8CF60D3 is the authorization code, you can also set it on PagSeguroConfig::getAccountCredentials, as described in the examples, thus:

$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");

Some of the other problems (error 403) that occur may be due to missing "token" from pagesecure file, configure the file and preferably add the actual path to a log file.

Start configuration normally on Pagseguroconfig.php:

$PagSeguroConfig = array();

$PagSeguroConfig['environment'] = "production"; // production ou sandbox

$PagSeguroConfig['credentials'] = array();
$PagSeguroConfig['credentials']['email'] = "your_pagseguro_email";

This may be the point that needs to be corrected, it is necessary to token of production the appId and the appKey:

$PagSeguroConfig['credentials']['token']['production'] = "Token de produçao do pagseguro";
$PagSeguroConfig['credentials']['token']['sandbox'] = "Token do sandbox";
$PagSeguroConfig['credentials']['appId']['production'] = "Seu ID de produção";
$PagSeguroConfig['credentials']['appId']['sandbox'] = "Seu ID de produção";
$PagSeguroConfig['credentials']['appKey']['production'] = "Sua chave de aplicativo para o ambiente de produção";
$PagSeguroConfig['credentials']['appKey']['sandbox'] = "Sua chave de aplicativo para o ambiente sandbox";

Configure the log to get details, maybe it helps to find the problem define true in $PagSeguroConfig['log']['active'] = true; and the actual path of a file in $PagSeguroConfig['log']['fileLocation'], for example:

$PagSeguroConfig['log']['fileLocation'] = '/home/user/www/pagseguro/log.txt';

It should look something like:

$PagSeguroConfig['log'] = array();
$PagSeguroConfig['log']['active'] = true;
$PagSeguroConfig['log']['fileLocation'] = '/home/user/www/pagseguro/log.txt';

The mistake TypeError: this.callback is undefined may have occurred because of (2) Bloqueado carregamento de conteúdo ativo mesclado, but I don’t know exactly at what point this problem occurs (whether it is on your site or when it is already on the pagseguro page).

To download the API for PHP go to:

Tip: after downloading access folder source/examples, has all the examples needed for integration via PHP, it might be useful

  • 2

    +1 For the detailed answer! Who does not understand already has where to read on the subject :)

  • See: http://download.uol.com.br/pagseguro/docs/pagseguro-checkout-lightbox.pdf, on the last page, was the detail that I had forgotten (Events of Checkout Lightbox)... You can edit your reply and add this, because for me it solved this way. That is, I need to generate that script, so that in case of success(payment completed) I redirect the customer, or if abort(closed the means of payment) I can do something (like offer another offer..) @Guilhermenascimento

  • @Alexandrec.Caus does not that I disagree with his solution, on the contrary, but I think you yourself could provide an answer, unfortunately there is no way to provide the reward for yourself, but you could formulate a good answer. I just didn’t add it because I don’t know if lightbox is really necessary for use with the API in PHP and since I never used lightbox I don’t know if it’s really necessary. :)

1

About the first problem, I found a solution on google.

In your question you quoted:

This must occur because my site is https, but I don’t believe it is the problem..

In that link you can see the original conversation.

Follow the answer given:

I’m glad its usefulness to you ! Mixed content usually means that your static files are being served from HTTP and HTTPS, if this is true, you will need to ensure that all files ( and API) is using HTTPS

Try this.

By the way, have you tried to enter their forum at this link ?

  • I will try, but the blocked content is from pagseguro, I find it strange that pagseguro does not make it clear, or does not provide an API that also accompanies a secure server (HTTPS), I will try to make a purchase and see if(now with SSL disabled) works normally. Just as I entered the forum, I left my question there, and the answers are the basics, the patterns, as activation of the payment API in the settings.. Thanks for the suggestion, I’ll test here and come back later to tell you whether it worked or not.

  • friend, tested and did not work, as I said, doubted this possibility, because if an API of a large payment method fails in relation to https sites to the point of taking a feature like redirection.. Anyway, thanks for the suggestion!!

  • By my experience even large companies sin a lot in API documentation. Imagine then on this rs. Well, you disabled SSL, the proposal was to change all links and statics files to HTTPS (yes, this problem sometimes, so many scripts test if it is with SSL enabled to add "S" to http when including JS or CSS). Have you tried that too? (Unsure the way is to try)

  • Raul, grateful for the help and knowledge, this time did not work, but it is something that can happen in the future and I now have one more option how I can solve, thank you!

Browser other questions tagged

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