0
頁面上有貝寶按鈕。有2個自定義字段與貝寶按鈕。我在ipn.php頁面上獲得IPN響應。我從貝寶網站得到了這段代碼。PHP - 貝寶IPN集成問題
當我使用SandBox進行測試時,支付是從買方帳戶中推導出來的,並存入商家帳戶。但是數據並沒有被插入到我在下面最後提到的代碼中提到的數據庫表中。我也嘗試在名爲「custom」的單個變量中發送這兩個變量值,但仍然沒有運氣。請檢查我的代碼,並讓我知道我在做什麼錯誤。請幫助我,因爲我在過去的兩天掙扎。
$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]);
}
$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";
}
$ch = curl_init('https://www.sandbox.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");
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'];
$custom_memname = $_POST['custom_memname']; // This is 1st custom variable
$custom_mempass = $_POST['custom_mempass']; // This is 2nd custom variable
$str_query_insert="insert into t_fmember(memberid,password) values('" .$custom_memname."','".$custom_mempass."')";
ExecuteQuery($str_query_insert);
}
我加入這個代碼我ipn.php網頁上使用IPN模擬器,但沒有得到任何迴應呢。
$post_data_string = serialize($_POST);
mail('[email protected]', 'PayPal IPN', $post_data_string);
如果可能,請進一步幫助。謝謝
愚蠢的問題,但你知道,在沙箱模式PayPal不會發送IPN響應到您的服務器不是嗎?您需要在開發人員工具中使用IPN模擬器。 – toomanyredirects 2013-02-21 10:39:46
我接受問題的愚蠢,但我沒有線索,所以我會做你的建議。非常感謝你。 – KRA 2013-02-21 10:45:48
沒問題。我已重新張貼爲答案,如果這解決了您的問題,請接受。 – toomanyredirects 2013-02-21 10:47:35