I'm getting the error "Item amount must add up to specified amount subtotal (or total if amount details not specified)"
from PayPal using the PHP SDK.
I know from reading the documentation that this error happens when the items total doesn't match the specified total. Except in my case, they do add up.
From reading other answers, I know that the items are tallied per-item. i.e the item's price * quantity, but the error still persists.
What's more interesting, though, is that this error occurs AFTER the user has already logged in and pressed the "Pay Now" button.
Here is the transaction object (as array):
`array (
'amount' => array (
'currency' => 'GBP',
'total' => '558.48',
'details' => array (
'shipping' => '0',
'tax' => '93.08',
'subtotal' => '465.40',
),
),
'item_list' => array (
'items' => array (
0 => array (
'name' => 'Q-Connect Premium White A4 90gsm Inkjet Paper (500 Pack) KF01090',
'currency' => 'GBP',
'quantity' => 50,
'price' => '7.49',
),
1 => array (
'name' => 'Stabilo Point 88 Fineliner Pen Black (Pack of 10 with 5 neon pens free) UK12/110-8846885',
'currency' => 'GBP',
'quantity' => 10,
'price' => '9.09',
),
),
),
)`
Please don't suggest that I remove shipping if it's £0.00 because I've already tried that and I still get the error if shipping is > 0
Tax is done on the subtotal + shipping. So in this case (465.40 + 0) * 1.2 = 558.48
Similarly, 465.40 + 93.08 + 0 = 558.48
I solved this problem.
You need to re-validate the payment after the "Pay Now" button has been clicked. On the second time round, I was sending the wrong amounts which is what caused the error. This is why it was happening after the payment was already sent through.