Skip to content

Commit

Permalink
Ran Tests, Format and provided Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
BurtDS committed Jan 23, 2024
1 parent d14fee0 commit 03c1048
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 29 deletions.
17 changes: 2 additions & 15 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
# Changelog

All notable changes to `burtds/cash-converter` will be documented in this file
All notable changes to `burtds/laravel-vatnumber-checker` will be documented in this file

## 1.0.3 - 2023-10-24

- Downgrade the guzzle dependency

## 1.0.2 - 2023-10-23

- Move Laravel Pint to the dev dependencies

## 1.0.1 - 2023-10-23

- Exception Handling for Invalid API Key, Inactive Account and Quota Reached
- Cleanup all over the board

## 1.0.0 - 2023-10-22
## 1.0.0 - 202-01-23

- Initial release
60 changes: 59 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
info goes here
[![Latest Version on Packagist](https://img.shields.io/packagist/v/burtds/laravel-vatnumber-checker.svg?style=flat-square)](https://packagist.org/packages/burtds/laravel-vatnumber-checker)
[![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/burtds/laravel-vatnumber-checker/run-tests-pest.yml?branch=main&label=Tests)](https://github.com/burtds/laravel-vatnumber-checker/actions/workflows/run-tests-pest.yml)
[![Total Downloads](https://img.shields.io/packagist/dt/burtds/laravel-vatnumber-checker.svg?style=flat-square)](https://packagist.org/packages/burtds/laravel-vatnumber-checker)

## About laravel-vatnumber-checker

A small package that allows you to easily retrieve information associated with a VAT number.
Verification of validity, company name, and address of the company is only one api call away.

## How to use laravel-vatnumber-checker

### Installation

You can install the package via composer:
```bash
composer require burtds/laravel-vatnumber-checker
```
Afterwords, you're able to fetch your desired information.

### Usage

This packages uses an API provided by the European Commission called "[VIES](https://ec.europa.eu/taxation_customs/vies/#/vat-validation)".

We'll need to import the Facade of this package on top of your file.
```php
use Burtds\VatChecker\Facades\VatChecker
```
Once that is done, you'll be able to use the conversion functions.
**For this example we're using the VAT Number of Vulpo BV.
```php
VatChecker::getRawVatInstance('BE','0749617582'); // returns a raw response of the European Commission's API.
VatChecker::isVatValid('BE','0749617582'); // returns the validity of a VAT Number.
VatChecker::getCompanyName('BE','0749617582'); // returns the company name related to the VAT Number.
VatChecker::getCompanyAddress('BE','0749617582'); // returns the company address related to the VAT Number.
```

### Test & Format
For testing you can run:
```bash
composer test
```
For formatting the code using pint you can run:
```bash
composer format
```

## Security Vulnerabilities

If you discover a security vulnerability within this package, please send me an e-mail via [bert@bert.gent](mailto:bert@bert.gent).
I'll get back at you as soon as possible.

## Credits

- [Bert De Swaef](https://github.com/burtds)
- [All Contributors](../../contributors)

## License

This package is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
1 change: 0 additions & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

class Validator
{

public function __construct()
{

Expand Down
6 changes: 3 additions & 3 deletions src/VatEuropeApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ public function __construct(protected string $api)
public function retreiveVatInstance(string $countryCode, string $vatNumber): VatInstance
{
// $url = "{$this->api}/check-vat-number";
$url = "https://ec.europa.eu/taxation_customs/vies/rest-api/check-vat-number";
$url = 'https://ec.europa.eu/taxation_customs/vies/rest-api/check-vat-number';

$response = Http::post($url,[
$response = Http::post($url, [
'countryCode' => $countryCode,
'vatNumber' => $vatNumber
'vatNumber' => $vatNumber,
]);

$x = $response->json();
Expand Down
2 changes: 1 addition & 1 deletion src/VatnumberCheckerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function configurePackage(Package $package): void
public function packageBooted()
{
$this->app->bind(VatEuropeApi::class, function () {
$api = "https://ec.europa.eu/taxation_customs/vies/rest-api";
$api = 'https://ec.europa.eu/taxation_customs/vies/rest-api';

return new VatEuropeApi($api);
});
Expand Down
14 changes: 7 additions & 7 deletions tests/Feature/VatcheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@
use Burtds\VatChecker\Facades\VatChecker;

it('can get a valid VAT number', function () {
$vatinstance = VatChecker::getRawVatInstance('BE','0749617582');
$vatinstance = VatChecker::getRawVatInstance('BE', '0749617582');
expect(json_decode($vatinstance)->valid)->toBeTrue();
});

it('can get the company name from a valid vat number', function () {
$name = VatChecker::getCompanyName('BE','0749617582'); // Test with Vulpo's VAT Number
$name = VatChecker::getCompanyName('BE', '0749617582'); // Test with Vulpo's VAT Number
expect($name)->toBeString();
});

it('can get the company address from a valid vat number', function () {
$name = VatChecker::getCompanyAddress('BE','0749617582'); // Test with Vulpo's VAT Number
expect($name)->toBeString();
$address = VatChecker::getCompanyAddress('BE', '0749617582'); // Test with Vulpo's VAT Number
expect($address)->toBeString();
});

it('can get a valid state for a valid vat number', function () {
$name = VatChecker::isVatValid('BE','0749617582'); // Test with Vulpo's VAT Number
expect($name)->toBeTrue();
$isValid = VatChecker::isVatValid('BE', '0749617582'); // Test with Vulpo's VAT Number
expect($isValid)->toBeTrue();
});

it('fails with invalid vat number', function () {
$vatinstance = VatChecker::getRawVatInstance('BE','617582');
$vatinstance = VatChecker::getRawVatInstance('BE', '617582');
// expect(json_decode($vatinstance)->valid)->toBeFalse();

})->throws(VatNumberNotFound::class);
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Tests;

use Orchestra\Testbench\TestCase as BaseTestCase;
use Burtds\VatChecker\VatnumberCheckerServiceProvider;
use Orchestra\Testbench\TestCase as BaseTestCase;

class TestCase extends BaseTestCase
{
Expand Down

0 comments on commit 03c1048

Please sign in to comment.