开发者

PHP MySQL IPN Problem

开发者 https://www.devze.com 2023-02-15 14:30 出处:网络
I\'m using a PayPal IPN script to process subscription payments on my new project. Everything seems to work great but for some reason when the payment is processed and accepted my databases just don\'

I'm using a PayPal IPN script to process subscription payments on my new project. Everything seems to work great but for some reason when the payment is processed and accepted my databases just don't update.

This is the part of the IPN script to update my databases:

$p->add_field('cmd','_xclick-subscriptions');
$p->add_field('no_note','1');
$p->add_field('currency_code','USD');
$p->add_field('a3', "0.01");
$p->add_field('t3', "M");
$p->add_field('p3', "1");
$p->add_field('src', "1");
$p->add_field('sra', "1");
$p->add_field('business', "myemail@gmail.com");
$p->add_field('return', "http://myurl.com/");
$p->add_field('cancel_return', $this_script.'?action=cancel');
$p->add_field('notify_url', $this_script.'?action=ipn');
$p->add_field('item_name', "My Package Thing ($_POST[hash])");
$p->add_field('custom', "$_POST[hash]");

$p->submit_paypal_post();
      //$p->dump_fields();
      break;
    case 'success':
      echo "<html><head>开发者_StackOverflow社区<title>Success</title></head><body><h3>Thank you for your order.</h3>";
      echo "</body></html>";
      break;
    case 'cancel':
      echo "<html><head><title>Canceled</title></head><body><h3>The order was canceled.</h3>";
      echo "</body></html>";
      break;
    case 'ipn':
if ($p->validate_ipn()) {
include("config.php");
$select = mysql_query("UPDATE `mydb_accounts`.`accounts` SET `active` = '1' WHERE `accounts`.`hash` = '$_POST[hash]';") or die(mysql_error());
mysql_query($select);
} break; }

$_POST[hash] works fine because when the "PayPal Payment Page" appears it's shown the item description.

Any thoughts? Thanks!


Be sure that you mysql_connect in your config file (not only set database info).


Having built a PayPal IPN handler three times (for different) systems I can confirm that most of the problems are caused by simple PHP syntax errors, or bugs that you can't see because the output of the script is lost.

There is no point putting any output at all into the IPN handler - PayPal is the only thing that will see them and it discards them.

My code is in two parts, the payment callback and the core logic entity. Always try opening the callback handler from the browser first to trap any syntax or logic errors. Then substitute the callback POST with a hardcoded test and see if it works. Then test against the paypal sandbox.

I use my Emesary notification system to send the messages to the backend - however you could append to a log file etc..

0

精彩评论

暂无评论...
验证码 换一张
取 消