Integrate with PayU - How to read data individually

0

Hello

I'm integrating with an online payment resource called PayU. I am not able to read the return data individually. The code I'm using:

$url = "https://sandbox.api.payulatam.com/payments-api/4.0/service.cgi";    

  if(!function_exists('curl_init')) {
    die('cURL not available!');
  }  

  $dados = array(
        "language" => "es",
        "command" => "SUBMIT_TRANSACTION",

            "merchant" => array(
                "apiKey" => "4Vj8eK4rloUd272L48hsrarnUA",
                "apiLogin" => "pRRXKOl8ikMmt9u",
            ),

        "transaction" => array(
            "order" => array(

                "accountId"=> "512327",
                 "referenceCode"=> "payment_test_00000001",
                 "description"=> "payment test",
                 "language"=> "es",
                 "signature"=> "31eba6f397a435409f57bc16b5df54c3",
                 "notifyUrl"=> "http=>//www.tes.com/confirmation",

                   "additionalValues"=>array(
                        "TX_VALUE"=>array(  

                            "value"=> 100,
                            "currency"=> "BRL"

                        )//end array TX_VALUE
                    ),//end array additionalValues

                    "buyer"=>array(
                        "fullName"=> "First name and second buyer  name",
                        "emailAddress"=> "[email protected]",
                        "dniNumber"=> "811.807.405-64",
                        "cnpj"=> "24.481.827",

                        "shippingAddress"=>array(
                           "street1"=> "calle 100",
                           "street2"=> "5555487",
                           "city"=> "Sao paulo",
                           "state"=> "SP",
                           "country"=> "BR",
                           "postalCode"=> "01019-030"
                        )//end array shippingAddress

                    )//end array buyer

            ),//end array order     

              "type"=> "AUTHORIZATION_AND_CAPTURE",
              "paymentMethod"=> "BOLETO_BANCARIO",
              "paymentCountry"=> "BR",
              "expirationDate"=> "2018-12-28T00:00:00",
              "ipAddress"=> "127.0.0.1" 

        ),//end array transaction

        "test"=>false

  );//end array principal

  //var_dump($dados);

  /*
  foreach($dados as $d_show) {
    echo $d_show, '<br>';
  }
  */

  $json = json_encode($dados);


    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);   
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                                                       
        //'Authorization: xxzY789jKlPwWwW',                                                         
        //'Accept: application/json',                                       
        'Content-Type: application/json',                                                               
    )); 

    $output = curl_exec($curl);

        if ($output === FALSE) {
            echo 'An error has occurred: ' . curl_error($curl) . PHP_EOL;
        }
        else {

            echo $output;                                               

            echo "<br>";

            $retorno = json_decode($output, true);                                  

            //$code = $retorno->code;
            //$orderId = $retorno->orderId;

            $URL_BOLETO_BANCARIO = $retorno->URL_BOLETO_BANCARIO;

            /*
            echo "code: ".$code[0];
            echo "\n";
            echo "orderId: ".$orderId[0];
            */

            echo "URL_BOLETO_BANCARIO: ".$URL_BOLETO_BANCARIO[2];

        }

With the code above, I can send the data via json / php / cURL to the PayU url.

With this section, I can read the return data cluster via jSon:

$output = curl_exec($curl);
echo $output;

appears like this on the screen:

SUCCESS844619692f570a54f-a499-405b-b1d5-21b72f00831fPENDINGAWAITING_NOTIFICATIONPENDING_TRANSACTION_CONFIRMATIONEXPIRATION_DATE2018-12-27T19:00:00URL_PAYMENT_RECEIPT_PDFhttps://sandbox.checkout.payulatam.com/ppp-web-gateway-payu/boletoReceipt/pdf/vid/844619692Yf570a54fa499405Ya97caf8259aecd7.pdfBAR_CODE34191.11129 56160.131118 11111.160005 8 77510000010000URL_PAYMENT_RECEIPT_HTMLhttps://sandbox.checkout.payulatam.com/ppp-web-gateway-payu/blv?vid=844619692Yf570a54fa499405Ya97caf8259aecd7URL_BOLETO_BANCARIOhttps://sandbox.checkout.payulatam.com/ppp-web-gateway-payu/blv?vid=844619692Yf570a54fa499405Ya97caf8259aecd7

Now the problem is that you can read this data individually. For example, read only the link that generates the ticket, URL_BOLETO_BANCARIO. I'm trying like this (excerpt present in the code above):

$retorno = json_decode($output, true);                                  
$URL_BOLETO_BANCARIO = $retorno->URL_BOLETO_BANCARIO;
echo "URL_BOLETO_BANCARIO: ".$URL_BOLETO_BANCARIO[2];

... this way it did not work, this message appears on the screen:

Notice: Trying to get property 'URL_BOLETO_BANCARIO' of non-object in C:\xampp\htdocs\

Does anyone know how to solve it?

    
asked by anonymous 29.08.2018 / 19:50

1 answer

1

Turn around and see if it works.

I removed the comment from

'//'Accept: application/json' 

Why was it returning in XML format, and I checked that the return data is in array format and not object

You can check all the data by giving a print_r in 'return' just below this section:

$retorno = json_decode($output, true);  

If you can not please let me know so I can check with you.

<?php

$url = "https://sandbox.api.payulatam.com/payments-api/4.0/service.cgi";    

  if(!function_exists('curl_init')) {
    die('cURL not available!');
  }  

  $dados = array(
        "language" => "es",
        "command" => "SUBMIT_TRANSACTION",

            "merchant" => array(
                "apiKey" => "4Vj8eK4rloUd272L48hsrarnUA",
                "apiLogin" => "pRRXKOl8ikMmt9u",
            ),

        "transaction" => array(
            "order" => array(

                "accountId"=> "512327",
                 "referenceCode"=> "payment_test_00000001",
                 "description"=> "payment test",
                 "language"=> "es",
                 "signature"=> "31eba6f397a435409f57bc16b5df54c3",
                 "notifyUrl"=> "http=>//www.tes.com/confirmation",

                   "additionalValues"=>array(
                        "TX_VALUE"=>array(  

                            "value"=> 100,
                            "currency"=> "BRL"

                        )//end array TX_VALUE
                    ),//end array additionalValues

                    "buyer"=>array(
                        "fullName"=> "First name and second buyer  name",
                        "emailAddress"=> "[email protected]",
                        "dniNumber"=> "811.807.405-64",
                        "cnpj"=> "24.481.827",

                        "shippingAddress"=>array(
                           "street1"=> "calle 100",
                           "street2"=> "5555487",
                           "city"=> "Sao paulo",
                           "state"=> "SP",
                           "country"=> "BR",
                           "postalCode"=> "01019-030"
                        )//end array shippingAddress

                    )//end array buyer

            ),//end array order     

              "type"=> "AUTHORIZATION_AND_CAPTURE",
              "paymentMethod"=> "BOLETO_BANCARIO",
              "paymentCountry"=> "BR",
              "expirationDate"=> "2018-12-28T00:00:00",
              "ipAddress"=> "127.0.0.1" 

        ),//end array transaction

        "test"=>false

  );//end array principal

  //var_dump($dados);

  /*
  foreach($dados as $d_show) {
    echo $d_show, '<br>';
  }
  */

  $json = json_encode($dados);


    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_FAILONERROR, false);
    curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($curl, CURLOPT_POST, true); 
    curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);   
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(                                                                                                       
        //'Authorization: xxzY789jKlPwWwW',                                                         
        'Accept: application/json',                                       
        'Content-Type: application/json',                                                               
    )); 

    $output = curl_exec($curl);

        if ($output === FALSE) {
            echo 'An error has occurred: ' . curl_error($curl) . PHP_EOL;
        }
        else {

            //echo $output;                                               

            echo "<br>";

            $retorno = json_decode($output, true);                                  

            //$code = $retorno->code;
            //$orderId = $retorno->orderId;

            //$URL_BOLETO_BANCARIO = $retorno->URL_BOLETO_BANCARIO;
            $URL_BOLETO_BANCARIO = $retorno['transactionResponse']['extraParameters']['URL_BOLETO_BANCARIO'];

            /*
            echo "code: ".$code[0];
            echo "\n";
            echo "orderId: ".$orderId[0];
            */

            echo "URL_BOLETO_BANCARIO: ".$URL_BOLETO_BANCARIO;

        }
    
29.08.2018 / 20:43