Paypal API:购物车项目金额的总数与订单金额不匹配

时间:2012-04-17 12:24:35

标签: php paypal express-checkout

我正在使用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"
);

如果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

我已经尝试了几个小时来修复它并放弃了。有人可以强调我需要做些什么才能让它发挥作用吗?

3 个答案:

答案 0 :(得分:24)

你错过了ITEMAMT。另请参阅Paypal Express checkout with shipping cost and error中的答案,其中包含多个数量的工作示例。

&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  

答案 1 :(得分:2)

直接与此问题相关,但由于在按错误消息搜索时首先出现在Google中,因此对于收到此错误的其他人可能会有用。

如果未设置某些字段(null /空白),则可能会收到此错误。

例如在我的情况下,为了清晰起见,添加了换行符:

    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

它给了我同样的错误,即使金额很好。 我认为这是一个解析问题,因为如果你在L_PAYMENTREQUEST_0_NAME0 =之后插入一个空格

&L_PAYMENTREQUEST_0_NAME0=&L_PAYMENTREQUEST_0_AMT0=1.00

工作正常。

所以我的猜测是,在PayPal结束时,它只是将“& L_PAYMENTREQUEST_0_AMT0 = 1.00”分配给L_PAYMENTREQUEST_0_NAME0,从而有效地将其从消息中删除并因此触发此错误,因为没有该行,金额确实不会累加。

答案 2 :(得分:0)

我遇到了同样的麻烦并通过函数number_format为参数L_PAYMENTREQUEST_0_AMT $ k格式化foreach中的价格来解决它

示例:

$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);