Hi Tuan,
I have an update for you.
I finally asked the people that use the software if we could go ahead and buy it again so we could have access to the newest version for Joomla 1.5.
On Monday I performed the upgrade and did a bit of comparison with the PayPal plugin (it seemed like it had a few differences that might improve the situation) but then today (Thursday) the person that uses the software mentioned she hadn't received 2 out of the last 3 confirmation emails she should have received.
So I started doing some digging and figured out a few things.
One, the PayPal plugin refers to a ipn_logs.txt file which didn't exist so I created it manually and gave it the proper permissions.
A few minutes later someone had registered and the log was updated and the main thing I noticed was that it had timed out:
Code:
IPN Response from Paypal Server:
HTTP/1.0 408 Request Time-out
Server: AkamaiGHost
Mime-Version: 1.0
Date: Thu, 11 Jul 2013 18:45:22 GMT
Content-Type: text/html
Content-Length: 218
Expires: Thu, 11 Jul 2013 18:45:22 GMT
<HTML><HEAD>
<TITLE>Request Timeout</TITLE>
</HEAD><BODY>
<H1>Request Timeout</H1>
The server timed out while waiting for the browser's request.<P>
Reference #2.9d9b1160.1373568322.0
</BODY></HTML>
So it would appear that sometimes the code returns the correct response and sometimes it just hangs and times out like in the example above (which would explain why sometimes we'll get the confirmations and sometimes we won't).
I did some research and came across this StackOverflow article:
stackoverflow.com/questions/8314064/payp...-with-feof-and-fgets
Which mentioned using stream_get_contents instead of the feof/fgets way currently being used.
That sort of worked, but the code on the above page needed a slight modification (the response from PayPal is longer than 1024 bytes so I needed to take out that parameter so the full response would get returned).
The other thing I changed was the use of the eregi function to JString::strpos instead.
After making these changes the timeouts seem to have gone away and the validation is successful and the confirmation emails get sent out.
Here's the modified _validate method:
Code:
function _validate() {
$errNum="";
$errStr="";
$urlParsed = parse_url($this->_url);
$host = $urlParsed['host'];
$path = $urlParsed['path'];
$postString = '';
$response = '';
foreach ($_POST as $key=>$value) {
$this->_data[$key] = $value;
$postString .= $key.'='.urlencode(stripslashes($value)).'&';
}
$postString .='cmd=_notify-validate';
$fp = fsockopen($host , '80', $errNum, $errStr, 30);
if(!$fp) {
return false;
} else {
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ".strlen($postString)."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $postString . "\r\n\r\n");
// Gets the entire response:
$response = stream_get_contents($fp, -1);
//while(!feof($fp)) {
//$response .= fgets($fp, 1024);
//}
fclose($fp);
}
$this->ipn_response = $response ;
$this->log_ipn_results(true);
if ($this->_mode) {
if ((JString::strpos($response, 'VERIFIED') !== false) && ($this->_data['payment_status'] == 'Completed'))
return true;
else
return false;
} else {
return true ; //Always return true on testing to avoid bug from Paypal
/*if ($this->_data['payment_status'] == 'Completed')
return true ;
else
return false ;
*/
}
}
I'll keep on monitoring to make sure it's a true fix, but it did seem to have an immediate effect so I'm hoping this will resolve the issue for us.