php Paypal API:购物车项目金额的总和与订单金额不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10191209/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Paypal API: The totals of the cart item amounts do not match order amounts
提问by Rijndael
I am working with the paypal express checkout API and am having issues with setting the quantity. Below are my URI parameters:
我正在使用 paypal express checkout API 并且在设置数量时遇到问题。以下是我的 URI 参数:
$params = array(
'METHOD' => 'SetExpressCheckout',
'PAYMENTREQUEST_0_SHIPPINGAMT' => '0',
'PAYMENTREQUEST_0_TAXAMT' => '0',
'PAYMENTREQUEST_0_HANDLINGAMT' => '0',
'PAYMENTREQUEST_0_AMT' => "50.00",
'RETURNURL' => $this->_returnUri,
'CANCELURL' => $this->_cancelUri,
'HDRIMG' => $this->_logoUri,
'PAYMENTREQUEST_0_CURRENCYCODE' => 'GBP',
'L_PAYMENTREQUEST_0_DESC0' => 'Product description',
'L_PAYMENTREQUEST_0_NAME0' => 'Product name',
'L_PAYMENTREQUEST_0_AMT0' => "50.00",
'L_PAYMENTREQUEST_0_QTY0' => "2"
);
If L_PAYMENTREQUEST_0_QTY0 is set to 1 the process is fine. However, changing it to 2 and adding 'PAYMENTREQUEST_0_ITEMAMT' => "100.00" to the array gives me the following error:
如果 L_PAYMENTREQUEST_0_QTY0 设置为 1,则过程正常。但是,将其更改为 2 并将 'PAYMENTREQUEST_0_ITEMAMT' => "100.00" 添加到数组会给我以下错误:
TIMESTAMP: 2012-04-17T12:11:16Z
CORRELATIONID: da43f6c91254
ACK: Failure
VERSION: 88.0
BUILD: 2808426
L_ERRORCODE0: 10413
L_SHORTMESSAGE0: Transaction refused because of an invalid argument. See additional error messages for details.
L_LONGMESSAGE0: The totals of the cart item amounts do not match order amounts.
L_SEVERITYCODE0: Error
I have tried for hours on end to fix it and have given up. Can someone highlight want I need to do to get it to work ?
我已经尝试了几个小时来修复它并放弃了。有人可以强调我需要做什么才能让它工作吗?
回答by Robert
You're missing an ITEMAMT. See also my answer in Paypal Express checkout with shipping cost and errorwhich contains a working example with multiple quantities.
你缺少一个ITEMAMT. 另请参阅我在Paypal Express checkout 中的回答,其中包含运费和错误,其中包含一个具有多个数量的工作示例。
&L_PAYMENTREQUEST_0_NAME0=10% Decaf Kona Blend Coffee
&L_PAYMENTREQUEST_0_NUMBER0=623083
&L_PAYMENTREQUEST_0_DESC0=Size: 8.8-oz
&L_PAYMENTREQUEST_0_AMT0=9.95
&L_PAYMENTREQUEST_0_QTY0=2
&L_PAYMENTREQUEST_0_NAME1=Coffee Filter bags
&L_PAYMENTREQUEST_0_NUMBER1=623084
&L_PAYMENTREQUEST_0_DESC1=Size: Two 24-piece boxes
&L_PAYMENTREQUEST_0_AMT1=39.70
&L_PAYMENTREQUEST_0_QTY1=2
&PAYMENTREQUEST_0_ITEMAMT=99.30
&PAYMENTREQUEST_0_TAXAMT=2.58
&PAYMENTREQUEST_0_SHIPPINGAMT=3.00
&PAYMENTREQUEST_0_HANDLINGAMT=2.99
&PAYMENTREQUEST_0_SHIPDISCAMT=-3.00
&PAYMENTREQUEST_0_INSURANCEAMT=1.00
&PAYMENTREQUEST_0_AMT=105.87
&PAYMENTREQUEST_0_CURRENCYCODE=USD
回答by Zar Shardan
Not directlyrelated to the question, but since this comes up first in Google when searching by error message this might be useful to other people who are receiving this error.
与问题没有直接关系,但由于在通过错误消息搜索时首先出现在 Google 中,因此这可能对收到此错误的其他人有用。
You might be getting this error if some of the fields are not set(null/blank).
如果某些字段未设置(空/空白),您可能会收到此错误。
For instance in my case it was(line breaks added for clarity):
例如,就我而言,它是(为清楚起见添加了换行符):
PAYMENTREQUEST_0_PAYMENTACTION=Sale
&REQCONFIRMSHIPPING=0
&RETURNURL=some_url
&CANCELURL=some_other_url
&BRANDNAME=Brand
&L_PAYMENTREQUEST_0_NAME0=
&L_PAYMENTREQUEST_0_AMT0=1.00
&L_PAYMENTREQUEST_0_QTY0=1
&PAYMENTREQUEST_0_AMT=1.00
&PAYMENTREQUEST_0_CURRENCYCODE=USD
And it was giving me the same error, even though the amounts are fine. I think it is a parsing issue, because if you insert even a space after L_PAYMENTREQUEST_0_NAME0= in
即使数量很好,它也给了我同样的错误。我认为这是一个解析问题,因为如果你在 L_PAYMENTREQUEST_0_NAME0= 之后插入一个空格
&L_PAYMENTREQUEST_0_NAME0=&L_PAYMENTREQUEST_0_AMT0=1.00
It works fine.
它工作正常。
So my guess is that at the PayPal's end it just assigns "&L_PAYMENTREQUEST_0_AMT0=1.00" to L_PAYMENTREQUEST_0_NAME0, thus effectively removing it from the message and consequently triggers this error, since without that line the amounts do not add up indeed.
所以我的猜测是,在 PayPal 结束时,它只是将“&L_PAYMENTREQUEST_0_AMT0=1.00”分配给 L_PAYMENTREQUEST_0_NAME0,从而有效地将其从消息中删除并因此触发此错误,因为没有该行,金额确实不会加起来。
回答by realmag777
I had the same trouble and resolved it by formating prices in foreach by function number_format for parameter L_PAYMENTREQUEST_0_AMT$k
我遇到了同样的问题,并通过参数 L_PAYMENTREQUEST_0_AMT$k 的函数 number_format 在 foreach 中格式化价格来解决它
Example:
例子:
$items_amount = 0;
foreach ($products as $k => $product) {
$params["L_PAYMENTREQUEST_0_NAME$k"] = $product['name'];
$params["L_PAYMENTREQUEST_0_DESC$k"] = $product['desc'];
$params["L_PAYMENTREQUEST_0_AMT$k"] = number_format($product['priceIVA'], 2);
$params["L_PAYMENTREQUEST_0_QTY$k"] = $product['count'];
$items_amount += (floatval($product['priceIVA']) * $product['count']);
}
$params['PAYMENTREQUEST_0_AMT'] = $params['PAYMENTREQUEST_0_ITEMAMT'] = number_format($items_amount, 2);

