public function getTaxRateForLocation($countryCode, $postalCode = null, $company = false, $type = null)
    {
        if ($company && strtoupper($countryCode) !== strtoupper($this->businessCountryCode)) {
            return 0;
        }
        $taxKey = 'vat_calculator.rules.'.strtoupper($countryCode);
        if (isset($this->config) && $this->config->has($taxKey)) {
            return $this->config->get($taxKey, 0);
        }

        if (isset($this->postalCodeExceptions[$countryCode]) && $postalCode !== null) {
            foreach ($this->postalCodeExceptions[$countryCode] as $postalCodeException) {
                if (!preg_match($postalCodeException['postalCode'], $postalCode)) {
                    continue;
                }
                if (isset($postalCodeException['name'])) {
                    return $this->taxRules[$postalCodeException['code']]['exceptions'][$postalCodeException['name']];
                }

                return $this->taxRules[$postalCodeException['code']]['rate'];
            }
        }

        if ($type !== null) {
            return isset($this->taxRules[strtoupper($countryCode)]['rates'][$type]) ? $this->taxRules[strtoupper($countryCode)]['rates'][$type] : 0;
        }

        return isset($this->taxRules[strtoupper($countryCode)]['rate']) ? $this->taxRules[strtoupper($countryCode)]['rate'] : 0;
    }
public function getTaxRateForLocation($countryCode, $postalCode = null, $company = false, $type = null)
    {
        if ($company && strtoupper($countryCode) !== strtoupper($this->businessCountryCode)) {
            return 0;
        }
        $taxKey = 'vat_calculator.rules.'.strtoupper($countryCode);
        if (isset($this->config) && $this->config->has($taxKey)) {
            return $this->config->get($taxKey, 0);
        }

        if (isset($this->postalCodeExceptions[$countryCode]) && $postalCode !== null) {
            foreach ($this->postalCodeExceptions[$countryCode] as $postalCodeException) {
                if (!preg_match($postalCodeException['postalCode'], $postalCode)) {
                    continue;
                }
                if (isset($postalCodeException['name'])) {
                    return $this->taxRules[$postalCodeException['code']]['exceptions'][$postalCodeException['name']];
                }

                return $this->taxRules[$postalCodeException['code']]['rate'];
            }
        }

        if ($type !== null) {
            return isset($this->taxRules[strtoupper($countryCode)]['rates'][$type]) ? $this->taxRules[strtoupper($countryCode)]['rates'][$type] : 0;
        }

        return isset($this->taxRules[strtoupper($countryCode)]['rate']) ? $this->taxRules[strtoupper($countryCode)]['rate'] : 0;
    }
public function getTaxRateForLocation ( $ countryCode , $ postalCode = null , $ company = false , $ type = null ) { if ( $ company && strtoupper ( $ countryCode ) !== strtoupper ( $ this -> businessCountryCode ) ) { return 0 ; } $ taxKey = 'vat_calculator.rules.' . strtoupper ( $ countryCode ) ; if ( isset ( $ this -> config ) && $ this -> config -> has ( $ taxKey ) ) { return $ this -> config -> get ( $ taxKey , 0 ) ; } if ( isset ( $ this -> postalCodeExceptions [ $ countryCode ] ) && $ postalCode !== null ) { foreach ( $ this -> postalCodeExceptions [ $ countryCode ] as $ postalCodeException ) { if ( ! preg_match ( $ postalCodeException [ 'postalCode' ] , $ postalCode ) ) { continue ; } if ( isset ( $ postalCodeException [ 'name' ] ) ) { return $ this -> taxRules [ $ postalCodeException [ 'code' ] ] [ 'exceptions' ] [ $ postalCodeException [ 'name' ] ] ; } return $ this -> taxRules [ $ postalCodeException [ 'code' ] ] [ 'rate' ] ; } } if ( $ type !== null ) { return isset ( $ this -> taxRules [ strtoupper ( $ countryCode ) ] [ 'rates' ] [ $ type ] ) ? $ this -> taxRules [ strtoupper ( $ countryCode ) ] [ 'rates' ] [ $ type ] : 0 ; } return isset ( $ this -> taxRules [ strtoupper ( $ countryCode ) ] [ 'rate' ] ) ? $ this -> taxRules [ strtoupper ( $ countryCode ) ] [ 'rate' ] : 0 ; }
Returns the tax rate for the given country code.
If a postal code is provided, it will try to lookup the different
postal code exceptions that are possible.

@param string      $countryCode
@param string|null $postalCode
@param bool|false  $company
@param string|null $type

@return float
Returns the tax rate for the given country code . If a postal code is provided it will try to lookup the different postal code exceptions that are possible .