2012-10-29 104 views
4

我將PayPal與IPN集成在一起(我曾在很多網站上完成此操作,之前從未遇到過這個問題。)我使用PHP Paypal IPN集成類 - Micah Carrick。IPN驗證失敗

我正在沙盒帳戶上測試它。 我從貝寶收到的所有數據都沒有問題。但總是IPN驗證失敗。

我在很多項目上都使用過相同的類,但從來沒有遇到過這個問題,請指導我,這個問題可能是什麼原因。

這是我在日誌文件中我得到:

[10/29/2012 5:02 AM] - FAIL: IPN Validation Failed. 
IPN POST Vars from Paypal: 
mc_gross=10.00, protection_eligibility=Eligible, address_status=confirmed, payer_id=LZ3J5RXT7ZRSW, tax=0.00, address_street=1 Main St, payment_date=03:02:41 Oct 29, 2012 PDT, payment_status=Completed, charset=windows-1252, address_zip=95131, first_name=AProfessionals, mc_fee=0.59, address_country_code=US, address_name=AProfessionals Inc, notify_version=3.7, custom=, payer_status=verified, [email protected], address_country=United States, address_city=San Jose, quantity=1, verify_sign=AV0bkFkV43dlmXuqlWjyHTfWE.SBANTBgLiHNABcsVQsMvyhdLQg8mTi, [email protected], txn_id=9ES74523RB953760X, payment_type=instant, last_name=Inc, address_state=CA, [email protected], payment_fee=0.59, receiver_id=NEV59MNUMBET6, txn_type=web_accept, item_name=Paypal Test Transaction, mc_currency=USD, item_number=, residence_country=US, test_ipn=1, handling_amount=0.00, transaction_subject=Paypal Test Transaction, payment_gross=10.00, shipping=0.00, ipn_track_id=74d5b2446aded, 

IPN Response from Paypal Server: 
HTTP/1.0 302 Found 
Location: https://www.sandbox.paypal.com 
Server: BigIP 
Connection: close 
Content-Length: 0 
+0

我試着IPN模擬器來檢查問題,我在我的日誌文件中得到這個錯誤:[29-Oct-2012 11:24:51 UTC] cURL錯誤:[77]問題與SSL CA證書(路徑?訪問權利?) –

+1

您是否在請求中使用「主機」標題?你有沒有看到貝寶的這個通知? https://www.x.com/developers/community/blogs/pp_mts_robertg/action-required-update-your-ipn-pdt-scripts – dbellizzi

+0

今天剛剛面臨同樣的問題。解決這篇文章:http://stackoverflow.com/questions/11746644/paypal-sandbox-ipn-always-returns-invalid/37630831#37630831 – Naguissa

回答

3

從我的經驗這就是爲什麼IPN驗證失敗

1)cmd=_notify-validate是附加的而不是前面加上3個常見的原因......這有時會造成問題。因此,而不是:

$post_string = '';  
    foreach ($_POST as $field=>$value) { 
    $this->ipn_data["$field"] = $value; 
    $post_string .= $field.'='.urlencode(stripslashes($value)).'&'; 
    } 
    $post_string.="cmd=_notify-validate"; // append ipn command 

按照代碼此頁上:https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

// read the post from PayPal system and add 'cmd' 
$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"; 
} 

2)地址是多襯裏。

// read post data from PayPal and add 'cmd' 
$req = 'cmd=_notify-validate'; 
foreach ($_POST as $key => $value) 
{ 
    // put line feeds back to CR+LF as that's how PayPal sends them out 
    // otherwise multi-line data will be rejected as INVALID 
    $value = str_replace("\n", "\r\n", $value); 
     $this->ipn_data_arr[$key] = $value; 
     $req .= '&'.$key.'='.urlencode(stripslashes($value)); 
    } 

您可以去您的PayPal ACC,並從1號線更改爲2線和使用ACC辦理測試這個自己。 2號線慘遭失敗,但不會$value = str_replace("\n", "\r\n", $value);大家都知道爲什麼貝寶並沒有在他們的示例代碼行...

3)用戶在他們的姓名,地址非英文字符等(可能並不適用於你,但因爲我們的話題)

看到:http://blog.tentaclesoftware.com/archive/2010/04/09/87.aspx 的主要觀點是:

Log into PayPal 
Click the ‘Profile’ link in the menu bar under ‘My Account’ 
Click the ‘Language Encoding’ link under the ‘Selling Preferences’ column 
Click ‘More Options’ 
Set ‘Encoding’ to ‘UTF-8’ 
Click ‘Save’ 

如果您發現有在所有3一個共同的主題:數據的順序,數據的編碼,如果只是一件小事情略有不同,它會失敗。所以如果不是這三個理由,請按照這些思路來思考。查找並檢查該字段其數據將有可能導致問題......非標準的字符,隱元數據等

+0

代碼示例移動到http://paypal.github.io/sdk/sample -apps/ espcially https://github.com/paypal/ipn-code-samples – staabm

2

在貝寶的庫而改變一件事

//打開連接到PayPal

$fp = fsockopen(‘ssl://’.$url_parsed[host],「443」,$err_num,$err_str,30); 

//$fp = fsockopen($url_parsed[host],「80」,$err_num,$err_str,30);