简体   繁体   English

Paypal PDT不会返回所有变量

[英]Paypal PDT is not returning all variables

I am new to Paypal Payment Data Transfer (PDT), and I am trying to get PDT to return the following variables and print them on the confirmation page: first_name, last_name, payer_email, payment_gross, item_number, item_name, payment_date. 我是Paypal付款数据传输(PDT)的新手,我试图让PDT返回以下变量并将其打印在确认页上:first_name,last_name,payer_email,payment_gross,item_number,item_name,payment_date。 I used the PHP code from Github to get PDT to work ( https://github.com/paypal/pdt-code-samples/blob/master/paypal_pdt.php ), and it is only returning the variables first_name, last_name, payer_email and payment_gross. 我使用Github上的PHP代码来使PDT正常工作( https://github.com/paypal/pdt-code-samples/blob/master/paypal_pdt.php ),它仅返回变量first_name,last_name,payer_email和payment_gross。 PDT doesn't return the variables payment_date, item_number and item_name. PDT不返回变量payment_date,item_number和item_name。 Can anyone see what is my problem? 谁能看到我的问题吗?

Here is the PHP code for the confirmation page, where users are returned after paying for an item on Paypal: 这是确认页面的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>");}
}

?>

Thank you for your help. 谢谢您的帮助。

Change this line if (strcmp ($lines[0], "SUCCESS") == 0) to this if (strcmp ($lines[1], "SUCCESS") == 0) 将此行if (strcmp ($lines[0], "SUCCESS") == 0)更改为if (strcmp ($lines[1], "SUCCESS") == 0)

And

Change this line else if (strcmp ($lines[0], "FAIL") == 0) to this else if (strcmp ($lines[1], "FAIL") == 0) 更改此行else if (strcmp ($lines[0], "FAIL") == 0)更改为else if (strcmp ($lines[1], "FAIL") == 0)

OR 要么

Simply replace by using much better code; 只需使用更好的代码进行替换即可; Change this line if (strcmp ($lines[0], "SUCCESS") == 0) to this if (stripos($lines, "SUCCESS") !== false) 将此行if (strcmp ($lines[0], "SUCCESS") == 0)更改为if (stripos($lines, "SUCCESS") !== false)

And

Again, with better code; 同样,具有更好的代码; Change this line else if (strcmp ($lines[0], "FAIL") == 0) to this if (stripos($lines, "FAIL") !== false) 将该行else if (strcmp ($lines[0], "FAIL") == 0)更改为if (stripos($lines, "FAIL") !== false)

That should do it! 那应该做! :-) :-)
It sucks that paypal likes to throw out wack code for us coders/developers to fix. 贝宝(Paypal)喜欢扔出古怪的代码供我们的编码人员/开发人员修复,这很糟糕。 Have a great day! 祝你有美好的一天!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM