Giter VIP home page Giter VIP logo

vat-bundle's Introduction

VAT Bundle

Build Status Latest Stable Version PHP from Packagist Total Downloads License

This bundle allows you to use ibericode/vat in your Symfony projects.

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

The official VIES VAT number validation SOAP API is used for validating VAT numbers.

Installation

First, install the bundle using Composer.

composer require ibericode/vat-bundle

Then, load the bundle by adding it to your config/bundles.php file.

Ibericode\Vat\Bundle\VatBundle::class => ['all' => true]

Usage

Check out ibericode/vat for direct usage examples. This bundle adds service configuration & a validation constraint for VAT numbers.

Dependency injection

With this bundle enabled, you can use dependency injection to retrieve a class instance for the Countries, Validator, Rates or Geolocator classes.

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

class MyController 
{
    /**
     * Type-hint the class on your service constructors to retrieve a class instance
     */
    public function __construct(
        Rates $rates, 
        Validator $validator,
        Countries $countries, 
        Geolocator $geolocator
        )
    {
        $rates->getRateForCountry('NL'); // 21.00
        $validator->validateVatNumber('NL123456789B01'); // false
        $countries->isCountryCodeInEU('US') // false
        $geolocator->locateIpAddress('8.8.8.8'); // US
    }
}

Validation

To validate a VAT number using Symfony's Validation component, you can use the VatNumber constraint.

use Ibericode\Vat\Bundle\Validator\Constraints\VatNumber;

class Customer 
{
    /**
    * @VatNumber() 
    */
    public $vatNumber;
}

License

MIT licensed. See the LICENSE file for details.

vat-bundle's People

Contributors

dannyvankooten avatar arneee avatar jkobus avatar vincentlanglet avatar robinhoutevelts 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.