簡體   English   中英

Paypal訂閱IPN返回無效

[英]Paypal Subscription IPN Returning Invalid

如標題所示,貝寶(Paypal)出現問題,返回的IPN驗證了訂閱付款方式。 到目前為止,對於我進行的每個訂閱IPN,它都返回了帶有數據的INVALID。 問題是,對於相同的精確代碼,例如,將按鈕從_xclick-subscriptions更改為_donations會給我一個VERIFIED結果。

我一直在尋找時間來解決我的問題,但一直找不到。 這是正在發生的事情-我創建了一個訂閱按鈕,該按鈕會引導用戶進入Pay​​pal(在本例中為沙盒),然后由他們付款,付款后,他們可以選擇返回網站。 這是按鈕的代碼。

<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="mail@url.com"> 
<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的cmd值返回VERIFIED,但是_xclick-subscriptions返回帶有數據的INVALID。 我有一個返回的數據示例。

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

老實說,我不知道從這里開始應該走什么路,因此我們將不勝感激!

經過一整天的測試,我最終弄清楚了導致我特定問題的原因。 事實證明,Paypal喜歡使用多個IP將信息從沙箱發布到您的服務器。 我正在使用htaccess阻止除我的IP地址外的所有人查看該網站(擁有服務器,但我真的要上線了,這是禁止我打開網站的最后一件事)。 掌握了所有我認為的Paypal沙盒IP后,我在htaccess中打開了它們。 事實證明,與一次性付款方式相比,Paypal使用不同的IP來發布訂閱方式中的數據。 一旦發現該問題並將其添加到htaccess的IP中,我的問題就消失了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM