Ciwan Posted December 17, 2009 Share Posted December 17, 2009 Hi Guys I thought enabling PayPal IPN would be a simple tick option in PayPal settings or something similar ! I did not know it would be so complex as coding stuff. I am a beginner PHP programmer, and I can not program the IPN. I checked on PayPal and I see they have a template. Which parts do I need to change ? also is there anything that I need to add/remove from the template ? <?php error_reporting(E_ALL ^ E_NOTICE); $email = $_GET['ipn_email']; $header = ""; $emailtext = ""; // Read the post from PayPal and add 'cmd' $req = 'cmd=_notify-validate'; if(function_exists('get_magic_quotes_gpc')) { $get_magic_quotes_exits = true;} foreach ($_POST as $key => $value) // Handle escape characters, which depends on setting of magic quotes { if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { $value = urlencode(stripslashes($value)); } else { $value = urlencode($value); } $req .= "&$key=$value"; } // Post back to PayPal 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 ('www.paypal.com', 80, $errno, $errstr, 30); // Process validation from PayPal if (!$fp) { // HTTP ERROR } else { // NO HTTP ERROR fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { // TODO: // Check the payment_status is Completed // Check that txn_id has not been previously processed // Check that receiver_email is your Primary PayPal email // Check that payment_amount/payment_currency are correct // Process payment // If 'VERIFIED', send an email of IPN variables and values to the // specified email address foreach ($_POST as $key => $value){ $emailtext .= $key . " = " .$value ."\n\n"; } mail($email, "Live-VERIFIED IPN", $emailtext . "\n\n" . $req); } else if (strcmp ($res, "INVALID") == 0) { // If 'INVALID', send an email. TODO: Log for manual investigation. foreach ($_POST as $key => $value){ $emailtext .= $key . " = " .$value ."\n\n"; } mail($email, "Live-INVALID IPN", $emailtext . "\n\n" . $req); } } fclose ($fp); ?> I would greatly appreciate any help. Thank You. 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Support Manager WHMCS John Posted December 17, 2009 WHMCS Support Manager Share Posted December 17, 2009 It is just a case of ticking a checkbox as we've done the coding part for you! http://wiki.whmcs.com/PayPal 0 Quote Link to comment Share on other sites More sharing options...
Ciwan Posted December 17, 2009 Author Share Posted December 17, 2009 Hi John Thank You, I did a google search of IPN on PayPal and I got the above. So that is it now ? that is all I have to do ? 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Support Manager WHMCS John Posted December 17, 2009 WHMCS Support Manager Share Posted December 17, 2009 Yup, that's all there is to it; always check our documentation 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.