driesvints / vat-calculator

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unsupported operand types: array * float

Fossil01 opened this issue · comments

commented

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
            ]
    ],
commented

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.

$taxKey = 'vat_calculator.rules.'.strtoupper($countryCode);

Fixed in: #156