1
votes

For some reason I keep getting the following error in my logs when trying to authorise a PayPal payment using the SDK:

ERROR: Got Http response code 400 when accessing https://api.sandbox.paypal.com/v1/payments/payment. {"name":"VALIDATION_ERROR","details":[{"field":"transactions[0].amount","issue":"Transaction amount details (subtotal, tax, shipping) must add up to specified amount total"}],"message":"Invalid request - see details"

My transaction amount seems to add up fine so I don't know why PayPal is throwing an error, here is my transaction amount:

'transactions' => [
                0 => PayPal\Api\Transaction#5
                (
                    [PayPal\Common\PayPalModel:_propMap] => [
                        'amount' => PayPal\Api\Amount#6
                        (
                            [PayPal\Common\PayPalModel:_propMap] => [
                                'currency' => 'GBP'
                                'total' => '675.00'
                                'details' => PayPal\Api\Details#7
                                (
                                    [PayPal\Common\PayPalModel:_propMap] => [
                                        'fee' => '75.00'
                                        'subtotal' => '600.00'
                                    ]
                                )
                            ]
                        )
                        'item_list' => PayPal\Api\ItemList#8
                        (
                            [PayPal\Common\PayPalModel:_propMap] => [
                                'items' => [
                                    0 => PayPal\Api\Item#9
                                    (
                                        [PayPal\Common\PayPalModel:_propMap] => [
                                            'name' => 'Day 1: 30-12-2017'
                                            'currency' => 'GBP'
                                            'quantity' => 1
                                            'price' => '300.00'
                                        ]
                                    )
                                    1 => PayPal\Api\Item#10
                                    (
                                        [PayPal\Common\PayPalModel:_propMap] => [
                                            'name' => 'Day 2: 27-01-2018'
                                            'currency' => 'GBP'
                                            'quantity' => 1
                                            'price' => '300.00'
                                        ]
                                    )
                                ]
                            ]
                        )

Could it be something to do with the number_format function? I am using that function to ensure all values are consistant with their decimal places: $grandTotal = number_format($data['job']['grandTotalAmount'], 2, '.', '');

4

4 Answers

1
votes

I had this problem. In my case the solution was in right total and subtotal calculation:

subtotal has to be Price * Quantity

Whereas Total has to be Tax + shipping + subtotal

Don't just hardcode these fields.

Hope that'll help

0
votes

Remove your *.paypal.com cookies. This an unfortunate bug in the PayPal system, where the cookie gets too large and the server errors out on it. You can avoid the problem by using two different browsers, e.g. IE for PayPal Live and FF for the PayPal Sandbox. Check with incognito mode also.

0
votes

Fee is not included in the total calculation check.

This is a PayPal bug, not anything you are doing wrong. Simply add any fee to either the tax or the S&H (or even as a new line item).

0
votes

I had the same error, the reason was that I did not take into total and subtotal the promo code discount

Unfortunately, in PayPal SDK I did not find the ability to specify a discount, but there is an opportunity to add a product with a negative price

<?php

if ($discount > 0) {
    $item = new Item();
    $item->setName('Discount')
        ->setCurrency('USD')
        ->setQuantity(1)
        ->setPrice(number_format(-$discount, 2, '.', 0));
    $items[] = $item;
}