[英]php - PayPal IPN Not Working (on Sandbox)
更新:我什至嘗試將整個PHP腳本寫成一行,以在查看腳本時通過電子郵件發送給我,但仍然不通過電子郵件發送給我。
我已經嘗試了一切,或者感覺到了。 我已經設置了腳本(非常基本,因此我可以學習如何使用它)以根據IPN響應(完成,無效等)插入一行。
但是,它似乎沒有做任何事情。
我已經嘗試使用沙盒的內置IPN測試儀,但它沒有任何作用。 我嘗試使用基於沙箱的捐贈者按鈕,將“ notify_url”作為隱藏的輸入類型,但它不會執行任何操作。
實際插入一行的唯一時間是我直接通過瀏覽器訪問該文件時(當然是IPN文件)。 在這種情況下,它會插入一行以表示這是一筆無效的付款。
我在狄更斯做錯了什么,還是PayPal的沙盒暫時搞砸了?
<?php
require("../functions.php");
sql();
// read the post from PayPal system and add 'cmd'
$req = 'cmd=' . urlencode('_notify-validate');
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.sandbox.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HEADER, 0);
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_HTTPHEADER, array('Host: www.paypal.com'));
$res = curl_exec($ch);
curl_close($ch);
// 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 (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
// process payment
if($payment_status == "Completed") {
mysql_query("INSERT INTO donators (username)
VALUES ('completed')");
} else {
mysql_query("INSERT INTO donators (username)
VALUES ('wrong payment status')");
}
}
else if (strcmp ($res, "INVALID") == 0) {
mysql_query("INSERT INTO donators (username)
VALUES ('invalid')");
}
?>
捐贈形式:
<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="QJUZ2AGANUWYS">
<input name="notify_url" value="http://mysite.com/libs/paypal/ipn.php" type="hidden">
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
無效付款可能是由於您使用的是信用卡或沙盒帳戶模擬的信用卡。 if (strcmp ($res, "VERIFIED") == 0) {
,就可以丟掉條件了if (strcmp ($res, "VERIFIED") == 0) {
您就可以了。
我不知道沙盒內置的IPN測試器,很抱歉,這時也許有人會幫助您。
如此頁所述: https : //cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_api_nvp_r_GetExpressCheckoutDetails
“自63.0版起不推薦使用NOTIFYURL。請改用PAYMENTREQUEST_0_NOTIFYURL。”
此外,作為代碼注入點, 不要把你的IPN地址在你的HTML代碼。 任何人都可以查看它,因此知道文件的位置。 為了安全起見,請將其放在后台PHP腳本中, Paypal functions
文件中,函數調用ConfirmPayment
。
您是否嘗試過修剪$ res?
strcmp(trim($res), "VERIFIED")
代替
strcmp($res, "VERIFIED")
終於讓它為我工作了……
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.