我尝试通过在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
)
您能在该代码中看到任何错误吗?有谁可以帮助我吗?
经过对代码的长时间研究,我发现问题出在我的数字中的十进制数字上。问题是我不知道小数点到底有什么问题:(
谢谢
最佳答案
ITEMAMT + TAXAMT + SHIPPINGAMT + HANDLINGAMT必须等于AMT。
ITEMAMT应该只是项目的小计,但是您只在其中传递了1。
另外,您的数量为19.27。我从未专门测试过它们是否会接受这样的QTY值,但是即使它们接受了,您的ITEMAMT也应该为7.32。
在这种情况下,您没有传递其他值,因此您的ITEMAMT和AMT相同。您在那儿传递的那1会导致您得到错误,因为它不会加到您的AMT上。