For a long time I've been having a problem with PagSeguro which is giving me a lot of headaches.
I am making a transparent subscription to PagSeguro, and in the last step, I need to join the previously created plan. Anyway, I need to pass an XML per POST to a URL of them and receive a JSON. The problem is exactly there, because I'm setting up my XML, apparently all right, I do the POST in the same way as it is in several places suggested by PagSeguro, but I always get the error 405.
Has anyone ever had this problem and can you help me?
It follows both the XML generated in PHP and the code in which I do the entire POST operation.
XML:
<?xml version="1.0"?>
<directPreApproval>
<plan>VALOR AQUI</plan>
<reference>VALOR AQUI</reference>
<sender>
<name>VALOR AQUI</name>
<email>VALOR AQUI</email>
<hash>VALOR AQUI</hash>
<phone>
<areaCode>35</areaCode>
<number>988029321</number>
</phone>
<address>
<street>VALOR AQUI</street>
<number>VALOR AQUI</number>
<complement>VALOR AQUI</complement>
<district>VALOR AQUI</district>
<city>VALOR AQUI</city>
<state>VALOR AQUI</state>
<country>VALOR AQUI</country>
<postalCode>VALOR AQUI</postalCode>
</address>
<documents>
<document>
<type>VALOR AQUI</type>
<value>VALOR AQUI</value>
</document>
</documents>
</sender>
<paymentMethod>
<type>VALOR AQUI</type>
<creditCard>
<token>VALOR AQUI</token>
<holder>
<name>VALOR AQUI</name>
<birthDate>VALOR AQUI</birthDate>
<document>
<type>VALOR AQUI</type>
<value>VALOR AQUI</value>
</document>
<phone>
<areaCode>VALOR AQUI</areaCode>
<number>VALOR AQUI</number>
</phone>
<address>
<street>VALOR AQUI</street>
<number>VALOR AQUI</number>
<complement>VALOR AQUI</complement>
<district>VALOR AQUI</district>
<city>VALOR AQUI</city>
<state>VALOR AQUI</state>
<country>VALOR AQUI</country>
<postalCode>VALOR AQUI</postalCode>
</address>
</holder>
</creditCard>
</paymentMethod>
<directPreApproval>
PHP:
$xml = "TODO O XML QUE COLOQUEI ACIMA";
$xml = str_replace("\n", '', $xml);
$xml = str_replace("\r",'',$xml);
$xml = str_replace("\t",'',$xml);
print_r($xml."\n\n");
$curl = curl_init($this->url_adesao."?email=".$this->email."&token=".$this->token);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array('Content-Type: application/xml;charset=ISO-8859-1','Accept: application/vnd.pagseguro.com.br.v3+xml;charset=ISO-8859-1'));
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
$xml= curl_exec($curl);
if($xml == 'Unauthorized'){
// header('Location: paginaDeErro.php');
echo 'Unauthorized';
exit;
}
curl_close($curl);
print_r($xml);
$xml = simplexml_load_string($xml);
if(count($xml->error) > 0)
{
print_r($xml->error).'<br>';
exit;
}
return $xml;