4
Well, I need to generate subscription via pagseguro API, user should be redirected to the pagseguro page and when finished return to my page, this should be via API.
I tried through XML, with the codes:
$url = "https://ws.sandbox.pagseguro.uol.com.br/v2/pre-approvals/[email protected]&token=********************************";
$xml = '<?xml version="1.0" encoding="charset=ISO-8859-1"?>
<preApprovalRequest>
<reviewURL>http://www.site.com.br/dashboard/revisao.php</reviewURL>
<redirectURL>http://www.site.com.br/painel/sucesso.php</redirectURL>
<reference>EVX01</reference>
<sender>
<name>Jose de Solza</name>
<email>[email protected]</email>
<phone>
<areaCode>11</areaCode>
<number>56273440</number>
</phone>
<address>
<street>Avenida Brigadeiro Faria Lima</street>
<number>1384</number>
<complement>1 Andar</complement>
<district>Jardim Paulistano</district>
<postalCode>01452002</postalCode>
<city>São Paulo</city>
<state>SP</state>
<country>BRA</country>
</address>
</sender>
<preApproval>
<charge>auto</charge>
<name>testes Ultimate</name>
<details>
Todos os dias 26 de cada mes
</details>
<amountPerPayment>19.90</amountPerPayment>
<period>Monthly</period>
<finalDate>2018-01-21T00:00:000-03:00</finalDate>
<maxTotalAmount>2500.00</maxTotalAmount>
<date>2016-08-25T20:33:00.sTZD</date>
</preApproval>
</preApprovalRequest>
';
$xml = str_replace("\n", '', $xml);
$xml = str_replace("\r",'',$xml);
$xml = str_replace("\t",'',$xml);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/x-www-form-urlencoded; charset=ISO-8859-1"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
$data = array('entrada' => $xml);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
$resposta = curl_exec($ch)or die(curl_error($ch));
curl_close($ch);
//echo $url;
//exit;
$retorno = simplexml_load_string($resposta);
$xml = json_encode($retorno);
$array = json_decode($xml,TRUE);
print_r($array);
It’s returning to me:
Array ( [error] => Array ( [code] => 11101 [message] => preApproval data is required. ) )
What’s?
You’re running the tags twice, have you tried removing them? <receiver> and <Reference> and <redirectURL> at the end, and at the beginning, vc has already set them.
– Gustavo Tinoco
Are you using HTTPS or HTTP? Is there a firewall on your server?
– Allan Andrade
Opa @Gustavotinoco removed duplicate tags, thanks nor had seen. But, still the error in xml. The connection is HTTP
– sNniffer
I just don’t know. But I remind you that it is necessary to register the redirect in the configuration area of the https://pagseguro.uol.com.br/v2/guia-integracao/finalizaca-payment.html#v2-item-redirecting-the-buyer-to-a-url-fixed
– Andrei Coelho