PayPal IPN在模拟器中工作但不是直播

时间:2014-01-27 19:30:57

标签: paypal paypal-ipn

我使用了以下PayPal IPN脚本。在使用IPN模拟器进行测试时,代码可以正常工作,但是当我实现它时,它根本不起作用。我一直在网上寻找解决方案。有没有办法看到它返回无效的原因?有什么想法吗?

<?php
$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval) {
$keyval = explode ('=', $keyval);
if (count($keyval) == 2)
$myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the IPN message sent from PayPal and prepend 'cmd=_notify-validate'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
$get_magic_quotes_exists = true;
}
foreach ($myPost as $key => $value) {
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
    $value = urlencode(stripslashes($value));
} else {
    $value = urlencode($value);
}
$req .= "&$key=$value";
}

// Step 2: POST IPN data back to PayPal to validate

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));

if( !($res = curl_exec($ch)) ) {
error_log("Got " . curl_error($ch) . " when processing IPN data", 1, "myemail");
curl_close($ch);
exit;
}
curl_close($ch);

if (strcmp ($res, "VERIFIED") == 0) {

$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'];
$payment_id = $_POST['custom'];
$email_from = "from@email";
    $subject = "Your Deep Democracy account has been activated!";

    $headers = "From: DD Notifications\r\n";
    $headers .= "Reply-To: notifications@deep-democracy.net\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";

    require_once("../includes/db_connection.php");

    mail("myemail", $subject, $payment_id." ".$payer_email, $headers);
    //Customs
    $result = mysql_query("SELECT * FROM delegate_payments WHERE payment_id='$payment_id' AND payment_completed='No'");

    if (mysql_num_rows($result) == 1) {

        mysql_query("UPDATE delegate_payments SET payment_completed='Yes' WHERE payment_id='$payment_id'");
        $row = mysql_fetch_array($result);
        $amount = $row['payment_amount'];
        $names_array = explode(', ', $row['payment_content']);

        $result2 = mysql_query("SELECT * FROM users WHERE email='$payer_email'");
        $row = mysql_fetch_array($result2);
        $current_amount = $row['amount_due'];
        $new_amount = $current_amount - $amount;

        mysql_query("UPDATE users SET amount_due='$new_amount' WHERE email='$payer_email'");

        foreach ($names_array as &$value) {
            mysql_query("UPDATE users SET activated='1' WHERE email='$value'");
            mail($value, $subject, $email_message, $headers);
            mail("an@email.com", "Delegate Payment Notification", "Hi Britta, \n\nThis is a notification email to inform you that a new delegate has been paid for. The email address is: {$value}", $headers);
        }
    }

} else if (strcmp ($res, "INVALID") == 0) {
mail("myemail", "Failed", $res, $headers);}
?>

0 个答案:

没有答案
相关问题