PHP code example of mpociot / vat-calculator

1. Go to this page and download the library: Download mpociot/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/ */

    

mpociot / vat-calculator example snippets


// Easy to use!
VatCalculator::calculate(24.00, $countryCode = 'DE');
VatCalculator::calculate(24.00, $countryCode, $postalCode);
VatCalculator::calculate(71.00, 'DE', '41352', $isCompany = true);
VatCalculator::getTaxRateForLocation('NL');

// Check validity of a VAT number
VatCalculator::isValidVATNumber('NL123456789B01');

use Mpociot\VatCalculator\VatCalculator;

$vatCalculator = new VatCalculator();
$vatCalculator->setBusinessCountryCode('DE');
$grossPrice = $vatCalculator->calculate(49.99, $countryCode = 'LU');

$grossPrice = VatCalculator::calculate(24.00, 'DE');

$grossPrice = VatCalculator::calculate(24.00, 'DE', '12345', $isCompany = true);

$grossPrice = VatCalculator::calculate(24.00, 'DE'); // 28.56
$taxRate = VatCalculator::getTaxRate(); // 0.19
$netPrice = VatCalculator::getNetPrice(); // 24.00
$taxValue = VatCalculator::getTaxValue(); // 4.56

if (VatCalculator::shouldCollectVAT('DE')) {
    // This country code 

try {
    $validVAT = VatCalculator::isValidVATNumber('NL 123456789 B01');
} catch (VATCheckUnavailableException $e) {
    // The VAT check API is unavailable...
}

// This check will return false because no connection to VIES could be made...
$validVAT = VatCalculator::isValidVATNumber('NL 123456789 B01');

// This check will return true because only the format is checked...
$validVAT = VatCalculator::isValidVatNumberFormat('NL 123456789 B01');

try {
    $vat_details = VatCalculator::getVATDetails('NL 123456789 B01');
    print_r($vat_details);
    /* Outputs
    stdClass Object
    (
        [countryCode] => NL
        [vatNumber] => 123456789B01
        [requestDate] => 2017-04-06+02:00
        [valid] => false
        [name] => Name of the company
        [address] => Address of the company
    )
    */
} catch (VATCheckUnavailableException $e) {
    // The VAT check API is unavailable...
}

try {
    $vat_details = VatCalculator::getVATDetails('GB 553557881');
    print_r($vat_details);
    /* Outputs
    array(3) {
        ["name"]=>
            string(26) "Credite Sberger Donal Inc."
        ["vatNumber"]=>
            string(9) "553557881"
        ["address"]=>
            array(3) {
                ["line1"]=>
                    string(18) "131B Barton Hamlet"
                ["postcode"]=>
                    string(8) "SW97 5CK"
                ["countryCode"]=>
                    string(2) "GB"
            }
    }
    */
} catch (VATCheckUnavailableException $e) {
    // The VAT check API is unavailable...
}



return [
    'forward_soap_faults' => true,
];



return [
    'soap_timeout' => 10,
];

use Mpociot\VatCalculator\Rules\ValidVatNumber;

$validator = Validator::make(Input::all(), [
    'first_name' => ')) {
    // Input is correct...
}

use Laravel\Cashier\Billable;
use Mpociot\VatCalculator\Traits\BillableWithinTheEU;
use Laravel\Cashier\Contracts\Billable as BillableContract;

class User extends Model implements BillableContract
{
    use Billable, BillableWithinTheEU {
        BillableWithinTheEU::taxPercentage insteadof Billable;
    }

    protected $dates = ['trial_ends_at', 'subscription_ends_at'];
}

$user = User::find(1);

// For individuals use:
$user->useTaxFrom('NL');

// For business customers with a valid VAT ID, use:
$user->useTaxFrom('NL')->asBusiness();

$user->subscription('monthly')->create($creditCardToken);
bash
php artisan vendor:publish --provider="Mpociot\VatCalculator\VatCalculatorServiceProvider"