2014-02-10 98 views
1

我是Paypal支付數據傳輸(PDT)的新手,我試圖讓PDT返回以下變量並在確認頁面上輸出:first_name,last_name,payer_email,payment_gross, item_number,item_name,payment_date。我使用Github的PHP代碼讓PDT工作(https://github.com/paypal/pdt-code-samples/blob/master/paypal_pdt.php),它只返回變量first_name,last_name,payer_email和payment_gross。 PDT不會返回變量payment_date,item_number和item_name。任何人都可以看到我的問題是什麼?PayPal PDT沒有返回所有變量

下面是確認頁面,在這裏用戶對貝寶的支付項目後返回的PHP代碼:

<?php 

$pp_hostname = "www.sandbox.paypal.com"; 


// read the post from PayPal system and add 'cmd' 
$req = 'cmd=_notify-synch'; 

$tx_token = $_GET['tx']; 
$auth_token = "O1UZLXPTewPRo9cWvtdU5fSEB0KH4PerJcyTKCJzj-yiZi2JOQzZcjwTf1G"; 
$req .= "&tx=$tx_token&at=$auth_token"; 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr"); 
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); 
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here, 
//if your server does not bundled with default verisign certificates. 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname")); 
$res = curl_exec($ch); 
curl_close($ch); 

if(!$res){ 
//HTTP ERROR 

echo ("<p><h3>ERROR!</h3></p>"); 

} 
else{ echo ("<p><h3>THIS WOKRED!</h3></p>"); 
// parse the data 
$lines = explode("\n", $res); 
$keyarray = array(); 
if (strcmp ($lines[0], "SUCCESS") == 0) { 
for ($i=1; $i<count($lines);$i++){ 
list($key,$val) = explode("=", $lines[$i]); 
$keyarray[urldecode($key)] = urldecode($val); 
} 
// check the payment_status is Completed 
// check that txn_id has not been previously processed 
// check that receiver_email is your Primary PayPal email 
// check that payment_amount/payment_currency are correct 
// process payment 
$firstname = $keyarray['first_name']; 
$lastname = $keyarray['last_name']; 
$itemname = $keyarray['item_name']; 
$amount = $keyarray['payment_gross']; 
$itemnumber = $keyarray['item_number']; 
$payeremail = $keyarray['payer_email']; 
$paymentdate = $keyarray['payment_datel']; 


echo ("<p><h3>Thank you for your purchase!</h3></p>"); 

echo ("<b>Payment Details</b><br>\n"); 
echo ("<li>Name: $firstname $lastname</li>\n"); 
echo ("<li>Item: $itemname</li>\n"); 
echo ("<li>Amount: $amount</li>\n"); 
echo ("<li>Item Number: $itemnumber</li>\n"); 
echo ("<li>Payer Email: $payeremail</li>\n"); 
echo ("<li>Payment Date: $paymentdate</li>\n"); 

echo (""); 
} 
else if (strcmp ($lines[0], "FAIL") == 0) { 
// log for manual investigation 
echo ("<p><h3>ERROR NUMBER TWO!</h3></p>");} 
} 

?> 

謝謝您的幫助。

回答

0

改變這一行if (strcmp ($lines[0], "SUCCESS") == 0)這個if (strcmp ($lines[1], "SUCCESS") == 0)

而且

改變這一行else if (strcmp ($lines[0], "FAIL") == 0)這個else if (strcmp ($lines[1], "FAIL") == 0)

OR

只需使用更好的代碼替換; 此行if (strcmp ($lines[0], "SUCCESS") == 0)改成這樣if (stripos($lines, "SUCCESS") !== false)

而且

再次,更好的代碼; 更改此行else if (strcmp ($lines[0], "FAIL") == 0)至此if (stripos($lines, "FAIL") !== false)

這應該做到這一點! :-)
它吮吸貝寶喜歡拋出我們的編碼器/開發人員修復的怪異代碼。祝你有美好的一天!

+0

我遇到同樣的問題相同的問題,不幸的是這種解決方案並沒有爲我工作。 – Jeff