PHP code example of jakubjachym / vat-calculator

1. Go to this page and download the library: Download jakubjachym/vat-calculator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jakubjachym / vat-calculator example snippets


// Easy to use!
use JakubJachym\VatCalculator\VatCalculator;

$vatRates = new VatRates();
$vatCalculator = new VatCalculator($vatRates);
$vatCalculator->calculate(71.00, 'DE' /* $countryCode */, '41352' /* $postalCode or null */,  true /* Whether the customer you're calculating the VAT for is a company */);
$vatCalculator->getTaxRateForLocation('NL');
// Check validity of a VAT number
$vatCalculator->isValidVatNumber('NL123456789B01');

use JakubJachym\VatCalculator\VatCalculator;

$vatRates = new VatRates();
$vatCalculator = new VatCalculator($vatRates);
$vatCalculator->setBusinessCountryCode('DE');  // Where your company is based in
$price = $vatCalculator->calculate(49.99, 'LU', null, false);
$price->getPrice();
$price->getNetPrice();
$price->getTaxValue();
$price->getTaxRate();

$grossPrice = $vatCalculator->calculate(24.00, 'DE', null, false /* [, $rateType [, $dateTime]] */);

$grossPrice->getPrice();
$grossPrice->getNetPrice();
$grossPrice->getTaxValue();
$grossPrice->getTaxRate();


if ($vatCalculator->shouldCollectVat('DE')) {

}

if ($vatCalculator->shouldCollectEuVat('DE')) {

}

try {
	$validVat = $vatCalculator->isValidVatNumber('NL 123456789 B01');
} catch (VatCheckUnavailableException $e) {
	// Please handle me
}

try {
	$vat_details = $vatCalculator->getVatDetails('NL 123456789 B01');
	print_r($vat_details);
	/* Outputs VatDetails object, use getters to access values
	VatDetails Object
	(
		[valid:VatDetails:private] => false
		[countryCode:VatDetails:private] => NL
		[vatNumber:VatDetails:private] => 123456789B01
		[requestId:VatDetails:private] => FOOBAR338
	)
	*/
} catch (VatCheckUnavailableException $e) {
	// Please handle me
}

$vatRates = new VatRates();
$vatRates->getAllKnownRates('DE');

$vatRates = new VatRates();
$vatRates->addRateForCountry('NO');
$vatCalculator = new VatCalculator($vatRates);