Pagseguro does not redirect client after payment

5

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

I've got an API, I just needed to set up 2 files, they are: PaymentPagseguro.php and PagSeguroConfig.php .

The client pays, I get paid, everything is ok, the problem is that it is not directed to the page that I set up in this file PaymentPagseguro.php , exactly in this piece of code:

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

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

But look at the errors that occur on the console:

  • When opening the page:

      

    (2) Blocked loading of active content merged   " link "

    This should occur because my site is https, but I do not think it's the problem ..

  • When I fill in my email and click on forward:

      

    GET    link     403 Forbidden 60ms

         

    GET    link     403 Forbidden 42ms

  • When I finish the payment and click close

      

    TypeError: this.callback is undefined   ...

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

        
    asked by anonymous 30.03.2015 / 02:22

    3 answers

    5

    I think you're using v2 , like you did not inform how it was configured, I will only assume the answer according 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 he will not have to inform them again.

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

    Defining the currency to be used for payment.

    $paymentRequest->setCurrency("BRL"); 
    

    Defining additional information that may be used by your system after the payment flow in PagSeguro, I believe the problem may 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 in the checkout request parameters / information 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 requisition 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 PayPal.

    The way to perform buyer redirection to effect payment in PagSeguro after returning 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 $checkoutUrl , 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 PagSeguroConfig::getAccountCredentials does not work, then there is probably something wrong with the PagSeguroConfig.php data, 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 in PagSeguroConfig::getAccountCredentials , as described in the examples, like this:

    $credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
    

    Some of the other problems (error 403) that occur can be due to the lack of the token of the paysurance file, configure the file and preferably add the actual path to a log file.

    Start the configuration normally in 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 fixed, you need the% of production token and appId :

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

    Set the log to get details, it may help to find the problem set appKey to true and the actual path of a file to $PagSeguroConfig['log']['active'] = true; , for example:

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

    Should be something like:

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

    The error $PagSeguroConfig['log']['fileLocation'] may have occurred because of TypeError: this.callback is undefined , but I'm not sure exactly where this issue occurs (whether it's on your site or when you're already on the pay-

    To download the API for PHP, go to:

    link

      

    Tip: After downloading the source / examples folder, all examples needed for integration via PHP,

        
    05.04.2015 / 04:04
    5

    Follow the steps to deal with the issue:

  • Access the control panel of PagSeguro.

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

  • Enter the URL in the "Define redirect page:" field and click "Activate."

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

  • In the left menu option, Integrations, Automatic Data Retrieval, enter the URL in the "Set URL to receive notifications:" field and click "Activate."

    Are you using the new API?

        
  • 01.04.2015 / 16:08
    1

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

    In your question you mentioned:

      

    This should occur because my site is https, but I do not think it's the problem ..

    In this link you can see the original conversation.

    Here is the answer:

      

    I am happy to use it for 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 join their forum

        
    01.04.2015 / 22:59