diff --git a/README.md b/README.md index a333af9e36..7367575b42 100644 --- a/README.md +++ b/README.md @@ -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 ================ @@ -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. diff --git a/composer.json b/composer.json index 33bd8b98c4..1058b92f15 100644 --- a/composer.json +++ b/composer.json @@ -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.*" }, diff --git a/src/Facades/Countries.php b/src/Facades/Countries.php index a30a2160ce..3becb1d818 100644 --- a/src/Facades/Countries.php +++ b/src/Facades/Countries.php @@ -8,7 +8,7 @@ class Countries extends Facade { protected static function getFacadeAccessor() { - return \DvK\Vat\Countries::class; + return \Ibericode\Vat\Countries::class; } } diff --git a/src/Facades/Rates.php b/src/Facades/Rates.php index af111b49b9..29c8f6ef64 100644 --- a/src/Facades/Rates.php +++ b/src/Facades/Rates.php @@ -8,7 +8,7 @@ class Rates extends Facade { protected static function getFacadeAccessor() { - return \DvK\Vat\Rates\Rates::class; + return \Ibericode\Vat\Rates::class; } } diff --git a/src/Facades/Validator.php b/src/Facades/Validator.php index 31708b7b33..9ac49470f2 100644 --- a/src/Facades/Validator.php +++ b/src/Facades/Validator.php @@ -8,7 +8,7 @@ class Validator extends Facade { protected static function getFacadeAccessor() { - return \DvK\Vat\Validator::class; + return \Ibericode\Vat\Validator::class; } } diff --git a/src/Rules/Country.php b/src/Rules/Country.php index a711c35df6..768765fede 100644 --- a/src/Rules/Country.php +++ b/src/Rules/Country.php @@ -16,7 +16,7 @@ class Country implements Rule */ public function passes($attribute, $value) { - $countries = Countries::all(); + $countries = new Countries(); return isset($countries[$value]); } @@ -29,4 +29,4 @@ public function message() { return __('The :attribute must be a valid country.'); } -} \ No newline at end of file +} diff --git a/src/Rules/VatNumber.php b/src/Rules/VatNumber.php index 53a3452799..0d930d8266 100644 --- a/src/Rules/VatNumber.php +++ b/src/Rules/VatNumber.php @@ -16,7 +16,7 @@ class VatNumber implements Rule */ public function passes($attribute, $value) { - return Validator::validate($value); + return Validator::validateVatNumber($value); } /** @@ -28,4 +28,4 @@ public function message() { return __('The :attribute must be a valid VAT number.'); } -} \ No newline at end of file +} diff --git a/src/VatServiceProvider.php b/src/VatServiceProvider.php index 944c3310b7..7a8483da98 100644 --- a/src/VatServiceProvider.php +++ b/src/VatServiceProvider.php @@ -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 { diff --git a/tests/FacadesTest.php b/tests/FacadesTest.php index 23ff6d1f40..e09334730f 100644 --- a/tests/FacadesTest.php +++ b/tests/FacadesTest.php @@ -6,9 +6,9 @@ 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; @@ -16,16 +16,16 @@ 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')); } -} \ No newline at end of file +}