我爲這個問題掙扎了幾天,但沒有成功,我相對 新的paypal ipn,但已經用它在過去幾個monhts成功,現在也許我是 做一些愚蠢的錯誤或PayPal沙箱ipn服務器是不負責任的。paypal ipn和mysql
付款處理正常,錢從買家帳戶轉到賣家,但仍沒有在數據庫中輸入詳細信息。
所以這是HTML表單代碼:
<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="sanboxselleremail">
<input type="hidden" name="item_name" value="Product">
<input type="hidden" name="item_number" value="1">
<input type="hidden" name="amount" value="15">
<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="EN">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<input type="hidden" name="return" value="http://mysite.com/testipn/">
<input type="hidden" name="cancel_return" value="http://mysite.com/testipn/">
<input type="hidden" name="rm" value="2">
<input type="hidden" name="notify_url" value="http://mysite.com/testipn/ipn.php" />
<input type="submit" value="submit" />
</form>
這是IPN的代碼,我發現在貝寶:
include('db.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.sandbox.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) {
if($payment_status=='Completed'){
$paylog = $db->query("INSERT INTO....);
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
我仔細檢查過的一切,我知道你必須回發所有的變量,所以我也檢查了它們。 sql語法沒有問題,因爲我測試了它,並且它輸入了我想要的數據庫表的 值。
您能否快速查看並指出您可能發現的任何錯誤?
謝謝。 這個問題造成了我很多時間和壓力... :(
謝謝。我現在會測試這個代碼:)並且會讓你知道。謝謝。 – inrob
我一直在試圖讓大家覺得不舒服。謝謝你的建議。對此,我真的非常感激。上帝保佑你,上帝保佑stackoverflow太:) – inrob