ciao a tutti
sto facendo dei test con la sandbox,
funziona tutto a meraviglia, cioè mi manda l'email se lo stato è VERIFIED o INVALID,
solo che nel sito di paypal, nella cronologia ipn mi dice sempre tentativo in corso, e quindi mi invia molte email(tanti quanti sono i tentativi che fa)
e come se non scrivesse nel file di paypal che mi ha inviato la richiesta.....
Codice PHP:
{
if ($request->getMethod() == 'POST') {
$req = "cmd=_notify-validate";
foreach($request->request->all() as $key => $value ) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
/**
* Modificando la costante SIMULATION nel file di configurazione
* è possibile passare dall'ambiente di simulazione a quello di produzione
*/
$url = "www.sandbox.paypal.com";
$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Host: $url:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
if( $fp == false ) {
// HTTP ERROR
// $errstr - $errno
$messaggio = \Swift_Message::newInstance()
->setSubject('errore')
->setFrom('mittente@example.com')
->setTo('email@hotmail.it')
->setBody($this->renderView('AcmeProductBundle:Default:error.html.twig',array(
"error1"=>$errstr,
"error2"=>$errno)))
;
$this->get('mailer')->send($messaggio);
return false;
} else {
fputs($fp, $header . $req);
//////PENSO CHE L'ERRORE SIA QUI.....MA COSA CÈ DI SBAGLIATO?
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if( strcmp($res, "VERIFIED") == 0 ) {
$messaggio = \Swift_Message::newInstance()
->setSubject('VERIFIED')
->setFrom('mittente@example.com')
->setTo('email@hotmail.it')
->setBody($this->renderView('AcmeProductBundle:Default:test.html.twig'))
;
$this->get('mailer')->send($messaggio);
fclose ($fp);
return true;
} elseif( strcmp ($res, "INVALID") == 0 ) {
$messaggio = \Swift_Message::newInstance()
->setSubject('INVALID')
->setFrom('mittente@example.com')
->setTo('email@hotmail.it')
->setBody($this->renderView('AcmeProductBundle:Default:test.html.twig'))
;
$this->get('mailer')->send($messaggio);
fclose($fp);
return false;
}
}
}
help grazie