我已经为此工作了一段时间,但尚未找到解决方案。我正在尝试使 PayPal IPN 工作,但尚未成功。首先,我在连接 SSL 时遇到了一些问题,所以我暂时不用它。在那之后,我似乎遇到了其他问题。我继续添加了一些调试,发现我卡在了 VERIFY 检查中。这就是我所知道的一切。
下面是我的 PayPal IPN,下面是我的按钮代码。
<?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\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n"; // www.sandbox.paypal.com for a test site
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
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 .= "\n HTTP ERROR. \n";
} 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. \n\nThe transaction ID number is :$txn_id \n\nPayment status is: $payment_status \n\nPayment amount is: $payment_amount \n\nIf 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. \n\nThe transaction ID number is $txn_id \n\n username = $item_username";
mail($mail_To, $mail_Subject, $mail_Body);
sendEmailWithUsername("Carwash", "PayPal IPN", "Failure!!!!!!!!");
}
}
fclose($fp);
}
?>
按钮代码:
<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>
您能提供的任何帮助都会很棒!