Get the url of the Paypal payment slip

Asked

Viewed 162 times

0

I have a problem to pick up the Paypal ticket and open in a new browser tab. When I send the data and choose boleto the transaction is executed normally but I’m not able to pick up the return to display the boleto pro client. In Javascript I did so:

}else if(form_pg === 'BOLETO'){               
            $.ajax({
                type:'POST',
                url: 'routers/boleto.php',
                data:{sHash:sHash,
                    name:name,
                    email:email,
                    ddd:ddd,
                    telephone:telephone,
                    form_pg:form_pg,
                    cep:cep,
                    street:street,
                    numberHouse:numberHouse,
                    complement:complement,
                    neighbordhood:neighborhood,
                    city:city,
                    state:state,
                    cpf:cpfBoletoBalance,                                                            
                    valor:valor
                },
                 dataType:'json',
                 success:function(response){  
                    if(response.error == true){
                        alert('Ocorreu um erro: ' + response.msg);
                    }else{
                        alert('Pagamento efetuado com sucesso, um email foi enviado pra você com os dados do boleto. Obrigado pela compra.');                          
                    }
                }
            });  

In PHP that receives Ajax:

session_start();
require_once '../vendor/autoload.php';

PagSeguro\Library::initialize();    
PagSeguro\Library::cmsVersion()->setName("XXXXXXXXXXX")->setRelease("1.0.0");
PagSeguro\Library::moduleVersion()->setName("XXXXXXXXX")->setRelease("1.0.0");
PagSeguro\Configuration\Configure::setEnvironment("production");
PagSeguro\Configuration\Configure::setAccountCredentials("email.com", "XXXXXXXXXXXXXXX");
PagSeguro\Configuration\Configure::setCharset("UTF-8");
PagSeguro\Configuration\Configure::setLog(true, "pagseguro.log");

$sHash = addslashes($_POST["sHash"]);
$nome = addslashes($_POST["name"]);
$email = addslashes($_POST["email"]);
$ddd = addslashes($_POST["ddd"]);
$telefone = str_replace('-', '', $_POST["telephone"]);
$forma_pagamento = addslashes($_POST["form_pg"]);
$cep = str_replace('-', '', $_POST["cep"]);
$rua = addslashes($_POST["street"]);
$numero = addslashes($_POST["numberHouse"]);
$complemento = addslashes($_POST["complement"]);
$bairro = addslashes($_POST["neighbordhood"]);
$cidade = addslashes($_POST["city"]);
$estado = addslashes($_POST["state"]);
$cpf_msk = str_replace('.', '', $_POST["cpf"]);
$cpf = str_replace('-', '', $cpf_msk);
$valor = addslashes($_POST["valor"]);


$boleto = new \PagSeguro\Domains\Requests\DirectPayment\Boleto();
$boleto->setReceiverEmail('[email protected]');
$boleto->setReference($_SESSION['user_dm']); 
$boleto->setCurrency('BRL');



$boleto->addItems()->withParameters(
    $_SESSION['user_dm'],//identificador do produto
    "Conta Premium", //Nome do produto
    intval(1), // Quantidade
    floatval($valor)
);

//Comprador
$boleto->setSender()->setName($nome);
$boleto->setSender()->setEmail($email);
$boleto->setSender()->setDocument()->withParameters('CPF', $cpf);
$boleto->setSender()->setPhone()->withParameters(
    $ddd,
    $telefone
);

//Send Hash e IP
$boleto->setSender()->setHash($sHash);
$boleto->setSender()->setIp($_SERVER['REMOTE_ADDR']);

$boleto->setShipping()->setAddressRequired()->withParameters('FALSE');

$boleto->setMode('DEFAULT');

//Registrar o pagamento e recebe a resposta do pagseguro
    try{
        $resposta = $boleto->register(\PagSeguro\Configuration\Configure::getAccountCredentials());              
        echo $boleto->getLink() //Já tentei de tudo pra pegar o link;      
         exit();
    } catch (Exception $ex) {
        echo json_encode(array('error' => true, 'msg' => $ex->getMessage()));
        exit();
    }

When I make the payment by boleto and go in the log file of pagseguro the boleto link is there. Thanks

  • What’s in the answer? Take a look at the content of $resposta

  • $responsta->paymentLink

  • Jrd thanks for answering, I already gave a var_dump in $reply and there is nothing an empty array.

  • Wees thank you for answering, I have tried this way, inclusive é o que vem no xml de resposta do pagseguro mas da um erro informando que paymentLink não é reconhecido. Pagseguro has the documentation I have seen. I need to work urgently

  • Problem solved, both the boleto url and notification were being captured by the log file that was enabled, so the return was empty. To resolve just turn off the log.

No answers

Browser other questions tagged

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