scottfennell Posted February 15, 2012 Share Posted February 15, 2012 Hey Guys, I learned everything I know from Larry's books, but this question is not directly from any of his books. But I really need some help! I've set up a script to listen for IPN from paypal. I see the IPN activity in my paypal IPN history. The listener script that I set up is supposed to change one row in my database (I'm adding a user_meta value to a wordpress user to flag him as a premium user). The database update is not happening. When I point my browser to the page where the ipn script is hosted, this is the error message I see: web browser to the page on which my ipn script is located, I get this php error message: Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://www.paypal.com:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in /home/adven/avclients.com/belovedsamoa/latest/ipn.php on line 20 Does anyone have any advice at all? What more do you need in order to help me? phpinfo() output below: In full: http://avclients.com...est/phpinfo.php The highlights: PHP Version 5.3.6 SSL Version OpenSSL/0.9.8b System Linux webserver.adventuresdesign.com 2.6.18-164.11.1.el5xen #1 SMP Wed Jan 20 08:06:04 EST 2010 x86_64 Build Date Mar 23 2011 12:20:27 Configure Command './configure' '--disable-fileinfo' '--disable-phar' '--enable-bcmath' '--enable-calendar' '--enable-ftp' '--enable-libxml' '--enable-magic-quotes' '--enable-mbstring' '--enable-pdo=shared' '--enable-sockets' '--prefix=/usr' '--with-curl=/opt/curlssl/' '--with-curlwrappers' '--with-gd' '--with-gettext' '--with-imap=/opt/php_with_imap_client/' '--with-imap-ssl=/usr' '--with-jpeg-dir=/usr' '--with-kerberos' '--with-libdir=lib64' '--with-libxml-dir=/opt/xml2/' '--with-mysql=/usr' '--with-mysql-sock=/var/lib/mysql/mysql.sock' '--with-pcre-regex=/opt/pcre' '--with-pdo-mysql=shared' '--with-pdo-sqlite=shared' '--with-pic' '--with-png-dir=/usr' '--with-sqlite=shared' '--with-xpm-dir=/usr' '--with-zlib' '--with-zlib-dir=/usr' Link to comment Share on other sites More sharing options...
scottfennell Posted February 15, 2012 Author Share Posted February 15, 2012 FYI, here is my ipn script: <?php /** * Template Name: IPN * */ $wpdb; // read the post from PayPal system and add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } // post back to PayPal system to validate $header = "POST /cgi-bin/webscr HTTP/1.0\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.paypal.com', 443, $errno, $errstr, 30); if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // PAYMENT VALIDATED & VERIFIED! $current_user=wp_get_current_user(); $user_login=$current_user->user_login; $user_email=$current_user->user_email; $user_id=$current_user->ID; update_user_meta($user_id, 'is_premium', '1'); } else if (strcmp ($res, "INVALID") == 0) { // PAYMENT INVALID & INVESTIGATE MANUALY! } } fclose ($fp); } ?> Link to comment Share on other sites More sharing options...
Larry Posted February 15, 2012 Share Posted February 15, 2012 I know you don't think this pertains to one of my books, but I do IPN with PayPal in my e-commerce book. In any case, shouldn't fopen() be trying https://www.paypal.com? Perhaps I'm being absent minded right now, but SSL isn't a protocol used like you have it. Link to comment Share on other sites More sharing options...
scottfennell Posted February 15, 2012 Author Share Posted February 15, 2012 Hey Larry, After searching, I see that you're quite right: Your new book does cover IPN. Feel free to move this post if you want. I tried changing the ssl to https but all that did was change the error message to: Warning: fsockopen() [function.fsockopen]: unable to connect to https://www.paypal.com:443 (Unable to find the socket transport "https" - did you forget to enable it when you configured PHP?) in/home/adven/avclients.com/belovedsamoa/latest/ipn.php on line 14 Link to comment Share on other sites More sharing options...
Larry Posted February 16, 2012 Share Posted February 16, 2012 I was being quite daft. Your original code was correct. My best guess then is what's suggested in the error message: that PHP isn't configured to use fsockopen() with SSL. Perhaps you could use cURL? 1 Link to comment Share on other sites More sharing options...
scottfennell Posted February 19, 2012 Author Share Posted February 19, 2012 Is there some way to check that php is configured correctly for it? My host support said they had no idea what the problem was. Anything to be gleaned from the phpinfo() that I linked to? Link to comment Share on other sites More sharing options...
rob Posted February 19, 2012 Share Posted February 19, 2012 Under Registered Stream Socket Transports , ssl isn't listed, looks like it's not setup. Also, your original syntax for hostname was correct ssl://www.paypal.com don't include https. 1 Link to comment Share on other sites More sharing options...
scottfennell Posted February 20, 2012 Author Share Posted February 20, 2012 Thanks very much, Rob. This isn't really my server, it's the server for a design shop i'm doing work for. Can you think of any reason why this is not enabled already? What are the unforeseen consequences of enabling it? I just don't feel like I have any context here. Link to comment Share on other sites More sharing options...
rob Posted February 20, 2012 Share Posted February 20, 2012 No, sorry. On the basis that you've already stated support said they had no idea what the problem was and it's not your server, I would follow Larry's advice and use cURL. Link to comment Share on other sites More sharing options...
scottfennell Posted February 21, 2012 Author Share Posted February 21, 2012 And is it fair to say that I'll get a full review of using Curl to interact with paypal if I pick up Larry's e-commerce book? I've never used Curl before. Link to comment Share on other sites More sharing options...
Larry Posted February 22, 2012 Share Posted February 22, 2012 Definitely not fair to say that. In fact, you won't see how to use cURL with PayPal at all. You will, however, see how to use cURL with Authorize.net, which will be similar. You can download the code (for the second example) to see for yourself. Link to comment Share on other sites More sharing options...
Recommended Posts