2014-08-27 120 views
1

正如標題所述,我遇到了Paypal問題,並且IPN返回已通過訂閱支付方式進行驗證。對於我迄今爲止所完成的每個訂閱IPN,它都已返回INVALID與數據。事情是,對於相同的確切代碼,將按鈕從_xclick-subscriptions更改爲_donations例如給我一個VERIFIED結果。Paypal訂閱IPN退回無效

我一直在尋找一些時間來解決我的問題,但我一直無法找到一個。這就是發生了什麼 - 我已經創建了訂閱按鈕,該按鈕引導用戶到PayPal(在這種情況下,沙箱),然後他們付費,並在他們付費後,他們可以選擇返回到網站。這是按鈕的代碼。

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post"> 
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but20.gif" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> 
<input type="hidden" name="cmd" value="_xclick-subscriptions"> 
<input type="hidden" name="business" value="[email protected]"> 
<input type="hidden" name="item_name" value="Monthly Sub"> 
<input type="hidden" name="no_note" value="1"> 
<input type="hidden" name="currency_code" value="USD"> 
<input type="hidden" name="a3" value="10.00"> 
<input type="hidden" name="p3" value="1"> 
<input type="hidden" name="t3" value="M"> 
<input type="hidden" name="src" value="1"> 
<input type="hidden" name="sra" value="1"> 
<input type="hidden" name="rm" value="2"> 
<input type="hidden" name="return" value="http://url.com/thanks.php"> 
</form> 

因爲這一直是一個體面的問題,對我來說我已經打破了按鈕縮小到具有非常準系統所需的值,直到我能真正得到它返回驗證,而不是無效的。 以下是我作爲IPN偵聽器的代碼。

define("DEBUG", 1); 
define("USE_SANDBOX", 1); 
define("LOG_FILE", "./ipn.log"); 
// Read POST data 
// reading posted data directly from $_POST causes serialization 
// issues with array data in POST. Reading raw POST data from input stream instead. 
$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]); 
} 
// 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"; 
} 
// Post IPN data back to PayPal to validate the IPN data is genuine 
// Without this step anyone can fake IPN data 
if(USE_SANDBOX == true) { 
    $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr"; 
} else { 
    $paypal_url = "https://www.paypal.com/cgi-bin/webscr"; 
} 
$ch = curl_init($paypal_url); 
if ($ch == FALSE) { 
    return FALSE; 
} 
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); 
if(DEBUG == true) { 
    curl_setopt($ch, CURLOPT_HEADER, 1); 
    curl_setopt($ch, CURLINFO_HEADER_OUT, 1); 
} 
// Set TCP timeout to 30 seconds 
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close')); 
$res = curl_exec($ch); 
if (curl_errno($ch) != 0) // cURL error 
    { 
    if(DEBUG == true) { 
     error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE); 
    } 
    curl_close($ch); 
    exit; 
} else { 
     // Log the entire HTTP response if debug is switched on. 
     if(DEBUG == true) { 
      error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $req" . PHP_EOL, 3, LOG_FILE); 
      error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $res" . PHP_EOL, 3, LOG_FILE); 
      // Split response headers and payload 
      list($headers, $res) = explode("\r\n\r\n", $res, 2); 
     } 
     curl_close($ch); 
} 
// Inspect IPN validation result and act accordingly 
if (strcmp ($res, "VERIFIED") == 0) { 
    if(DEBUG == true) { 
     error_log(date('[Y-m-d H:i e] '). "Verified IPN: $req ". PHP_EOL, 3, LOG_FILE); 
    } 
} else if (strcmp ($res, "INVALID") == 0) { 
    if(DEBUG == true) { 
     error_log(date('[Y-m-d H:i e] '). "Invalid IPN: $req" . PHP_EOL, 3, LOG_FILE); 
    } 
} 

正如我剛纔所說,經覈實_donations回報,但_xclick-訂閱的CMD值返回無效的數據。我有一個這裏返回的數據的例子。

cmd=_notify-validate&txn_type=subscr_signup&subscr_id=I-SFYTVAKSSYGK&last_name=lastname&residence_country=US&mc_currency=USD&item_name=Monthly+Sub&business=mail%40url.com&amount3=10.00&recurring=1&address_street=1+Main+St&payer_status=verified&payer_email=name%40email.com&address_status=confirmed&first_name=firstname&receiver_email=mail%40url.com&address_country_code=US&payer_id=SYPW3V3BVWTJW&address_city=San+Jose&reattempt=1&address_state=CA&subscr_date=07%3A33%3A13+Aug+27%2C+2014+PDT&address_zip=95131&charset=windows-1252&period3=1+M&address_country=United+States&mc_amount3=10.00&address_name=firstname+lastname&auth=AwIHoldf-BK2GZqtPhPo0O2g3go74cV9ZOLRYhHTJdKDM5EP0YHuqHLo23RYPfQs-3YDnvhjVf.J3AtydGfvDfA&form_charset=UTF-8 

我真的不知道該從哪裏出去,所以任何和所有的幫助非常感謝!

+0

具有相同的問題。任何人都有解決方案? – 2014-08-31 17:48:53

+0

@MangirdasSkripka我想清楚我的問題是什麼。由於我正在一個新的網站上開發,我有htaccess阻止任何,但我的IP能夠看到該網站。在做了一天的IPN模擬測試以獲取IP地址後,貝寶用來發布數據,我認爲我擁有了所有這些數據。事實證明,我錯過了沙箱用於訂閱的付款,我不知道爲什麼,它與一次性付款不同。一旦我發現這一點,它就會繼續。因此,如果您使用htaccess阻止傳入的ips,請仔細檢查以及錯誤日誌。 – 2014-09-02 16:41:44

回答

0

經過另一整天的測試,我終於弄清楚是什麼導致了我的具體問題。事實證明,Paypal喜歡使用多個IP將信息從沙箱發佈到您的服務器。我正在使用htaccess來阻止所有,但我的IP地址查看網站(有一臺服務器,但我真的很接近上線,這是除了我打開網站的最後一件事)。抓住我認爲是PayPal沙箱IP的所有東西后,我在htaccess中打開了這些。事實證明,與一次性支付方式相比,Paypal使用不同的IP來發布訂閱方法中的數據。一旦我發現並添加到htaccess的IP,我的問題就消失了。