user6811107
user6811107

Reputation:

PayPal PHP SDK Error - Item Amount Must Add Up To Specified Amount Subtotal

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

Upvotes: 1

Views: 1868

Answers (2)

user6811107
user6811107

Reputation:

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.

Upvotes: 1

Gianluca Ghettini
Gianluca Ghettini

Reputation: 11648

you are passing the values as strings instead of numbers. There may be some rounding error going on or something like that. Try as numbers and see what happens. Quantity is passed correctly as number

OR

You may have to take into account PayPal fees but I'm not quite sure about that

OR

Price may be not individual but aggregate, again, I'm not quite sure... double check

OR

In PHP the last comma should be omitted when declaring arrays (it may be optional, double check... PHP is quite loose on error reporting)

AND

PayPal SDK is really really poorly documented and cumbersome to work with unless you do very simple stuff like "pay now" html buttons. Go for stripe -> https://stripe.com

Upvotes: 1

Related Questions