Paypal IPN does not work (ERROR checkPaypalIps: Error)

Please post your issues and questions about One Page Checkout for Virtuemart 2 to this forum.

Paypal IPN does not work (ERROR checkPaypalIps: Error)

Postby admin » Wed Dec 10, 2014 5:40 pm

This is Virtuemart bug which concerns all versions of virtuemart from 2.6.0 to 3.0.2 (and possibly on a few 2.0.20 releases and around)

On some servers, detected IP address of paypal can return a comma separated list of proxy servers between your webserver and paypal's notify server.

This leads to improper detection of IP address which prevents Virtuemart from updating your order status to confirmed.

To fix this code on VM2.6.14 (works on other versions as well) you need to locate function:


on VM2.6.14 and VM3 this is located in:
\plugins\vmpayment\paypal\paypal\helpers\paypal.php


Code: Select all
protected function checkPaypalIps ($paypal_data) {
      /*
            $test_ipn = (array_key_exists('test_ipn', $paypal_data)) ? $paypal_data['test_ipn'] : 0;
            if ($test_ipn == 1) {
               return true;
            }
      */
      $order_number = $paypal_data['invoice'];

      // Get the list of IP addresses for www.paypal.com and notify.paypal.com


      if ($this->_method->sandbox) {
         $paypal_iplist = gethostbynamel('ipn.sandbox.paypal.com');
         $paypal_iplist = (array)$paypal_iplist;
         $this->debugLog($paypal_iplist, 'checkPaypalIps SANDBOX', 'debug', false);

      } else {
         $paypal_iplist1 = gethostbynamel('www.paypal.com');
         $paypal_iplist2 = gethostbynamel('notify.paypal.com');
         $paypal_iplist3 = array('216.113.188.202', '216.113.188.203', '216.113.188.204', '66.211.170.66');
         $paypal_iplist = array_merge($paypal_iplist1, $paypal_iplist2, $paypal_iplist3);
// http://forum.virtuemart.net/index.php?topic=115375.msg406664#msg406664

         // 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',
            '173.0.82.126',

         );
         //------------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, // 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
         );

         $this->debugLog($paypal_iplist, 'checkPaypalIps PRODUCTION', 'debug', false);

      }

      $IP=$this->getRemoteIPAddress();
      
      $this->debugLog($IP, 'checkPaypalIps REMOTE ADDRESS', 'debug', false);

      //  test if the remote IP connected here is a valid IP address
      if (!in_array($IP, $paypal_iplist)) {

         $text = "Error with REMOTE IP ADDRESS = " . $IP . ".
                        The remote address of the script posting to this notify script does not match a valid PayPal IP address\n
            These are the valid IP Addresses: " . implode(",", $paypal_iplist) . "The Order ID received was: " . $order_number;
         $this->debugLog($text, 'checkPaypalIps', 'error', false);
         return false;
      }

      return true;
   }



and change it to:
Code: Select all
protected function checkPaypalIps ($paypal_data) {
      /*
            $test_ipn = (array_key_exists('test_ipn', $paypal_data)) ? $paypal_data['test_ipn'] : 0;
            if ($test_ipn == 1) {
               return true;
            }
      */
      $order_number = $paypal_data['invoice'];

      // Get the list of IP addresses for www.paypal.com and notify.paypal.com


      if ($this->_method->sandbox) {
         $paypal_iplist = gethostbynamel('ipn.sandbox.paypal.com');
         $paypal_iplist = (array)$paypal_iplist;
         $this->debugLog($paypal_iplist, 'checkPaypalIps SANDBOX', 'debug', false);

      } else {
         $paypal_iplist1 = gethostbynamel('www.paypal.com');
         $paypal_iplist2 = gethostbynamel('notify.paypal.com');
         $paypal_iplist3 = array('216.113.188.202', '216.113.188.203', '216.113.188.204', '66.211.170.66');
         $paypal_iplist = array_merge($paypal_iplist1, $paypal_iplist2, $paypal_iplist3);
// http://forum.virtuemart.net/index.php?topic=115375.msg406664#msg406664

         // 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',
            '173.0.82.126',

         );
         //------------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, // 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
         );

         $this->debugLog($paypal_iplist, 'checkPaypalIps PRODUCTION', 'debug', false);

      }

      $IP=$this->getRemoteIPAddress();
      if (stripos($IP, ',')!==false)
       {
          //stAn: As it turns out, HTTP_X_FORWARDED_FOR can sometimes have a comma delimited list of IP addresses
          $ip_a = explode(',', $IP);
         foreach ($ip_a as $k=>$ip_test)
          {
            $ip_a[$k] = trim($ip_test);
            
            if (in_array($ip_a[$k], $paypal_iplist )) return true;
          }
         
         
         
       }
      $this->debugLog($IP, 'checkPaypalIps REMOTE ADDRESS', 'debug', false);

      //  test if the remote IP connected here is a valid IP address
      if (!in_array($IP, $paypal_iplist)) {

         $text = "Error with REMOTE IP ADDRESS = " . $IP . ".
                        The remote address of the script posting to this notify script does not match a valid PayPal IP address\n
            These are the valid IP Addresses: " . implode(",", $paypal_iplist) . "The Order ID received was: " . $order_number;
         $this->debugLog($text, 'checkPaypalIps', 'error', false);
         return false;
      }

      return true;
   }
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm

Re: Paypal IPN does not work (ERROR checkPaypalIps: Error)

Postby admin » Wed Dec 10, 2014 5:43 pm

the new lines are:
Code: Select all
if (stripos($IP, ',')!==false)
       {
          //stAn: As it turns out, HTTP_X_FORWARDED_FOR can sometimes have a comma delimited list of IP addresses
          $ip_a = explode(',', $IP);
         foreach ($ip_a as $k=>$ip_test)
          {
            $ip_a[$k] = trim($ip_test);
           
            if (in_array($ip_a[$k], $paypal_iplist )) return true;
          }
         
       
         
       }


Best regards, Stan
admin
Site Admin
 
Posts: 2708
Joined: Wed Jan 06, 2010 11:43 pm


Return to One Page Checkout for Virtuemart 2

cron