By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,617 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,617 IT Pros & Developers. It's quick & easy.

Paypal IPN troubles

P: 6
I've got a setup for my online game for upgraded accounts. However, I'm unable to communicate with Paypal's IPN sandbox server. Does anyone have any experience with Paypal's IPN and, if so, can someone help me out?

Expand|Select|Wrap|Line Numbers
  1.     case 'validate':
  2.         // read the post from PayPal system and add 'cmd'
  3.         $req = 'cmd=_notify-validate';
  4.  
  5.         foreach ($_POST as $key => $value)
  6.         {
  7.             $value = urlencode(stripslashes($value));
  8.             $req .= "&$key=$value";
  9.         }
  10.  
  11.         // post back to PayPal system to validate
  12.         $header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
  13.         $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
  14.         $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
  15.  
  16.         $fp = fsockopen("paypal.com", 80, $errno, $errstr, 30);
  17.  
  18.         // assign posted variables to local variables
  19.         $item_name = $_POST['item_name'];
  20.         $item_number = $_POST['item_number'];
  21.         $payment_status = $_POST['payment_status'];
  22.         $payment_amount = $_POST['mc_gross'];
  23.         $payment_currency = $_POST['mc_currency'];
  24.         $txn_id = $_POST['txn_id'];
  25.         $receiver_email = $_POST['receiver_email'];
  26.         $payer_email = $_POST['payer_email'];
  27.         $custom = $_POST['custom'];
  28.  
  29.         // parse custom
  30.         $custom_arr = explode("&", $custom);
  31.         $params = array();
  32.         foreach($custom_arr as $custom_kvp)
  33.         {
  34.             $custom_kvp_kv = explode("=", $custom_kvp);
  35.             $params[$custom_kvp_kv[0]] = $custom_kvp_kv[1];
  36.         }
  37.  
  38.         if (!$fp)
  39.         {
  40.             $logstring = "[ip $_SERVER[REMOTE_ADDR]] " . date("r") . "; code HTTPFAIL: unable to connect to PayPal [$resdump]. \r\n";
  41.  
  42.             $lp = fopen("ipnlog.txt", "a");
  43.             fwrite($lp, $logstring);
  44.             fclose($lp);
  45.  
  46.             // error
  47.             die($logstring);
  48.         }
  49.  
  50.  
Thanks.

I'm willing to use an entirely different method if needed, I just need someone to point me in the right direction.
Oct 10 '07 #1
Share this Question
Share on Google+
2 Replies


ak1dnar
Expert 100+
P: 1,584
Sandbox url is like this "www.sandbox.paypal.com"
you are using live one.
Oct 10 '07 #2

P: 6
Thanks,

I've tried that, it's now at least getting a connection to Paypal. However, another problem has arisen; Paypal doesn't seem to be communicating with my server at all. From my understanding, it works like this:

I send person to Paypal -> They pay -> Paypal contacts my script -> I contact Paypal for verification -> Paypal verifies -> And we're all happy

Here's my code which POSTs to Paypal's server:

[PHP]
case 'process':
$fields['custom'] = "userID=" . $_POST['userid'] . "&planID=" . $_POST['plan'] . "&py=" . sha1(rand(0, 1024 * 1024));
$fields['rm'] = '2';
$fields['cmd'] = '_xclick';
$fields['currency_code'] = 'USD';
$fields['business'] = 'seller_1190225049_biz@tgohome.com';
$fields['business_name'] = 'Lizard Mania';
$fields['item_name'] = "Lizard Mania Platinum Upgrade (" . $plans[$_POST['plan']][1] . ")";
$fields['amount'] = $plans[$_POST['plan']][2];
$fields['notify_url'] = "http://www.lizard-mania.com/paypalcomm.php?do=validate";
$fields['notify'] = "http://www.lizard-mania.com/paypalcomm.php?do=validate";
$fields['return'] = "http://www.lizard-mania.com/platinum.php?do=thanks&pc=payment_almost_completed ";

$fields['shipping'] = 0.00;
$fields['amount_0'] = $plans[$_POST['plan']][2];
$fields['handling_0'] = 0.00;
$fields['shipping_0'] = 0.00;

$fields['no_note'] = 1;
$fields['no_shipping'] = 1;

echo "<html>\n";
echo "<head><title>Processing Payment...</title></head>\n";
echo "<body onload=\"document.form.submit();\">\n";
echo "<center><img src=\"http://www.lizard-mania.com/logo6.png\" /></center>\n";
echo "<center><h1>Thanks for your purchase!</h1></center>\n";
echo "<center><h3>Please wait, your order is being processed. <br />";
echo "You will be redirected to PayPal to complete the payment. </h3></center>\n";
echo "<center><h5>This may take a few seconds. </h5></center>\n";
echo "<center><img src=\"throbber.gif\" alt=\"Please wait... \" /></center>\n";
echo "<form method=\"post\" name=\"form\" action=\"$paypalurl\">\n";

foreach ($fields as $name => $value)
{
echo "<input type=\"hidden\" name=\"$name\" value=\"$value\">\n";
}

echo "<center><noscript><input type=\"submit\" name=\"trf_cust_extfield0\" value=\"Please click here if redirection fails\" /></noscript></center>";

echo "</form>\n";
echo "</body></html>\n\n\n";

$logstring = "[ip $_SERVER[REMOTE_ADDR]] " . date("r") . "; code STAGETWO_START_PAY. \r\n";

$lp = fopen("ipnlog.txt", "a");
fwrite($lp, $logstring);
fclose($lp);

die("<!--" . $logstring . "-->");
break;

[/PHP]
Oct 11 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.