dsbm49845 2012-01-18 22:37
浏览 53
已采纳

Paypal PHP NVP API - 购物车项目金额的总计与订单金额不匹配

I am having an issue with the totals on my custom paypal shopping cart. Using the PHP NVP API I get:

TIMESTAMP: 2012-01-18T07:27:10Z
CORRELATIONID: d1fac4fa784ef
ACK: Failure
VERSION: 84.0
BUILD: 2271164
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

However, I know my totals should be correct. Here is the PHP:

$count = sizeof($cartItem);
$subtotal = 0;
$itmStr = '';
foreach($cartItem as $k = $ci)
{
  $sub = $ci['cart_amt']*$ci['cart_price'];
  $subtotal = $sub + $subtotal;

  $itmStr .= '&L_PAYMENTREQUEST_'.$k.'_NUMBER0='.$ci['cart_id'].'&L_PAYMENTREQUEST_'.$k.'_NAME0='.$ci['cart_item'].'&L_PAYMENTREQUEST_'.$k.'_AMT0='.$ci['cart_price'].'&L_PAYMENTREQUEST_'.$k.'_QTY0='.$ci['cart_amt'].'&L_PAYMENTREQUEST_'.$k.'_DESC0='.truncate($ci['cart_desc'], 25);
}

$subtotal = (float) $subtotal; 
if(round($subtotal) < 25)
{
  $ups_rate = (float) 9.95; 
  $usps_rate = (float) 7.50; 
} 

$ups_rate = number_format($ups_rate, 2, '.', ''); 
$usps_rate = number_format($usps_rate, 2, '.', ''); 
$_SESSION['ups_rate'] = $ups_rate; 
$_SESSION['usps_rate'] = $usps_rate; 
$ups_tot = $ups_rate + $subtotal; 
$usps_tot = $usps_rate + $subtotal; 
$_SESSION['ups_tot'] = $ups_tot; 
$_SESSION['usps_tot'] = $usps_tot; 
$_SESSION['subtotal'] = $subtotal; 
$base_total = $subtotal+$usps_rate; 
$handling = number_format((float) ($base_total*0.029) + .30, 2, '.', ''); 
$total = number_format($handling+$base_total, 2, '.', ''); 

$returnURL = append_sid("{$url}cart.php", 'mode=paypal_transaction&currencyCodeType='.urlencode($currencyCodeType).'&paymentType='.urlencode($paymentType)); 
$cancelURL = append_sid("{$url}cart.php", 'paymentType='.urlencode($paymentType)); 

$nvpstr = ""; 
$shiptoAddress = "&PAYMENTREQUEST_0_SHIPTONAME=$personName&PAYMENTREQUEST_0_SHIPTOSTREET=$SHIPTOSTREET&PAYMENTREQUEST_0_SHIPTOCITY=$SHIPTOCITY&PAYMENTREQUEST_0_SHIPTOSTATE=$SHIPTOSTATE&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=$SHIPTOCOUNTRYCODE&PAYMENTREQUEST_0_SHIPTOZIP=$SHIPTOZIP"; 

$nvpstr = '&ADDRESSOVERRIDE=1'.$shiptoAddress.'&MAXAMT='.(string)$total."&PAYMENTREQUEST_0_AMT=".(string)$total."&PAYMENTREQUEST_0_ITEMAMT=".(string)$subtotal.'&CALLBACKTIMEOUT=4&PAYMENTRREQUEST_0_HANDLINGAMT='.$handling.'&PAYMENTREQUEST_0_SHIPPINGAMT='.$usps_rate.'&ReturnUrl='.$returnURL.'&CANCELURL='.$cancelURL.'&PAYMENTINFO_0_CURRENCYCODE='.$currencyCodeType.'&PAYMENTREQUEST_0_PAYMENTACTION='.$paymentType.$itmStr; 

Using the code above, I call SetExpressCheckout with the following parameters:

&ADDRESSOVERRIDE=1&PAYMENTREQUEST_0_SHIPTONAME=test user&PAYMENTREQUEST_0_SHIPTOSTREET=123 somewhere st&PAYMENTREQUEST_0_SHIPTOCITY=mytown&PAYMENTREQUEST_0_SHIPTOSTATE=NC&PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE=US&PAYMENTREQUEST_0_SHIPTOZIP=12345&MAXAMT=64.71&PAYMENTREQUEST_0_AMT=64.71&PAYMENTREQUEST_0_ITEMAMT=50.64&CALLBACKTIMEOUT=4&PAYMENTRREQUEST_0_HANDLINGAMT=2.12&PAYMENTREQUEST_0_SHIPPINGAMT=11.95&ReturnUrl=http://xxxx/cart.php?mode=paypal_transaction&sid=XXX&CANCELURL=http://therealmsofwickedry.com/cart.php?mode=paypal_transaction&sid=XXX&PAYMENTINFO_0_CURRENCYCODE=USD&PAYMENTREQUEST_0_PAYMENTACTION=Sale&L_PAYMENTREQUEST_0_NUMBER0=3320&L_PAYMENTREQUEST_0_NAME0=ITem number 1&L_PAYMENTREQUEST_0_AMT0=47.32&L_PAYMENTREQUEST_0_QTY0=1&L_PAYMENTREQUEST_0_DESC0=No description available&L_PAYMENTREQUEST_1_NUMBER0=4605&L_PAYMENTREQUEST_1_NAME0=Item number 2&L_PAYMENTREQUEST_1_AMT0=3.32&L_PAYMENTREQUEST_1_QTY0=1&L_PAYMENTREQUEST_1_DESC0=No description available

Am I not passing a parameter? Have I encoded them incorrectly somehow? Any pointers would be greatly appreciated!

  • 写回答

1条回答 默认 最新

  • dongnius85154 2012-01-19 06:19
    关注

    You are repeating the same list item each time. For example, where you have 'NUMBER0', you should have 'NUMBER'.$c.'='...etc (where $c starts at 0 an increments each time thru the loop) The same holds for each of your AMT0, QTY0, and so on. As it is PayPal will only add one item to get its total, so you get a mathematical error if you have more than one in your total. I'm pretty new to this, so apologies if I've misunderstood

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教