Giter VIP home page Giter VIP logo

vat's Introduction

ibericode/vat

Build Status Latest Stable Version PHP from Packagist Total Downloads License

This is a simple PHP library to help you deal with Europe's VAT rules.

  • Fetch VAT rates for any EU member state using ibericode/vat-rates.
  • Validate VAT numbers (by format and/or existence)
  • Validate ISO-3316 alpha-2 country codes
  • Determine whether a country is part of the EU
  • Geo-locate IP addresses

Installation

PHP version 7.1 or higher with the CURL and JSON extension is required.

For VAT number existence checking, the PHP SOAP extension is required as well.

To get the latest stable version, install the package using Composer:

composer require ibericode/vat

Usage

This library exposes 4 main classes to interact with: Rates, Countries, Validator and Geolocator.

Retrieving VAT rates.

$rates = new Ibericode\Vat\Rates('/path-for-storing-cache-file.txt');
$rates->getRateForCountry('NL'); // 21
$rates->getRateForCountry('NL', 'standard'); // 21
$rates->getRateForCountry('NL', 'reduced'); // 9
$rates->getRateForCountryOnDate('NL', new \Datetime('2010-01-01'), 'standard'); // 19

This fetches rate from ibericode/vat-rates and stores a local copy that is periodically refreshed (once every 12 hours by default).

Validation

Validating a VAT number:

$validator = new Ibericode\Vat\Validator();
$validator->validateVatNumberFormat('NL203458239B01'); // true (checks format)
$validator->validateVatNumber('NL203458239B01'); // false (checks format + existence)

Validating an IP address:

$validator = new Ibericode\Vat\Validator();
$validator->validateIpAddress('256.256.256.256'); // false
$validator->validateIpAddress('8.8.8.8'); // true

Validating an ISO-3166-1-alpha2 country code:

$validator = new Ibericode\Vat\Validator();
$validator->validateCountryCode('DE'); // true
$validator->validateCountryCode('ZZ'); // false

Dealing with ISO-3166-1-alpha2 country codes

$countries = new Ibericode\Vat\Countries();

// access country name using array access
echo $countries['NL']; // Netherlands

// loop over countries
foreach ($countries as $code => $name) {
    // ...
}

// check if country is in EU
$countries->isCountryCodeInEU('NL'); // true
$countries->isCountryCodeInEU('US'); // false

Geo-location

This library includes a simple geo-location service using ip2c.org or ip2country.info.

$geolocator = new Ibericode\Vat\Geolocator();
$geolocator->locateIpAddress('8.8.8.8'); // US

To use ip2country.info explicitly.

$geolocator = new Ibericode\Vat\Geolocator('ip2country.info');
$geolocator->locateIpAddress('8.8.8.8'); // US

Or, to use ip2c.org explicitly.

$geolocator = new Ibericode\Vat\Geolocator('ip2c.org');
$geolocator->locateIpAddress('8.8.8.8'); // US

Symfony support

If you need to use this package in a Symfony environment, check out ibericode/vat-bundle.

License

ibericode/vat is licensed under the MIT License.

vat's People

Contributors

bpolaszek avatar coenjacobs avatar dannyvankooten avatar dixonl90 avatar franmomu avatar gemal avatar holtkamp avatar jarlskov avatar malengrin avatar marcsollie avatar mixislv avatar peter279k avatar swop avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.