Reputation: 13511
I try to get the token for the PayPal by providing the following data in 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
)
This is the code that generating the above array values:
$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>";
and I get the following result from 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
)
Can you see anything wrong in that code ? Is there anybody who can help me ?
After a long time research in my code, I have see that the issue comes from the decimal digits in my numbers. The issue is that I don't know what exactly is the wrong with the decimals :(
Thanks
Upvotes: 1
Views: 5514
Reputation: 1276
check whether any amount value does not have more than two decimal for example "12.123" not valid amount whereas "12.12" is valid amount.
while preparing the cart than total amount of the cart+extras(tax+shipping) must be equal to total amount
Upvotes: 1
Reputation: 26036
ITEMAMT + TAXAMT + SHIPPINGAMT + HANDLINGAMT must equal AMT.
ITEMAMT should be the subtotal of just the items, but you're only passing a 1 there.
Also, you have a QTY of 19.27. I've never tested specifically to see if they'll accept QTY values like that, but even if they do, your ITEMAMT should be 7.32.
In this case, you're not passing the other values, so your ITEMAMT and AMT would be the same. That 1 you're passing there is causing the error you're getting because it doesn't add up to your AMT.
Upvotes: 2
Reputation: 7655
Look at the error message: The totals of the cart item amounts do not match order amounts.
The numbers you send to PayPal are incorrect. (are you sure your calculations are correct?)
Upvotes: 1