Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

Bump ibericode/vat to ^2.0 #37

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
39 changes: 16 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
> **HEADS UP** I suggest using [ibericode/vat](https://github.com/ibericode/vat) directly until #22 is tackled. Working with Laravel is not on my priority list so it would require someone else to send in a PR.

Laravel VAT
================

Expand Down Expand Up @@ -42,40 +40,35 @@ use DvK\Laravel\Vat\Facades\Validator;
use DvK\Laravel\Vat\Facades\Countries;

// Get current standard VAT rate for a country
Rates::country('NL'); // 21.00
Rates::getRateForCountry('NL'); // 21
Rates::getRateForCountry('NL', 'standard'); // 21

// Get reduced VAT rate
Rates::country('NL', 'reduced'); // 6.00
Rates::getRateForCountry('NL', 'reduced'); // 9

// Get reduced VAT rate on a given Date
Rates::country('NL', 'reduced', new \DateTime('2005-01-01')); // 19.00

// Get an array of rates in country code => rates format
Rates::all();
Rates::getRateForCountryOnDate('NL', new \DateTime('2010-01-01'), 'standard'); // 19.00

// Validate a VAT number by both format and existence
Validator::validate('NL50123'); // false
Validator::validateVatNumberFormat('NL203458239B01'); // true (checks format)

// Validate VAT number by format only
Validator::validateFormat('NL203458239B01'); // true

// Validate VAT number by existence (uses a remote HTTP service)
Validator::validateExistence('NL203458239B01') // false
Validator::validateVatNumber('NL203458239B01'); // false (checks format + existence)

// Get array of ISO-3316 country codes and country names
Countries::all(); // array of country codes + names
$countries = new Countries();

// Get name of country by ISO-3316 code
Countries::name('NL') // Netherlands
// access country name using array access
echo $countries['NL']; // Netherlands

// Get array of EU country codes + names
Countries::europe(); // array of EU country codes + names

// Check if ISO-3316 code is in EU
Countries::inEurope('NL'); // true
// loop over countries
foreach ($countries as $code => $name) {
// ...
}

// Get ISO-3316 code by IP address geo-location
Countries::ip('8.8.8.8'); // US
// check if country is in EU
$countries->isCountryCodeInEU('NL'); // true
$countries->isCountryCodeInEU('US'); // false
```

By default, VAT rates are cached for 24 hours using the default cache driver.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": ">=7.1",
"ibericode/vat": "^1.2",
"ibericode/vat": "^2.0",
"illuminate/contracts": "5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*",
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*|6.*|7.*|8.*|9.*"
},
Expand Down
2 changes: 1 addition & 1 deletion src/Facades/Countries.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Countries extends Facade {

protected static function getFacadeAccessor()
{
return \DvK\Vat\Countries::class;
return \Ibericode\Vat\Countries::class;
}

}
2 changes: 1 addition & 1 deletion src/Facades/Rates.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Rates extends Facade {

protected static function getFacadeAccessor()
{
return \DvK\Vat\Rates\Rates::class;
return \Ibericode\Vat\Rates::class;
}

}
2 changes: 1 addition & 1 deletion src/Facades/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Validator extends Facade {

protected static function getFacadeAccessor()
{
return \DvK\Vat\Validator::class;
return \Ibericode\Vat\Validator::class;
}

}
4 changes: 2 additions & 2 deletions src/Rules/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Country implements Rule
*/
public function passes($attribute, $value)
{
$countries = Countries::all();
$countries = new Countries();
return isset($countries[$value]);
}

Expand All @@ -29,4 +29,4 @@ public function message()
{
return __('The :attribute must be a valid country.');
}
}
}
4 changes: 2 additions & 2 deletions src/Rules/VatNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class VatNumber implements Rule
*/
public function passes($attribute, $value)
{
return Validator::validate($value);
return Validator::validateVatNumber($value);
}

/**
Expand All @@ -28,4 +28,4 @@ public function message()
{
return __('The :attribute must be a valid VAT number.');
}
}
}
6 changes: 3 additions & 3 deletions src/VatServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use DvK\Laravel\Vat\Facades\Validator as VatValidator;
use DvK\Laravel\Vat\Rules;

use DvK\Vat\Countries;
use DvK\Vat\Rates\Rates;
use DvK\Vat\Validator;
use Ibericode\Vat\Countries;
use Ibericode\Vat\Rates\Rates;
use Ibericode\Vat\Validator;

class VatServiceProvider extends ServiceProvider
{
Expand Down
14 changes: 7 additions & 7 deletions tests/FacadesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
use DvK\Laravel\Vat\Facades\Rates as RatesFacade;
use DvK\Laravel\Vat\Facades\Validator as ValidatorFacade;

use DvK\Vat\Countries;
use DvK\Vat\Rates\Rates;
use DvK\Vat\Validator;
use Ibericode\Vat\Countries;
use Ibericode\Vat\Rates;
use Ibericode\Vat\Validator;

use Orchestra\Testbench\TestCase;

class ServiceProviderTest extends TestCase
{
public function testCountries()
{
self::assertEquals((new Countries())->all(), CountriesFacade::all());
self::assertEquals(new Countries(), new CountriesFacade);
}

public function testRates()
{
self::assertEquals((new Rates())->all(), RatesFacade::all());
self::assertEquals((new Rates())->getRateForCountry('NL'), RatesFacade::getRateForCountry('NL'));
}

public function testValidator()
{
self::assertEquals((new Validator())->validateFormat('foobar'), ValidatorFacade::validateFormat('foobar'));
self::assertEquals((new Validator())->validateVatNumberFormat('foobar'), ValidatorFacade::validateVatNumberFormat('foobar'));
}
}
}