PayPal IPN未连接到数据库或发送邮件

时间:2013-08-06 12:56:04

标签: php mysql paypal paypal-ipn

只是想知道我在这里错过了什么......

我通过测试模拟器运行了以下IPN,并且它返回有效,但它根本没有与“MAIL”脚本或“UPDATE MYSQL”代码进行交互......

我第一次将它与Codeigniter框架结合使用,并且我的数据库连接被自动加载(因此代码中缺少它),但这不一定会阻止电子邮件脚本发送...实际上,我完全删除了这一点,只是为了集中精力让数据库更新正常工作。

<?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)
                                {
                                                // check the payment_status is Completed
                                                // check that txn_id has not been previously processed
                                                // check that receiver_email is your Primary PayPal email
                                                // check that payment_amount/payment_currency are correct

                // MAIL
                // mail script goes here...

                // MYSQL UPDATE
                                                mysql_query("UPDATE shop SET qty = '0' WHERE intId = '001'") or die(mysql_error());
                                }
                                else if (strcmp($res, "INVALID") == 0)
                                {
                                                // log for manual investigation
                                }
                }
                fclose($fp);
}

我只是错过了一些非常明显的东西吗?

谢谢你们!

0 个答案:

没有答案