driesvints / vat-calculator

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.
MIT License
1.2k stars 88 forks source link

Unsupported operand types: array * float #155

Closed ghost closed 1 year ago

ghost commented 1 year ago

When using custom tax rules I get this error on the calculate method: Unsupported operand types: array * float

When using 'TR' or 'NO' for example it does not work, but 'DE' works fine (built-in rate).

Seems to error out at: $this->taxValue = round($this->taxRate * $this->netPrice, 2);

It does indeed return an array instead of the direct value:

> VatCalculator::getTaxRateForLocation('DE');
= 0.21

> VatCalculator::getTaxRateForLocation('TR');
= [
    "rate" => 0.18,
  ]

Custom rules are identical in array format as the builtin ones:

return 
    'rules' => [
            'GB' => [ // United Kingdom
                'rate' => 0.20,
                'exceptions' => [
                    // UK RAF Bases in Cyprus are taxed at Cyprus rate
                    'Akrotiri' => 0.19,
                    'Dhekelia' => 0.19,
                ],
            ],
            'TR' => [ // Turkey
                'rate' => 0.18,
            ],
            'NO' => [ // Norway
                'rate' => 0.25
            ]
    ],
ghost commented 1 year ago

Looks like it gets the whole array key instead of just the rate value if requesting a country that only exists in the external config file.

https://github.com/driesvints/vat-calculator/blob/3b31ecd22b0685321909f32287889bc747a25930/src/VatCalculator.php#L756

Fixed in: https://github.com/driesvints/vat-calculator/pull/156