News:

Support the VirtueMart project and become a member

Main Menu

Paypal Error - TAX_TOTAL_MISMATCH

Started by audiorock, May 13, 2024, 19:49:15 PM

Previous topic - Next topic

audiorock

Hi,

Joomla 4.4.4, VirtueMart 4.2.10 11010, PHP 8.1.27


I'm having a problem with PayPal payment. Confirming the payment the following error is released in FRONTEND (this active debugging on the front-end side is terrible for the customer who purchases!!!)
1 vmdebug createOrder no OrderId Var0:
stdClass Object
(
    [name] => UNPROCESSABLE_ENTITY
    [details] => Array
        (
            [0] => stdClass Object
                (
                    [field] => /purchase_units/@reference_id=='default'/amount/breakdown/tax_total/value
                    [value] => 69.78
                    [issue] => TAX_TOTAL_MISMATCH
                    [description] => Should equal sum of (tax * quantity) across all items for a given purchase_unit
                )

        )

    [message] => The requested action could not be performed, semantically incorrect, or failed business validation.
    [debug_id] => a2cd68df1e418
    [links] => Array
        (
            [0] => stdClass Object
                (
                    [href] => https://developer.paypal.com/docs/api/orders/v2/#error-TAX_TOTAL_MISMATCH
                    [rel] => information_link
                    [method] => GET
                )

        )

)
2 vmdebug Created order here
4 vmdebug vmInfo: Checkout blocked by Payment plugin
5 vmdebug Confirmed order returned false
7 vmdebug findCorrectItemidBySQL use as like en-GB `link` like "index.php?option=com_virtuemart&view=cart%"

Incorrect data has been entered


Can you help me, please?

audiorock


AH

Get the latest version of VM and the plugins - released a few days ago
Regards
A

Joomla 4.4.5
php 8.1

audiorock

#3
I have already installed the latest version of the VM plugin (4.2.10 11010) and the problem persists!

the problem only occurs when I add multiples of the same item to my cart.



Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

audiorock

Hi,

we use VAT set at 22% (operator VATtax +%) and discounts in some products (operator DBTax -%)


audiorock

Hi,
if it can be useful, with parameter "with Breakdown" in OFF, the problem not appears!


carlos88

#7
Hello, 
I am experiencing the exact same issue. 
I'm posting it here, but I'm not sure if it's better to open a ticket in my VirtueMart members area.

Joomla 5.1.4 + VM 4.2.18 11050

It seems that by setting "With Breakdown" to No, the issue is apparently resolved, but I don't think this is the optimal solution. Also, I haven't received any new orders with PayPal payments yet, so I'm not entirely sure that it's working properly now. 
The underlying problem is an error in VAT calculation. 
I'm attaching a screenshot of a customer order that couldn't be paid:

The VAT amount shown in the screenshot is €27.65. 
That amount matches what is sent to PayPal in the request, but according to my calculations, that amount is incorrect; it should be €27.47.

{
  "reference_id": "default",
  "amount": {
    "currency_code": "EUR",
    "value": "154.49",
    "breakdown": {
      "shipping": {
        "currency_code": "EUR",
        "value": "0"
      },
      "item_total": {
        "currency_code": "EUR",
        "value": "131.83"
      },
      "discount": {
        "currency_code": "EUR",
        "value": "4.81"
      },
      "tax_total": {
        "currency_code": "EUR",
        "value": "27.65"
      }
    }
  }
}

The order details sent to PayPal in the request are:

"purchase_units": [
  {
    "reference_id": "default",
    "amount": {
      "currency_code": "EUR",
      "value": "154.49",
      "breakdown": {
        "shipping": {
          "currency_code": "EUR",
          "value": "0"
        },
        "item_total": {
          "currency_code": "EUR",
          "value": "131.83"
        },
        "discount": {
          "currency_code": "EUR",
          "value": "4.81"
        },
        "tax_total": {
          "currency_code": "EUR",
          "value": "27.65"
        }
      }
    },
    "description": "G2MB08277 jaltor.com",
    "custom_id": "G2MB08277",
    "items": [
      {
        "name": "HEBILLA 50X15 PLATEADA",
        "description": "0079",
        "quantity": 102,
        "unit_amount": {
          "currency_code": "EUR",
          "value": "0.5"
        },
        "tax": {
          "currency_code": "EUR",
          "value": "0.1"
        }
      },
      {
        "name": "HEBILLA 50X20 PLATEADA",
        "description": "0195",
        "quantity": 51,
        "unit_amount": {
          "currency_code": "EUR",
          "value": "0.41"
        },
        "tax": {
          "currency_code": "EUR",
          "value": "0.09"
        }
      },
      {
        "name": "PIQUETE 50-4.5 PLATEADO SOLDADO",
        "description": "0301",
        "quantity": 51,
        "unit_amount": {
          "currency_code": "EUR",
          "value": "0.58"
        },
        "tax": {
          "currency_code": "EUR",
          "value": "0.12"
        }
      },
      {
        "name": "CINTA 50MM POLIPROPILENO BLANCA ANIBAL",
        "description": "0184",
        "quantity": 41,
        "unit_amount": {
          "currency_code": "EUR",
          "value": "0.74"
        },
        "tax": {
          "currency_code": "EUR",
          "value": "0.16"
        }
      }
    ]
  }
]

And PayPal's response includes the following:

"body": {
  "name": "UNPROCESSABLE_ENTITY",
  "details": [
    {
      "field": "/purchase_units/@reference_id=='default'/amount/breakdown/tax_total/value",
      "value": "xxxxxx",
      "issue": "TAX_TOTAL_MISMATCH",
      "description": "Should equal sum of (tax * quantity) across all items for a given purchase_unit"
    }
  ],
  "message": "The requested action could not be performed, semantically incorrect, or failed business validation.",
  "debug_id": "",
  "links": [
    {
      "href": "https://developer.paypal.com/docs/api/orders/v2/#error-TAX_TOTAL_MISMATCH",
      "rel": "information_link",
      "method": "GET"
    }
  ]
}

Milbo

That is a rounding problem. And your items are an perfect example for that deeper math problem. You sell a product for 0.5 euro, 50 cent with quantity lets say 100 to make it easy.

So if you add a tax of 21% it would be 0.605, vm calculates it correct. But if you round that for the display and sum it up,... then you add 0.6 together. So for quantity 100 it is 60 and not 60.5 The 5 is removed due the rounding. The default mode in vm is to use for calculation the rounded steps. That is most time correct.

But in your case, you should use the other rounding mode, which you can set in the vm config tab pricing, in english "Round only display". The prices are correcter then, but sometimes the invoice can look wrong. because you get then lines like
0.5 plus 0.1 tax multiplied by 100 = 60.5 (and not 60). But your tax office should see the 60.5 as the right way, so you should change the rounding system.

To disable "with Breakdown" can have disadvantages for the vendor/shopper protection stuff, but actually, it can be also better.

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

carlos88

I'm a bit confused about this, sorry. 
I'm understanding that the correct setting is "Round only display" = No. 
This way, everything is rounded to 2 decimals internally in VM. 
Is that correct? 
With "Round only display" = No, PayPal will no longer return the "TAX_TOTAL_MISMATCH" error if I activate "with Breakdown."

Thank you.

Milbo

Yes it could work with breakdown if you use the "round only display", but it can be also the opposite. then you should use "round only display" and without breakdown.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/