denno020 Posted December 17, 2010 Share Posted December 17, 2010 I have set up my PayPal IPN and it works perfectly when sending test IPN's using the IPN Simulator on the PayPal developer website. When I change the ssl in this line $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); to www.paypal.com It no longer works. It comes back as INVALID, not VERIFIED. Anyone know what the problem could be? My IPN is below. You'll see there is entries into the log table, this is just for testing purposes, and how I found out that it's coming back as INVALID and not VERIFIED. Thanks Denno <?php //connect to the database here include "../scripts/connect_to_mysql.php"; //------------------------------- // PHP 4.1 // 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); // assign posted variables to local variables $team_name = $_POST['item_name']; $item_number = $_POST['item_number']; $payment_status = $_POST['payment_status']; $payment_amount = $_POST['mc_gross']; $payment_currency = $_POST['mc_currency']; $txn_id = $_POST['txn_id']; $receiver_email = $_POST['receiver_email']; $payer_email = $_POST['payer_email']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $associated_club = $_POST['custom']; $contact_number = $_POST['invoice']; if (!$fp) { // HTTP ERROR } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { //User code is added below here $dateField=date("Y-m-d H:i:s"); $sqlCommand = "INSERT INTO log VALUES('','$dateField','$payment_status','$payment_amount','$payment_currency','1','0')"; $update = mysql_query($sqlCommand, $myConnection); if($payment_status == "Completed"){ if($payment_amount == '40.00' && $payment_currency == "AUD"){ //process payment and enter information into database $sqlCommand = "INSERT INTO teams VALUES ('','$first_name','$last_name','$associated_club','$team_name','$contact_number','1')"; $update = mysql_query($sqlCommand, $myConnection); } } //User code is added above here } else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation $dateField=date("Y-m-d H:i:s"); $sqlCommand = "INSERT INTO log VALUES('','$dateField','$payment_status','$payment_amount','$payment_currency','0','1')"; $update = mysql_query($sqlCommand, $myConnection); } } fclose ($fp); } echo "$sqlCommand"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/ Share on other sites More sharing options...
kirkh34 Posted December 17, 2010 Share Posted December 17, 2010 I'm not sure if you are set on using ssl but i use $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); just remove the ssl: and change to port 80... this works for me just fine Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148538 Share on other sites More sharing options...
denno020 Posted December 17, 2010 Author Share Posted December 17, 2010 Thanks for the reply kirkh34.. Still doesn't work for me though.. Could I possible see your IPN file? Did you write your own, or did you use the sample code from PayPal? Denno Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148539 Share on other sites More sharing options...
kirkh34 Posted December 17, 2010 Share Posted December 17, 2010 I believe I found code on a forum and manipulated it... they also have a really good script generator you could use...this is my working code: include("includes/db_connect.php"); $txn_id = $_POST['txn_id']; $r1 = mysql_query("SELECT * FROM orders WHERE txn_id='$txn_id' ") or die(mysql_error()); if(mysql_num_rows($r1) == 1) exit(); // 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 ('www.paypal.com', 80, $errno, $errstr, 30); // If possible, securely post back to paypal using HTTPS // Your PHP server will need to be SSL enabled // $fp = fsockopen ('ssl://www.sandbox.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) { ////// //////do stuff here ///// } //close if else if (strcmp ($res, "INVALID") == 0) { // log for manual investigation } ///close else if } } fclose ($fp); Check out this link for the script generator... https://www.paypaltech.com/sg2/ What hosting do you have? I DID have godaddy and had major problems with godaddy allowing POST data to be sent to my server. I was on a shared hosting plan. The only way I could fix it was to buy a dedicated IP address.. I just switched hosting providors and everything is fine now. Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148783 Share on other sites More sharing options...
harristweed Posted December 17, 2010 Share Posted December 17, 2010 Make sure you are posting the data to paypal and not sandbox Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148789 Share on other sites More sharing options...
denno020 Posted December 18, 2010 Author Share Posted December 18, 2010 I'm with JustHost for the web hosting.. I'm not sure about the ins and outs with their SSL and receiving POST data.. I'm actually creating this website for a client, so this is the host that they've got. And thankyou harristweed, I'm pretty sure I already said that I have changed the POST destination.. The weird thing is, when I first set up the button, I put it with a price of $0.01, and made a payment using my paypal account (a normal buyers account), and the IPN worked fine. I then changed the price to the correct amount, and the 5 payments that have occurred since then, the IPN didn't work properly. I set up another button with a price of $0.01 on a different page in the site, and tested it again myself, and again, it worked perfectly. So I don't know why it would work perfectly when I'm paying, but not when other people are paying? Denno Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148850 Share on other sites More sharing options...
Anti-Moronic Posted December 18, 2010 Share Posted December 18, 2010 To be quite honest if you are the least bit unsure about how to do this: hire somebody else who knows exactly what they're doing. You're dealing with people's money and believe me if you're not careful you might end up costing somebody a lot of money. Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148875 Share on other sites More sharing options...
kirkh34 Posted December 18, 2010 Share Posted December 18, 2010 that's strange if you made a live payment and all you did was change the pricing... submit a ticket on x.com, one of their specialists will look at your situation and respond within 24 hours.. https://ppmts.custhelp.com/app/ask/session/L3RpbWUvMTI5MjY0NDMyOS9zaWQvRFdpWE1OaGs%3D Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148895 Share on other sites More sharing options...
denno020 Posted December 18, 2010 Author Share Posted December 18, 2010 that's strange if you made a live payment and all you did was change the pricing... submit a ticket on x.com, one of their specialists will look at your situation and respond within 24 hours.. https://ppmts.custhelp.com/app/ask/session/L3RpbWUvMTI5MjY0NDMyOS9zaWQvRFdpWE1OaGs%3D Ta mate, I shall do that. Denno Quote Link to comment https://forums.phpfreaks.com/topic/221949-paypal-ipn-help-needed-urgently/#findComment-1148902 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.