1. Post #1
    Catnip Cody
    cody8295's Avatar
    February 2009
    2,411 Posts
    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          
    //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);
    }
    ?>
    
    


    Thanks in advance.

  2. Post #2
    Gold Member
    nivek's Avatar
    June 2009
    3,508 Posts
    What are the returned errors?
    Reply With Quote Edit / Delete Reply Windows XP Professional x64 United States Show Events Informative Informative x 1Agree Agree x 1 (list)

  3. Post #3
    Catnip Cody
    cody8295's Avatar
    February 2009
    2,411 Posts
    What are the returned errors?


    They were just sql errors that I fixed no problem. But now nothing is being returned.

  4. Post #4
    Gold Member
    nivek's Avatar
    June 2009
    3,508 Posts
    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
    if (($payment_status == 'Completed') &&
    and just have it write the post data to a text file or something and see if anything shows up.

  5. Post #5
    Gold Member
    jetboy's Avatar
    January 2009
    2,261 Posts
    $fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
    You said you weren't using the sandbox.

  6. Post #6
    Gold Member
    nivek's Avatar
    June 2009
    3,508 Posts
    https://www.paypaltech.com/SG2/

    try to start with that.
    Reply With Quote Edit / Delete Reply Windows XP Professional x64 United States Show Events Winner Winner x 1 (list)

  7. Post #7
    Catnip Cody
    cody8295's Avatar
    February 2009
    2,411 Posts
    You said you weren't using the sandbox.
    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.

    Edited:

    Hey thanks man! That site is really useful. Thanks again!
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Friendly Friendly x 1 (list)