首页 文章

Paypal PDT没有返回所有变量

提问于
浏览
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 . 任何人都可以看到我的问题是什么?

以下是确认页面的PHP代码,用户在Paypal上支付项目后退回:

<?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>");}
}

?>

谢谢您的帮助 .

1 回答

  • 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)

    要么

    只需使用更好的代码替换;将此行 if (strcmp ($lines[0], "SUCCESS") == 0) 更改为此 if (stripos($lines, "SUCCESS") !== false)

    再次,使用更好的代码;将此行 else if (strcmp ($lines[0], "FAIL") == 0) 更改为此 if (stripos($lines, "FAIL") !== false)

    应该这样做! :-)
    Paypal喜欢抛弃wack代码让我们的程序员/开发人员修复它 . 祝你有美好的一天!

相关问题