Well, I need to generate a subscription via the pagseguro API, the user should be redirected to the pagseguro page and when I return to my page, this should be via API.
I've 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);
You are returning me:
Array ( [error] => Array ( [code] => 11101 [message] => preApproval data is required. ) )
What's up?