Paypal PDT 未返回所有变量

Posted

技术标签:

【中文标题】Paypal PDT 未返回所有变量【英文标题】:Paypal PDT is not returning all variables 【发布时间】:2014-03-08 08:36:42 【问题描述】:

我是 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】:

将此行 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 PDT 未返回所有变量的主要内容,如果未能解决你的问题,请参考以下文章

Paypal标准按钮不返回事务变量

PayPal 集成问题:PDT 在返回站点时挂起

Paypal 中的 IPN 与 PDT

Paypal 中的 IPN 与 PDT

nodejs 贝宝 pdt 返回 302

贝宝 PDT 缺少变量