2013-02-04 36 views
1

我paypalipn.php文件看起來像甚至定期付款,貝寶:無效的IPN收到響應成功創建

<?php 

$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"; 
} 


// STEP 2: Post IPN data back to paypal to validate 

$ch = curl_init('https://www.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); 


// STEP 3: Inspect IPN validation result and act accordingly 

if (strcmp ($res, "VERIFIED") == 0) { 


    // 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']; 
} else if (strcmp ($res, "INVALID") == 0) { 

} 
?> 

我已實施貝寶進入我的應用程序。我可以成功獲取定期付款的個人資料ID,但是我從即時付款通知中得到的回覆無效。只有這個原因是我得到的,也沒有得到任何更多的錯誤消息。所以我一直在尋找你的幫助來得到這個......

+0

顯示你的代碼,請。 – monkeymatrix

回答

1

你在使用沙盒嗎?實時網站不會驗證沙盒中的IPN,反之亦然。如果IPN來自沙盒,您需要將其發送回沙盒進行驗證。

嘗試修改此代碼:

$ch = curl_init('https://www.paypal.com/cgi-bin/webscr'); 

要這樣:

if($myPost['test_ipn'] == "1") { 
    $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); 
} else { 
    $ch = curl_init('https://www.paypal.com/cgi-bin/webscr'); 
} 
+0

感謝馬特,我得到了它的工作,得到了答覆,驗證。但是,只有當我從貝寶做出退款的問題,但是對於最初的交易,我仍然得到了無效的答覆,請給我一個想法 –

+0

嗯...不確定。您可以在發生這種情況的交易中發佈交易ID嗎? –

+0

墊,我得到了正確的, –