我尝试通过在PayPal中提供以下数据来获取PayPal的令牌:
Array
(
[PAYMENTREQUEST_0_CURRENCYCODE] => EUR
[PAYMENTREQUEST_0_INVNUM] => TLT-GR-1
[RETURNURL] => http://www.mysite.ext/my_app/payment-completed/
[CANCELURL] => http://www.mysite.ext/my_app/payment-canceled/
[PAYMENTREQUEST_0_PAYMENTACTION] => Sale
[SOLUTIONTYPE] => Sole
[L_PAYMENTREQUEST_0_NAME0] => Product Description
[L_PAYMENTREQUEST_0_AMT0] => 0.38
[L_PAYMENTREQUEST_0_QTY0] => 19.27
[PAYMENTREQUEST_0_AMT] => 7.32
[PAYMENTREQUEST_0_ITEMAMT] => 1
)
这是生成上述数组值的代码:
$data = array();
$data['PAYMENTREQUEST_0_CURRENCYCODE'] = $currencyCode;
$data['PAYMENTREQUEST_0_INVNUM'] = $order->ID;
$data['RETURNURL'] = $returnUrl;
$data['CANCELURL'] = $cancelUrl;
$data['PAYMENTREQUEST_0_PAYMENTACTION'] = 'Sale';
$data['SOLUTIONTYPE'] = 'Sole';
$subtotal = 0;
$tax = 0;
$counter = 0;
foreach($products as $product)
{
if($product->Type == 0) // Production is diretion
{
if($product->NightDuration == 0)
{
$price = round($product->Price , 2);
$qty = round($product->Qty , 2);
$data['L_PAYMENTREQUEST_0_NAME' . $counter] = $product->Title;
$data['L_PAYMENTREQUEST_0_AMT' . $counter] = $price;
$data['L_PAYMENTREQUEST_0_NUMBER' . $counter] = ($counter + 1);
$data['L_PAYMENTREQUEST_0_QTY' . $counter] = $qty;
$data['L_PAYMENTREQUEST_0_TAXAMT' . $counter] = round(($qty * $price) * ($taxPercentage / 100), 2);
$data['L_PAYMENTREQUEST_0_ITEMCATEGORY' . $counter] = 'Digital';
$subtotal += $qty * $price;
$tax += ($qty * $price) * ($taxPercentage / 100);
}
else
{
}
}
else
{
}
$counter++;
}
$data['PAYMENTREQUEST_0_AMT'] = round($subtotal + $tax, 2);
$data['PAYMENTREQUEST_0_ITEMAMT'] = 1;
$data['PAYMENTREQUEST_0_TAXAMT'] = round($tax, 2);
echo "<pre>";
print_r($data);
echo "</pre>";
$data = http_build_query($data, '', '&');
$pp = new TaxiBookingPayPal();
$rt = $pp->PPHttpPost('SetExpressCheckout', $data);
echo "<pre>";
print_r($rt);
echo "</pre>";
我从PayPal得到以下结果:
Array
(
[TIMESTAMP] => 2013%2d01%2d19T14%3a44%3a25Z
[CORRELATIONID] => bdfce7f34a1db
[ACK] => Failure
[VERSION] => 94
[BUILD] => 4181146
[L_ERRORCODE0] => 10413
[L_SHORTMESSAGE0] => Transaction%20refused%20because%20of%20an%20invalid%20argument%2e%20See%20additional%20error%20messages%20for%20details%2e
[L_LONGMESSAGE0] => The%20totals%20of%20the%20cart%20item%20amounts%20do%20not%20match%20order%20amounts%2e
[L_SEVERITYCODE0] => Error
)
你能看到那段代码有什么问题吗?有没有人可以帮助我?
经过长时间的研究,我发现问题来自我的数字中的十进制数字。问题是我不知道小数的确切错误:(
由于
答案 0 :(得分:2)
ITEMAMT + TAXAMT + SHIPPINGAMT + HANDLINGAMT必须等于AMT。
ITEMAMT应该只是项目的小计,但你只在那里传递1。
此外,您的数量为19.27。我从来没有专门测试过他们是否会接受这样的QTY值,但即使他们这样做,你的ITEMAMT应该是7.32。
在这种情况下,您没有传递其他值,因此您的ITEMAMT和AMT将是相同的。你正在通过的那个1导致你得到的错误,因为它没有加起来你的AMT。
答案 1 :(得分:1)
查看错误消息:购物车项目金额的总数与订单金额不匹配。
您发送给PayPal的号码不正确。 (你确定你的计算是正确的吗?)
答案 2 :(得分:1)
检查任何金额值是否不超过两位小数,例如“12.123”无效金额,而“12.12”是有效金额。
准备购物车时,购物车的总金额+额外费用(税金+运费)必须等于总金额