0

Hi everyone. I watched Alex's PayPal IPN series and I was testing it on the PayPal IPN Sandbox and it won't work. Here is my code.

verify.php

<br />To verify your account click the button below.<br /><br />
                                        <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                                            <input type="hidden" name="cmd" value="_xclick">
                                            <input type="hidden" name="business" value="upgrade@megainstrumentals.co.uk">
                                            <input type="hidden" name="item_name" value="Verification">
                                            <input type="hidden" name="item_number" value="1">
                                            <input type="hidden" name="amount" value="1.25"> 
                                            <input type="hidden" name="no_shipping" value="1">
                                            <input type="hidden" name="no_note" value="1">
                                            <input type="hidden" name="currency_code" value="GBP">
                                            <input type="hidden" name="lc" value="GB">
                                            <input type="hidden" name="bn" value="PP-BuyNowBF">
                                            <input type="hidden" name="return" value="http://www.megainstrumentals.co.uk/instrumentals.php">
                                            <input type="hidden" name="cancel_return" value="http://www.megainstrumentals.co.uk/verify.php">
                                            <input type="hidden" name="rm" value="2">
                                            <input type="hidden" name="notify_url" value="http://www.megainstrumentals.co.uk/ver_ipn.php" />
                                            <input type="hidden" name="custom" value="<?php echo $_SESSION["uid"]; ?>">
                                            <input type="submit" value="Verify Your Account" class="input-submit" style="width: 180px;" />
                                        </form>

ver_ipn.php

<?php
include "config.inc.php";
// 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
$item_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"];

if (!$fp) {
   // HTTP ERROR
} else {
  fputs ($fp, $header . $req);
  while (!feof($fp)) {
    $res = fgets ($fp, 1024);
    if (strcmp ($res, "VERIFIED") == 0)
	{
		if($payment_status=="Completed")
		{
			$txn_check = mysql_query("SELECT `txn_id` FROM `upgrade_logs` WHERE `txn_id`='" . $txn_id . "'");
			if(mysql_num_rows($txn_check)!=1)
			{
				if($receiver_email=="upgrade@megainstrumentals.co.uk")
				{
					if($payment_amount=="1.25"&&$payment_currency=="GBP")
					{
						//insert `upgrade_logs`
						$insert_upgradelogs = mysql_query("INSERT INTO `upgrade_logs` VALUES('', '" . $txn_id . "', '" . $prokey->encrypt($payer_email) . "')");
						
						//update candownload to 1
						$update_candownlaad = mysql_query("UPDATE `users` SET `candownload`='1' WHERE paypal_email='" . $prokey->encrypt($payer_email) . "'");
					}
				}
			}
		}
    }
    else if (strcmp ($res, "INVALID") == 0) {
         // log for manual investigation
    }
  }
  fclose ($fp);
}
?>

I have set up my PayPal account to allow IPN's and I have set the URL to http://www.megainstrumentals.co.uk/ver_ipn.php. I can't see what the problem is. I have tested it with a member of my family's PayPal account and it won't work.

Thanks in advance.

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by diafol
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.