普通网友 2013-07-24 01:49
浏览 67
已采纳

PayPal IPN卡在付款验证

I have been working for some time on this, and have yet to find the solution. I am attempting to get the PayPal IPN to work, but have yet to be successful at doing so. First, I was having some trouble connecting with SSL, so I went without it for now. After that, I seemed to be getting some other issue. I went ahead and added some debug, and have found that I am getting stuck at the VERIFY check. That is really all I know about what is going on.

Below is my PayPal IPN, and below that, my button code.

<?php
include("inc/database.php");
$debug = true;
$header = '';
$req = "cmd=_notify-validate";
foreach($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

$header .= "POST /cgi-bin/webscr HTTP/1.1
";
$header .= "Content-Type: application/x-www-form-urlencoded
";
$header .= "Host: www.sandbox.paypal.com
";  // www.sandbox.paypal.com for a test site
$header .= "Content-Length: " . strlen($req) . "

";

if ($debug)
{
    $ourFileName = "pdebug.txt";
    $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
    fwrite($ourFileHandle, $req);
    fclose($ourFileHandle);
}

$fp = fsockopen('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if(!$fp) {
    // HTTP Error;
    $message .= "
 HTTP ERROR. 
";
} else {
    if ($debug)
    {
        $ourFileName = "debug/debug2_connected.txt";
        $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
        fclose($ourFileHandle);
    }
    fputs($fp, $header . $req);
    while(!feof($fp)) {
        $res = fgets($fp, 1024);
        if ($debug)
        {
            $ourFileName = "debug/debug3_fgets.txt";
            $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
            fwrite($ourFileHandle, $res);
            fclose($ourFileHandle);
        }
        if(strcmp($res, "VERIFIED") == 0) {
            if ($debug)
            {
                $ourFileName = "debug/debug4_verified.txt";
                $ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
                fclose($ourFileHandle);
            }
            $ids = explode("|", $_POST['custom']);
            $item_name = $_POST["item_name"];
            $item_number = $_POST["item_number"];
            $item_username = $ids[0];
            $item_packageid = $ids[1];
            $item_email = $ids[2];
            $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"];

            $prices = array(4, 4, 4);

            if(($payment_status == "Completed") && ($receiver_email == "bking-facilitator@inbox.com") && ($payment_amount == $prices[$item_packageid - 1]) && ($payment_currency == "USD") && (checkTxnId($txn_id) == 0)) {
                addPaypalPayment($item_name, $item_number, $item_username, $item_packageid, $item_email, $payment_status, $payment_amount, $payment_currency, $txn_id, $receiver_email, $payer_email);
                serviceAdd($item_username, $item_number, $item_packageid);
                setServiceActive($item_packageid);
                sendEmailWithUsername("Carwash", "PayPal IPN", "Success!");
            } else {
                $mail_To = getUserEmail($item_username);
                $mail_Subject = "Purchase Unsuccessful";
                $mail_Body = "Something went wrong with your recent order. 

The transaction ID number is :$txn_id 

Payment status is: $payment_status 

Payment amount is: $payment_amount 

If you believe this is an error on our part, please submit a ticket and we will look into this for you.";
                mail($mail_To, $mail_Subject, $mail_Body);
                sendEmailWithUsername("Carwash", "PayPal IPN", "Failure!!");
            }
        } else if(!strcmp($res, "INVALID")) {
            $mail_To = "bking@inbox.com";
            $mail_Subject = "PayPal - Invalid IPN";
            $mail_Body = "We had an INVALID response. 

The transaction ID number is $txn_id 

 username = $item_username";
            mail($mail_To, $mail_Subject, $mail_Body);
            sendEmailWithUsername("Carwash", "PayPal IPN", "Failure!!!!!!!!");
        }
    }
    fclose($fp);
}
?>

Button Code:

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo $ppemail; ?>">
<input type="hidden" name="item_name" value="<?php echo $pname; ?>">
<input type="hidden" name="item_number" value="<?php echo $id; ?>">
<input type="hidden" name="amount" value="<?php echo $prices[$id - 1] . ".00"; ?>">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but23.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!">
<img alt="" border="0" src="https://www.paypal.com/en_GB/i/scr/pixel.gif" width="1" height="1">
<!-- <div style="padding-top:100px; padding-right: 40%; padding-left: 40%;">
    <center><input type="submit" name="submit" class="btn" value="Checkout with PayPal"></center>
</div> -->
<input type="hidden" name="return"
       value="http://bvpn.biz/success.php?id=<?php echo $id; ?>&met=<?php echo $met; ?>">
<input type="hidden" name="cancel_return"
       value="http://bvpn.biz/success.php?id=<?php echo $id; ?>&met=<?php echo $met; ?>&do=2">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="notify_url" value="http://bvpn.biz/ipn.php"/>
<input type="hidden" name="custom" value="<?php echo $_SESSION['username'].'|'.$pid.'|'.getUserEmail($_SESSION["username"]); ?>">
</form>

Any help that you could supply would be great!

  • 写回答

1条回答 默认 最新

  • dqyhj2014 2013-07-24 04:18
    关注

    Try if(strcmp(trim($res), "VERIFIED") == 0)...

    According to this post here Paypal is sending VERIFIED response followed by when HTTP1.1 header is used. trim($res) solved the problem for me.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1