How to check the installment fee in the Pagseguro query API?

0

I integrated the pagseguro into my virtual store. I use a transaction-by-code query API to get details of the transaction / purchase that was made at the store:

link

The payload returns an xml with the information, so I save the information in a variable ($ transactions).

An example of the query response is here: link

I try to check the installment fee ($ transactions-> installmentFeeAmount) but the xml does not return anything, probably because the field is as optional on the pagseguro site, I would like to know how to enable this parameter. >

follow the code:

<?php

header("access-control-allow-origin: https://sandbox.pagseguro.uol.com.br");

$email = 'douglas...';
$token = '4360...';

$codigotransicao = $_GET['pagamento'];
$url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/'. $codigotransicao .'?email=' .$email. '&token=' .$token;

// Errado $url = 'https://ws.sandbox.pagseguro.uol.com.br/v2/transactions/notifications/' . $_POST['notificationCode'] . '?email=' . $email . '&token=' . $token;

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$transaction= curl_exec($curl);
curl_close($curl);

if($transaction == 'Unauthorized'){
    //Insira seu código avisando que o sistema está com problemas, sugiro enviar um e-mail avisando para alguém fazer a manutenção
    $name = 'log.txt';
    $text = " A transação não foi validada!" . "\r\n";
    $file = fopen($name, 'a+');
    fwrite($file, $text);
    fclose($file);
    exit;//Mantenha essa linha
}
$transaction = simplexml_load_string($transaction);

if($transaction->code > 0) {
$TransacaoID = $transaction->code;
$CompradorID = $transaction->reference;        
    $mpresult = $transaction->paymentMethod->type;
    if($mpresult == 1){ 
        $MetodoPagamento = "Cartão de crédito";
    } elseif($mpresult == 2){ 
        $MetodoPagamento = "Boleto";
    } elseif($mpresult == 3){ 
        $MetodoPagamento = "Débito online (TEF)"; 
    } else { 
        $MetodoPagamento = "Outro"; 
    }
    $nParcelas = $transaction->installmentCount;
    $TaxaPacelas = $transaction->installmentFeeAmount;
    $DataTransacao = date('d/m/Y', strtotime($transaction->date));
    if($transaction->status == 1){
        $transactionStatus = 'Aguardando pagamento';
    } elseif($transaction->status == 2){
        $transactionStatus = 'Em análise';
    } elseif($transaction->status == 3){ // :)
        $transactionStatus = 'Paga';
    } elseif($transaction->status == 4){ // :D
        $transactionStatus = 'Disponível';
    } elseif($transaction->status == 5){
        $transactionStatus = 'Em disputa';
    } elseif($transaction->status == 6){
        $transactionStatus = 'Devolvida';
    } elseif($transaction->status == 7){
        $transactionStatus = 'Cancelada';
    }   
    $CliNome = $transaction->sender->name;

    $sql = mysql_query("INSERT INTO pedidos (TransacaoID,CompradorID,MetodoPagamento,nParcelas,TaxaParcelas,StatusTransacao,CliNome) VALUES ('".$TransacaoID."', '".$CompradorID."', '".$MetodoPagamento."', '".$nParcelas."', '".$TaxaParcelas."', '".$transactionStatus."', '".$CliNome."')") or die(mysql_error());
?>
    
asked by anonymous 03.03.2016 / 16:32

1 answer

1

Because you are using version 2, this parameter is only available in version 3.

See the answers available in version two: link

    
04.03.2016 / 15:52