php - 重定向到 PayPal 时出现 AMOUNT_ERROR - 旧的 PayPal 脚本
问题描述
我正在尝试更新使用 PayPal 结帐的旧脚本。该$auth_token
变量等于我的企业帐户的身份令牌。
if ($_REQUEST['do'] == 'receipt')
{
$request = 'cmd=_notify-synch';
$tx_token = $_REQUEST['tx'];
$auth_token = $configtoken;
$request .= "&tx=$tx_token&at=$auth_token";
$headerx .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$headerx .= "Content-Type: application/x-www-form-urlencoded\r\n";
$headerx .= "Host: www.paypal.com\r\n";
$headerx .= "Content-Length: " . strlen ($request) . "\r\n\r\n";
$sock = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
if (!$sock)
{
$file = fopen($config['log'] . $_REQUEST['tx'] . '.datatrans', "w", 0);
fputs($file, "HTTP ERROR\n");
fclose($file);
eval('$cartinfo .= "' . fetch_template('covercart_orderfailure') . '";');
} else
{
fputs($sock, $headerx . $request);
// read the body data
$result = '';
$headerdone = false;
while (!feof($sock))
{
$line = fgets($sock, 1024);
if (strcmp($line, "\r\n") == 0)
{
// read the header
$headerdone = true;
} else
if ($headerdone)
{
// header has been read. now read the contents
$result .= $line;
}
}
// parse the data
$lines = explode("\n", $result);
$keyarray = array();
if (!strcmp($lines[0], "SUCCESS") == 0)
{
$file = fopen($config['log'] . $_REQUEST['tx'] . '.datatrans', "w", 0);
fputs($file, "COULD NOT VALIDATE\n");
fclose($file);
eval('$cartinfo .= "' . fetch_template('covercart_orderfailure') . '";');
} else
{
for ($i = 1; $i < count($lines); $i++)
{
list($key, $val) = explode("=", $lines[$i]);
$keyarray[urldecode($key)] = urldecode($val);
}
$txn_id = $keyarray['txn_id'];
$item_name = $keyarray['item_name'];
$item_number = $keyarray['item_number'];
$payment_status = $keyarray['payment_status'];
$payer_email = $keyarray['payer_email'];
$product = explode("|", $item_number);
$item_array = explode("-", $product[1]);
$transamount = $_REQUEST['amt'];
$cm = urldecode($_REQUEST['cm']);
$transid = explode(":", $cm);
$transactionid = $transid[2];
$buyerid = $transid[0];
$transcookie = $transid[3];
$who = fetch_userinfo($buyerid);
$buyername = $who['username'];
$buyeremail = $who['email'];
$transamount = sprintf('%.2f', $transamount);
$mcgross = number_format(doubleval($_POST['mc_gross']), 2);
if ($item_name != 'renewal' and $transamount)
{
$verify = $db->query_first("SELECT amount FROM " . TABLE_PREFIX .
"covercartfraud WHERE transactionid='" . $transid[2] . "' AND userid='" . $buyerid .
"'");
if ($verify['amount'] <> $transamount)
{
$file = fopen($config['log'] . $_REQUEST['tx'] . '.datatrans', "w", 0);
fputs($file, "POSSIBLE FRAUD IP: " . $_SERVER['REMOTE_ADDR'] . " FROM PAYPAL: " .
$transamount . " VBCART TRANSACTION ID: " . $transid[2] . " USERID: " . $buyerid .
" FROM DB: " . $verify['amount'] . "\n");
fclose($file);
eval(standard_error(fetch_error('covercart_invalidamount')));
}
}
它走得更远,但我觉得我需要关注的部分就在顶部。因为那是它与 PayPal 通信的地方。
当我提交到 PayPal 时,它会将我发送到https://www.paypal.com/webapps/shoppingcart/error?flowlogging_id=3986eaa08f5be&code=AMOUNT_ERROR
并声明Things don't appear to be working at the moment. Please try again later.
我进行了以下更改,更新了标题并在 2 个位置添加了修剪(我认为是正确的),但是当我尝试结帐时仍然收到此错误。
$headerx .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$headerx .= "Content-Length: " . strlen($request) . "\r\n";
$headerx .= "Content-Type: application/x-www-form-urlencoded\r\n";
$headerx .= "Host: www.paypal.com\r\n";
$headerx .= "Connection: close\r\n\r\n";
//$sock = fsockopen('www.paypal.com', 80, $errno, $errstr, 30);
$sock = fsockopen( 'tls://ipnpb.paypal.com', 443, $errno, $errstr, 30);
if (!$sock)
{
$file = fopen($config['log'] . $_REQUEST['tx'] . '.datatrans', "w", 0);
fputs($file, "HTTP ERROR\n");
fclose($file);
eval('$cartinfo .= "' . fetch_template('covercart_orderfailure') . '";');
} else
{
fputs($sock, $headerx . $request);
// read the body data
$result = '';
$headerdone = false;
while (!feof($sock))
{
$line = fgets($sock, 1024);
if (strcmp(trim($line), "\r\n") == 0)
{
// read the header
$headerdone = true;
} else
if ($headerdone)
{
// header has been read. now read the contents
$result .= $line;
}
}
// parse the data
$lines = explode("\n", $result);
$keyarray = array();
if (!strcmp(trim($lines[0]), "SUCCESS") == 0)
我的网站和 PayPal 之间的通信哪里出错了?
更新:我深入研究了AMOUNT_ERROR
我在 url 中注意到的内容(这似乎很可疑),并发现我的输入$1.00
在需要发送时正在提交,从而1.00
删除了$
允许通过的过程。
解决方案
这是一个非常广泛的问题,所以我的回答将是广泛的。
从$request = 'cmd=_notify-synch';
直到$lines = explode("\n", $result);
它是对 PayPal 的 API 调用。因此,也许您可以从 PayPal 文档中查找该调用开始。并用 PayPal PHP SDK 替换代码的平静。该库将包含有关身份验证的信息,我假设它会告诉您将客户端 ID 和密码放在哪里。
推荐阅读
- python - 鼠标悬停后弹出时使用selenium和python提取数据
- javascript - webpack watch 双重编译节点模块
- python - 如何在 python 中将 datetime 转换为 unix 时间戳
- maven - 马文最大值 每个线程的测试数,并行运行时
- javascript - useState 函数不会立即更新
- javascript - 经典 Google 网站上的 HTML、CSS 和 JavaScript - 为什么视频录制不起作用?
- qt - 如何编写if语句比较在QML中有条件地创建对象的数字
- javascript - 使用 .map() 将查询到的数据从另一个数组传递到组件数组的构造中
- vega-lite - 如何使水平轴居中
- python-3.x - 如何在python3中使用正则表达式获取值