• Paypal IPN
    6 replies, posted
I'm trying to set it up, I've followed many tutorials, it just doesn't work. And I can't set it up on a sandbox account because if I even try to edit my profile settings I get some error about the wrong PayPal version caused by bookmarks or some shit. I've had a few people send a few cents to test it, and they came up with some php errors that I fixed and after they tested it again, the result was nothing, a blank page. How can I test/fix my IPN script? [PHP] <?php //echo "Please go away."; $req = 'cmd=_notify-validate'; foreach ($_POST as $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } $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.sandbox.paypal.com', 80, $errno, $errstr, 30); //$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); if (!$fp) { $mail_From = "From: IPN@aftermathprojects.com"; $mail_To = $email; $mail_Subject = "HTTP ERROR"; $mail_Body = $errstr; mail($mail_To, $mail_Subject, $mail_Body, $mail_From); echo "Something went wrong while processing your transaction, please contact an administrator."; } else { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); if (strcmp ($res, "VERIFIED") == 0) { $item_name = $_POST['item_name']; $item_number = $_POST['item_number']; $item_sid = $_POST['custom']; $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']; if (($payment_status == 'Completed') && ($receiver_email == "chuckstaco@gmail.com") && ($payment_currency == "USD")) { $dbhost = "www.aftermathprojects.com"; $dbuser = "edited"; $dbpass = "edited"; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql, contact an administrator with your Transaction ID and Steam ID ready. '); $dbname = "aftermat_chuck"; mysql_select_db($dbname); if ($payment_amount >= 5.00) { echo "Thank you for purchasing VIP."; $sql="INSERT INTO donators (sid, tid, vip) VALUES ('$txn_id','$item_sid', '1')"; if (!mysql_query($sql, $conn)) { die('Error: ' . mysql_error()); } else { echo "<br>Added to VIP list."; } } else { echo "You're donation was less than $5.00 USD. You have not purchased VIP, however thank you for the donation. If you believe this is an error, please contact an administrator."; $sql="INSERT INTO donators (sid, tid, vip) VALUES ('$txn_id','$item_sid', '0')"; if (!mysql_query($sql, $conn)) { die('Error: ' . mysql_error()); } else { echo "<br>Added to donator list."; } } mysql_close($conn); // uncomment this section during development to receive an email to indicate whats happened // $mail_To = "payit@designertuts.com"; // $mail_Subject = "completed status received from paypal"; // $mail_Body = "completed: $item_number $txn_id"; // mail($mail_To, $mail_Subject, $mail_Body); } else { //Canceled_Reversal: A reversal has been canceled. For example, you won a dispute with the customer, and the funds for // Completed the transaction that was reversed have been returned to you. //Completed: The payment has been completed, and the funds have been added successfully to your account balance. //Denied: You denied the payment. This happens only if the payment was previously pending because of possible // reasons described for the PendingReason element. //Expired: This authorization has expired and cannot be captured. //Failed: The payment has failed. This happens only if the payment was made from your customer’s bank account. //Pending: The payment is pending. See pending_reason for more information. //Refunded: You refunded the payment. //Reversed: A payment was reversed due to a chargeback or other type of reversal. The funds have been removed from // your account balance and returned to the buyer. The reason for the // reversal is specified in the ReasonCode element. //Processed: A payment has been accepted. //Voided: This authorization has been voided. $mail_To = "payit@aftermathprojects.com"; $mail_Subject = "PayPal IPN status not completed or security check fail"; $mail_Body = "Something wrong. \n\nThe transaction ID number is: $txn_id \n\n Payment status = $payment_status \n\n Payment amount = $payment_amount"; mail($mail_To, $mail_Subject, $mail_Body); } } else if (strcmp ($res, "INVALID") == 0) { $mail_To = "payit@aftermathprojects.com"; $mail_Subject = "PayPal - Invalid IPN "; $mail_Body = "We have had an INVALID response. \n\nThe transaction ID number is: $txn_id \n\n username = $username"; mail($mail_To, $mail_Subject, $mail_Body); } } fclose ($fp); } ?> [/PHP] Thanks in advance.
What are the returned errors?
[QUOTE=nivek;34998554]What are the returned errors?[/QUOTE] They were just sql errors that I fixed no problem. But now nothing is being returned.
What I would do to crack down on the error (as it has worked for me before when using the paypal IPN) is get rid of all your code inside [php]if (($payment_status == 'Completed') &&[/php] and just have it write the post data to a text file or something and see if anything shows up.
[quote][php]$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);[/php][/quote] You said you weren't using the sandbox.
[url]https://www.paypaltech.com/SG2/[/url] try to start with that.
[QUOTE=jetboy;35000295]You said you weren't using the sandbox.[/QUOTE] This code from a tutorial where it had that line commented out, I uncommented it when trying to use sandbox, right before I posted here. [editline]5th March 2012[/editline] [QUOTE=nivek;35000342][url]https://www.paypaltech.com/SG2/[/url] try to start with that.[/QUOTE] Hey thanks man! That site is really useful. Thanks again!
Sorry, you need to Log In to post a reply to this thread.