VirtueMart Forum

VirtueMart 1.1.x [ Old version - no longer supported ] => Payment VM 1.1 => Topic started by: Phenotype on May 06, 2013, 11:48:19 am

Title: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: Phenotype on May 06, 2013, 11:48:19 am
Regarding this topic: https://forum.virtuemart.net/index.php?topic=113426.0

Has anyone implemented a fix for this?  If so, it would be great if you could share the changes that had to be made.
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: abcisme on August 07, 2013, 22:31:25 pm
I believe I figured this out.  In administrator/components/com_virtuemart/notify.php make the following changes:

Change:
Code: [Select]
Line 32: header("HTTP/1.0 200 OK");
To:
Code: [Select]
Line 32: header("HTTP/1.1 200 OK");


Change:
Code: [Select]
$header = "POST $uri HTTP/1.0\r\n";
$header.= "User-Agent: PHP/".phpversion()."\r\n";
$header.= "Referer: ".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']."\r\n";
$header.= "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n";
$header.= "Host: ".$hostname.":80\r\n";
$header.= "Content-Type: application/x-www-form-urlencoded\r\n";
$header.= "Content-Length: ".strlen($workstring)."\r\n";
$header.= "Accept: */*\r\n\r\n";

To:
Code: [Select]
    $header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header.= "User-Agent: PHP/".phpversion()."\r\n";
    $header.= "Referer: ".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']."\r\n";
    $header.= "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n";
    $header.= "Host: www.paypal.com\r\n";
    $header.= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header.= "Content-Length: " . strlen($req) . "\r\n";
// $header.= "Accept: */*\r\n\r\n";
    $header .= "Connection: close\r\n\r\n";


Change:
Code: [Select]
$fp = fsockopen ( $hostname, 80, $errno, $errstr, 30);
To:
Code: [Select]
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);


Change:
Code: [Select]
if (eregi ( "VERIFIED", $res) || @PAYPAL_VERIFIED_ONLY == '0' ) {
To:
Code: [Select]
if (eregi ( "VERIFIED", trim($res)) || @PAYPAL_VERIFIED_ONLY == '0' ) {


Change:
Code: [Select]
elseif (eregi ("INVALID", $res)) {
To:
Code: [Select]
elseif (eregi ("INVALID", trim($res))) {
My test transaction worked... so I'm hoping it's all set.  If anyone can see anything wrong, please let me know.
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: dbzeroone on August 12, 2013, 18:12:03 pm
I just tried making the code changes above and I'm still having the same issue.

Transactions are processing fine... customer's cards are being charged appropriately, but their order is NOT changing to confirmed in VM Orders.

This is a problem because I'm selling digital downloads and if their payment doesn't change to "Confirmed", they don't get the download link.

Does anyone have any suggestions? I'll try anything at this point!!

PHP 5.3.13
Joomla 1.5.26
Virtuemart 1.1.19
PayPal Website Payment Pro

Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: abcisme on August 13, 2013, 15:14:25 pm
Have you tried this?  http://www.b-planet.com/VirtueMart/paypal-patch.html
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: ssbuchan on August 28, 2013, 20:26:24 pm
dbzeroone,

I just replied to another post you made a comment on regarding this issue.  Below is that same reply with a bit more information regarding the HTTP/1.1 headers.

I had this same issue and just resolved it today.  I'm using Hostgator for my hosting and the problem for me was on their end.  They recently made some changes to their system which resulted in Paypal being blocked by a firewall. I started getting 406 error codes returned to Paypal which are logged in the IPN History section in my Paypal account.  The solution was for Hostgator to whitelist my domain so that Paypal could once again communicate with virtuemart and get through the firewall.

Not sure if this will resolve your issue or for anyone else, but I thought it would be worth sharing just in case.


As for the header info:

I basically implemented the same changes that abcisme suggested.  The only difference that I have is the following:

I changed:
Code: [Select]
$header = "POST $uri HTTP/1.0\r\n";
$header.= "User-Agent: PHP/".phpversion()."\r\n";
$header.= "Referer: ".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].@$_SERVER['QUERY_STRING']."\r\n";
$header.= "Server: ".$_SERVER['SERVER_SOFTWARE']."\r\n";
$header.= "Host: ".$hostname.":80\r\n";
$header.= "Content-Type: application/x-www-form-urlencoded\r\n";
$header.= "Content-Length: ".strlen($workstring)."\r\n";
$header.= "Accept: */*\r\n\r\n";

to:
Code: [Select]
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "User-Agent: PHP/" . phpversion() . "\r\n";
$header .= "Referer: " . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . @$_SERVER['QUERY_STRING'] . "\r\n";
$header .= "Server: " . $_SERVER['SERVER_SOFTWARE'] . "\r\n";
$header .= "Host: www.paypal.com:443\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($workstring) . "\r\n";
$header .="Connection: close\r\n\r\n";

Besides that, I made every other change exactly as abcisme suggested.  After I made those changes the problem wasn't rectified.  Once I talked to Hostgator that finally resolved everything.  So, I'm not sure if both solutions are necessary, but I can confirm that the changes I made to notify.php DO work.

Hope this helps you get everything resolved!
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: daknoxy on August 29, 2013, 15:27:35 pm
Hi

I am running Virtuemart 1.1.9 but have been unable to fix the issue, I am with hostgator and continue to get 406 errors. I have tried abcisme fix although I don't see the line
if (eregi ( "VERIFIED", $res) || @PAYPAL_VERIFIED_ONLY == '0' ) {
I can only see the line
if (preg_match ( "/VERIFIED/", $res) || @PAYPAL_VERIFIED_ONLY == '0' ) {
in my version to make the change
I have also tried ssbuchan slightly different fix, but again no result.
I have spoken to hostgator who say there are no firewall issues on the server and I am also running a site with virtuemart 2.22 on the same server with no paypal ipn issues.
Can anyone advise the full notify.php file that they have working with 1.1.9?

HELP!
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: AH on August 30, 2013, 17:58:06 pm
I have the following code working on my test site

Here is the notify.php

## mod

New notify.zip in post below 05 sept 2013

Save old notify.php and overwrite with this one.



Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: daknoxy on September 03, 2013, 10:09:26 am
Thanks Hutson, but still getting a 406 response code error on paypal's IPN report with the new file.
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: stinga on September 03, 2013, 20:54:48 pm
I didn't make any change and it still works.
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: AH on September 03, 2013, 22:18:52 pm
I have not tested on live, and will do so this week.  Will post results back here
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: ssbuchan on September 03, 2013, 23:20:02 pm
There's one thing that I didn't mention before b/c I didn't think it was the root of the problem with the 406 error codes.  When I started having problems I logged into my Paypal account and noticed that the IPN settings were wiped out and not enabled anymore.  Actually, this was the case in more than 1 Paypal account that I have.  I know for certain I didn't disable those settings so it appears that Paypal screwed something up on their end.

You might want to double check your IPN settings in Paypal.  I'm not sure if that would have anything to do with receiving 406 error codes though.  I think your IPN stuff would already have to be set up or Paypal wouldn't be trying to send notifications to your site and then receiving error codes.  Again I'm not certain about this.
Title: Works with VM 1.1.3 :)
Post by: Jörgen on September 05, 2013, 08:08:36 am
@hutson
Thanks for the notify.php (post #6). I installed it on my site and it works great  :)
Maybe line #32 should be changed from
Code: [Select]
header("HTTP/1.0 200 OK");to
Code: [Select]
header("HTTP/1.1 200 OK");
@stinga
According to PayPal the old http/1.0 will stop working October 7  ;)

regards

Jörgen @ Kreativ Fotografi
Title: Re: Has anyone implemeneted the Paypal IPN fix?
Post by: AH on September 05, 2013, 10:23:07 am
Jorgen

Thanks for that catch! I clearly was focused on the validate part of the code.

I have updated.

Updated Patch now at end of postings
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: Jörgen on September 05, 2013, 10:33:28 am
You´re welcome ;D

I am grateful for receiving a patch for my current shop. Migrating to 2.0.x is to far away, so I simply have to heed the warning from Paypal in the meantime.

regards

Jörgen @ Kreativ Fotografi
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: AH on September 05, 2013, 19:19:36 pm
I can confirm that this IPN patch is working in a live VM 1.1.9 UK store  8)
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: stinga on September 09, 2013, 16:44:15 pm
Ah, that will be why then!

Must get around to making the change then.
Just had an interesting problem where two order where placed at the same time (probably a double click issue) and ended up with the wrong order being changed from pending to  confirmed.
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: Jörgen on October 12, 2013, 18:09:08 pm
Hello Hutson

I have seen that PayPal has published a new list of IP-adresses to be checked.

I have changed line 224 in the notify.php with the extended list. There are probably some duplicates made by the redundant iplist and iplist1 calls to gethostbyname.

Change  line 224:
Code: [Select]
$paypal_iplist = array_merge( $paypal_iplist, $paypal_iplist2, $paypal_iplist3 );
With:
Code: [Select]
      // Added JH 2013-10-12
//Current IP addresses
//------------api.paypal.com---------
$paypal_iplist_api = array( '173.0.88.66','173.0.88.98','173.0.84.66','173.0.84.98',
'173.0.80.00','173.0.80.01','173.0.80.02','173.0.80.03','173.0.80.04','173.0.80.05','173.0.80.06','173.0.80.07','173.0.80.08','173.0.80.09','173.0.80.10','173.0.80.11','173.0.80.12','173.0.80.13','173.0.80.14','173.0.80.15','173.0.80.16','173.0.80.17','173.0.80.18','173.0.80.19','173.0.80.20');
//------------api-aa.paypal.com------------
$paypal_iplist_api_aa = array( '173.0.88.67','173.0.88.99','173.0.84.99','173.0.84.67');
//'------------api-3t.paypal.com------------'
$paypal_iplist_api_3t_aa = array('173.0.88.69','173.0.88.101','173.0.84.69','173.0.84.101');
//------------api-aa-3t.paypal.com------------
$paypal_iplist_api_aa_3t = array('173.0.88.68','173.0.88.100','173.0.84.68','173.0.84.100');
//------------notify.paypal.com (IPN delivery)------------
$paypal_iplist_notify = array('173.0.81.1','173.0.81.33');
//'-----------reports.paypal.com-----------'
$paypal_iplist_reports = array('66.211.168.93',
'173.0.84.161','173.0.84.198','173.0.88.161','173.0.88.198');
//'------------www.paypal.com------------'
//'Starting September 12, 2012 www.paypal.com will start resolving to a dynamic list of IP addresses and as such should not be whitelisted.'
//'For more information on IPNs please go here.'
//'------------ipnpb.paypal.com------------'
$paypal_iplist_ipnb = array('64.4.240.0','64.4.240.1','64.4.240.2','64.4.240.3','64.4.240.4','64.4.240.5','64.4.240.6','64.4.240.7','64.4.240.8','64.4.240.9','64.4.240.10','64.4.240.11','64.4.240.12','64.4.240.13','64.4.240.14','64.4.240.15','64.4.240.16','64.4.240.17','64.4.240.18','64.4.240.19','64.4.240.20',
'118.214.15.186','118.215.103.186','118.215.119.186','118.215.127.186','118.215.15.186','118.215.151.186','118.215.159.186','118.215.167.186','118.215.199.186','118.215.207.186','118.215.215.186','118.215.231.186','118.215.255.186','118.215.39.186','118.215.63.186','118.215.7.186','118.215.79.186','118.215.87.186','118.215.95.186',
'202.43.63.186',
'69.192.31.186',
'72.247.111.186',
'88.221.43.186',
'92.122.143.186','92.123.151.186','92.123.159.186','92.123.163.186','92.123.167.186','92.123.179.186','92.123.183.186');
// JH

$paypal_iplist = array_merge( $paypal_iplist, $paypal_iplist2, $paypal_iplist3,
// Added JH 2013-10-12
$paypal_iplist_api,
$paypal_iplist_api_aa,
$paypal_iplist_api_3t_aa,
$paypal_iplist_api_aa_3t,
$paypal_iplist_notify,
$paypal_iplist_ipnb
// JH
);

I think this will remedy the fraud reports :)
What Do You think ?

regards

Jörgen @ Kreativ Fotografi

[edit] Added two ' and removed the first line of code (Thank You Hutson)

Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: AH on October 12, 2013, 18:57:43 pm
Jorgen

We were not getting an issue with the gethostbyname1

Your solution could help those that are and I will adopt after I have tested it (although I guess this would need to go into live production for some time before any IP fault might occur.)

For those of you have this issue now, you can replace the code as jorgen suggests with the block below.

However you missed a couple of characters out of the listing that gave me a code error, I have adjusted accordingly

Code: [Select]
        $paypal_iplist3 = array( '216.113.188.202' , '216.113.188.203' , '216.113.188.204' , '66.211.170.66' );
// Added JH 2013-10-12
//Current IP addresses
//------------api.paypal.com---------
$paypal_iplist_api = array( '173.0.88.66','173.0.88.98','173.0.84.66','173.0.84.98',
'173.0.80.00','173.0.80.01','173.0.80.02','173.0.80.03','173.0.80.04','173.0.80.05','173.0.80.06','173.0.80.07','173.0.80.08','173.0.80.09','173.0.80.10','173.0.80.11','173.0.80.12','173.0.80.13','173.0.80.14','173.0.80.15','173.0.80.16','173.0.80.17','173.0.80.18','173.0.80.19','173.0.80.20');
//------------api-aa.paypal.com------------
$paypal_iplist_api_aa = array( '173.0.88.67','173.0.88.99','173.0.84.99','173.0.84.67');
//'------------api-3t.paypal.com------------'
$paypal_iplist_api_3t_aa = array('173.0.88.69','173.0.88.101','173.0.84.69','173.0.84.101');
//------------api-aa-3t.paypal.com------------
$paypal_iplist_api_aa_3t = array('173.0.88.68','173.0.88.100','173.0.84.68','173.0.84.100');
//------------notify.paypal.com (IPN delivery)------------
$paypal_iplist_notify = array('173.0.81.1','173.0.81.33');
//'-----------reports.paypal.com-----------'
$paypal_iplist_reports = array('66.211.168.93','173.0.84.161','173.0.84.198','173.0.88.161','173.0.88.198');
//'------------www.paypal.com------------'
//'Starting September 12, 2012 www.paypal.com will start resolving to a dynamic list of IP addresses and as such should not be whitelisted.'
//'For more information on IPNs please go here.'
//'------------ipnpb.paypal.com------------'
$paypal_iplist_ipnb = array('64.4.240.0','64.4.240.1','64.4.240.2','64.4.240.3','64.4.240.4','64.4.240.5','64.4.240.6','64.4.240.7','64.4.240.8','64.4.240.9','64.4.240.10','64.4.240.11','64.4.240.12','64.4.240.13','64.4.240.14','64.4.240.15','64.4.240.16','64.4.240.17','64.4.240.18','64.4.240.19','64.4.240.20',
    '118.214.15.186','118.215.103.186','118.215.119.186','118.215.127.186','118.215.15.186','118.215.151.186','118.215.159.186','118.215.167.186','118.215.199.186','118.215.207.186','118.215.215.186','118.215.231.186','118.215.255.186','118.215.39.186','118.215.63.186','118.215.7.186','118.215.79.186','118.215.87.186','118.215.95.186',
    '202.43.63.186',
    '69.192.31.186',
    '72.247.111.186',
    '88.221.43.186',
    '92.122.143.186','92.123.151.186','92.123.159.186','92.123.163.186','92.123.167.186','92.123.179.186','92.123.183.186');
// JH

$paypal_iplist = array_merge( $paypal_iplist, $paypal_iplist2, $paypal_iplist3,
// Added JH 2013-10-12
$paypal_iplist_api,
$paypal_iplist_api_aa,
$paypal_iplist_api_3t_aa,
$paypal_iplist_api_aa_3t,
$paypal_iplist_notify,
$paypal_iplist_ipnb
// JH
);




Thanks again for your diligence Jorgen ( I am geting closer to migrating VM1 to VM2 - months not years!)
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: Jörgen on October 12, 2013, 21:34:46 pm
Hello Hutson,

Thanks for finding the typos, I have edited the original piece of code. It should be correct now. The first line doesn´t need to be included in the patch. This line is a duplication. Sorry about that. But it doesn´t cause any error if added to the patch.

I am also on the way of migrating my shop to VM 2. It will soon be what it should have been from the start, an easy task. But for now this extends my VM 1.1.3 until the migration is done  :)

The edited patch has been tested live a couple of minutes ago, seems to work.

regards

Jörgen @ Kreativ Fotografi
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: alatak on October 15, 2013, 08:41:06 am
Hello
Thank you very much for this. I will add the code.
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: AH on October 15, 2013, 10:14:24 am
Patch to include new IP addresses

Tested and working in live by Me and Jorgen

Thanks Jorgen for the update, I am sure many people will benefit from this but will not respond. So a big thanks from them and me!!

[attachment cleanup by admin]
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: chetanmadaan on December 07, 2013, 00:40:26 am
Patch to include new IP addresses

Tested and working in live by Me and Jorgen

Thanks Jorgen for the update, I am sure many people will benefit from this but will not respond. So a big thanks from them and me!!

Thanks, This worked well.
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: Jörgen on December 07, 2013, 10:44:44 am
Hello chetanmadaan

Nice to hear this. As until today i haven't received a single IPN error using this patch.  Glad to be of help. So it seems to have solved the issue.
Regards

Jörgen @ kreativ fotografi
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: baulamon on December 17, 2013, 09:14:02 am
I just tried making the code changes above and I'm still having the same issue.
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: Jörgen on December 17, 2013, 09:34:51 am
What issue are you having and with which VM and Joomla version?
PLease share.

Regards

Jörgen @ kreativ fotografi
Title: Re: Paypal IPN OCT 2013 http 1.1 fix vm 1.1.9
Post by: stinga on December 18, 2013, 11:39:40 am
Have you looked at the PP logs for IPN transactions? It might tell you what is going on.