Want more features on Pastebin? Sign Up, it's FREE!
Guest

Improve eShop PayPal IPN for SSL

By: kitchin on Jun 7th, 2012  |  syntax: PHP  |  size: 1.74 KB  |  views: 97  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. --- eshop-paypal.class.php      Wed Jun 06 13:11:32 2012
  2. +++ fix.php     Wed Jun 06 13:12:27 2012
  3. @@ -196,17 +196,30 @@
  4.        }
  5.        $post_string.="cmd=_notify-validate"; // append ipn command
  6.  
  7. -       // open the connection to paypal was:
  8. -       //$fp = fsockopen($url_parsed[host],"80",$err_num,$err_str,30);
  9. -       //try uncommenting that line if the following doesn't work.
  10. -               $fp = fsockopen ('ssl://'.$url_parsed[host], "443", $err_no, $err_str, 30);
  11. -      if(!$fp) {
  12. -         // could not open the connection.  If loggin is on, the error message
  13. -         // will be in the log.
  14. -         $this->last_error = "fsockopen error no. $errnum: $errstr";
  15. -         $this->log_ipn_results(false);      
  16. -         return false;
  17. -        
  18. +       $ipnhost= $url_parsed['host'];
  19. +       $ipnport= 80;
  20. +
  21. +       if (function_exists('stream_get_transports')) {
  22. +               $transports= stream_get_transports();
  23. +               if (in_array('ssl', $transports)) {
  24. +                       $ipnport= 443;
  25. +               }
  26. +       }
  27. +
  28. +       if ($ipnport == 443) {
  29. +               $ipnhost= "ssl://$ipnhost";
  30. +       }
  31. +
  32. +       $fp = fsockopen($ipnhost, $ipnport, $err_no, $err_str, 30);
  33. +
  34. +       if(!$fp) {
  35. +               // could not open the connection.  If loggin is on, the error message
  36. +               // will be in the log. // TYPO FIXES:
  37. +               $this->last_error = "fsockopen error no. $err_no: $err_str";
  38. +               $this->last_error .= "\n host= $ipnhost, port= $ipnport";
  39. +               $this->log_ipn_results(false);      
  40. +               return false;
  41. +
  42.        } else {
  43.  
  44.           // Post the data back to paypal
  45. @@ -236,6 +249,7 @@
  46.    
  47.           // Invalid IPN transaction.  Check the log for details.
  48.           $this->last_error = 'IPN Validation Failed.';
  49. +         $this->last_error .= "\n host= $ipnhost, port= $ipnport";
  50.           $this->log_ipn_results(false);  
  51.           return false;
clone this paste RAW Paste Data