Consultation of Secured Transaction

Asked

Viewed 1,207 times

1

Opa

I am generating the payment via pagseguro and storing your transaction code for later consultation. In the transaction query, by the transaction code I am doing so:

$email_pagseguro = '[email protected]';
$token_pagseguro = '****************************';
$url = 'https://ws.pagseguro.uol.com.br/v2/transactions/'.$tabela_itens['usuario_checkout_transactionCode'].'?email='.$email_pagseguro.'&token='.$token_pagseguro;

$_h = curl_init();
//curl_setopt($_h, CURLOPT_HEADER, 1);

curl_setopt($_h, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($_h, CURLOPT_HTTPGET, 1);
curl_setopt($_h, CURLOPT_URL, $url );
curl_setopt($_h, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($_h, CURLOPT_SSL_VERIFYHOST,  2);
curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 );
$output = curl_exec($_h);

var_dump($output);
//$transaction = simplexml_load_string($output);

var_dump is returning a text with all the transaction data, a string, where I believe an xml should be returned.

Doc for this query

  • Put the comeback.

  • what is this text that is returning? wouldn’t be xml?

  • Solved it, added the curl_setopt($_h, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml; charset=ISO-8859-1"));

  • The return was being a string

2 answers

0


Solution for Code Transaction Query.

$email_pagseguro = '[email protected]';
$token_pagseguro = '*******************';
$url = 'https://ws.pagseguro.uol.com.br/v2/transactions/'.$tabela_itens['usuario_transactionCode'].'?email='.$email_pagseguro.'&token='.$token_pagseguro;

$_h = curl_init();
curl_setopt($_h, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml; charset=ISO-8859-1"));

curl_setopt($_h, CURLOPT_RETURNTRANSFER, true);
curl_setopt($_h, CURLOPT_HTTPGET, 1);
curl_setopt($_h, CURLOPT_URL, $url );
curl_setopt($_h, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($_h, CURLOPT_SSL_VERIFYHOST,  2);
curl_setopt($_h, CURLOPT_DNS_USE_GLOBAL_CACHE, false );
curl_setopt($_h, CURLOPT_DNS_CACHE_TIMEOUT, 2 );
$output = curl_exec($_h);

//var_dump($output);
    $transaction = simplexml_load_string($output);

    $status_compra = $transaction -> status;

    echo '<br><br><Br>'.$status_compra;

0

The text you are receiving is nothing more than the XML return. To work with you PHP, you must effect the parse with simplexml_load_string:

<?php

$xml = <<<XML
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?>  
<checkout>  
    <currency>BRL</currency>  
    <items>  
        <item>  
            <id>0001</id>  
            <description>Notebook Prata</description>  
            <amount>24300.00</amount>  
            <quantity>1</quantity>  
            <weight>1000</weight>  
        </item>  
        <item>  
            <id>0002</id>  
            <description>Notebook Rosa</description>  
            <amount>25600.00</amount>  
            <quantity>2</quantity>  
            <weight>750</weight>  
        </item>  
    </items>  
    <reference>REF1234</reference>  
    <sender>  
        <name>José Comprador</name>  
        <email>[email protected]</email>  
        <phone>  
            <areacode>11</areacode>  
            <number>56273440</number>  
        </phone>  
    </sender>  
    <shipping>  
        <type>1</type>  
        <address>  
            <street>Av. Brig. Faria Lima</street>  
            <number>1384</number>  
            <complement>5o andar</complement>  
            <district>Jardim Paulistano</district>  
            <postalcode>01452002</postalcode>  
            <city>Sao Paulo</city>  
            <state>SP</state>  
            <country>BRA</country>  
        </address>  
    </shipping>  
</checkout>  
XML;

$xmlObject = simplexml_load_string($xml);

var_dump($xmlObject);

Will return:

object(SimpleXMLElement)#1 (5) {
  ["currency"]=>
  string(3) "BRL"
  ["items"]=>
  object(SimpleXMLElement)#2 (1) {
    ["item"]=>
    array(2) {
      [0]=>
      object(SimpleXMLElement)#5 (5) {
        ["id"]=>
        string(4) "0001"
        ["description"]=>
        string(14) "Notebook Prata"
        ["amount"]=>
        string(8) "24300.00"
        ["quantity"]=>
        string(1) "1"
        ["weight"]=>
        string(4) "1000"
      }
      [1]=>
      object(SimpleXMLElement)#6 (5) {
        ["id"]=>
        string(4) "0002"
        ["description"]=>
        string(13) "Notebook Rosa"
        ["amount"]=>
        string(8) "25600.00"
        ["quantity"]=>
        string(1) "2"
        ["weight"]=>
        string(3) "750"
      }
    }
  }
  ["reference"]=>
  string(7) "REF1234"
  ["sender"]=>
  object(SimpleXMLElement)#3 (3) {
    ["name"]=>
    string(17) "José Comprador"
    ["email"]=>
    string(20) "[email protected]"
    ["phone"]=>
    object(SimpleXMLElement)#6 (2) {
      ["areacode"]=>
      string(2) "11"
      ["number"]=>
      string(8) "56273440"
    }
  }
  ["shipping"]=>
  object(SimpleXMLElement)#4 (2) {
    ["type"]=>
    string(1) "1"
    ["address"]=>
    object(SimpleXMLElement)#6 (8) {
      ["street"]=>
      string(20) "Av. Brig. Faria Lima"
      ["number"]=>
      string(4) "1384"
      ["complement"]=>
      string(8) "5o andar"
      ["district"]=>
      string(17) "Jardim Paulistano"
      ["postalcode"]=>
      string(8) "01452002"
      ["city"]=>
      string(9) "Sao Paulo"
      ["state"]=>
      string(2) "SP"
      ["country"]=>
      string(3) "BRA"
    }
  }
}

Browser other questions tagged

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