Coder Social home page Coder Social logo

vat_validator's Introduction

This project is really old and unmaintained. It's kept here for legacy reasons.

We advice you to use this one instead : https://github.com/yolk/valvat

Description

Use this plugin to validate VAT numbers for European countries.

Basic Usage

To validate a model field as a valid intracom VAT number :

validates :vat_number, :vat => true

It may be optional like this :

validates :vat_number, :vat => true, :allow_blank => true

If you want the VAT number's country to match another kind of country field, use the 'country_method' option :

validates :vat_number, :vat => { :country_method => :my_method }

where it is supposed that your model has a method named 'my_method' which returns the country ISO code you want to match. The available country codes available for Europa are: DE, AT, BE, BG, CY, DK, ES, EE, FI, FR, EL, HU, IE, IT, LV, LT, LU, MT, NL, PL, PT, GB, RO, SK, SI, SE and CZ.

Example :

class Invoice < ActiveRecord::Base validates :vat_number, :vat => { :country_method => :country_code }

# Logic to return the country code
def country_code
  case country.downcase
    when 'belgium' then 'BE'
    when 'france'  then 'FR'
    when 'sweden'  then 'SE'
    # ...
    else nil
  end
end

end

Validating the Number at VIES

It's also possible to have the VAT number validated against Europa's VIES webservice. Simply use the :vies option like this :

validates :vat_number, :vat => { :vies => true }

Keep in mind that the webservice might be offline at some time for some countries. Check the VIES FAQ for more information about that.

Installation

In your project's Gemfile :

gem 'vat_validator'

= Tests

If you want to run the specs :

rake spec

Credits

This plugin in released under MIT license by Aurélien Malisart (see MIT-LICENSE file).

(c) http://aurelien.malisart.be

vat_validator's People

Contributors

jeroenj avatar

Stargazers

Janice Shiu avatar Nathan Hawes avatar Michel Pigassou avatar Thomas avatar  avatar Michael Schiller avatar  avatar Francois Stephany avatar Joren De Groof avatar Ebony avatar Didier Lafforgue avatar Aurélien Malisart avatar Vesa Vänskä avatar Allen Bargi avatar Jérôme Lipowicz avatar Sebastian Munz avatar Olivier avatar

Watchers

Aurélien Malisart avatar James Cloos avatar Xavier Cazin avatar  avatar

vat_validator's Issues

module causing issues in Rails 3.0.x app

I have an old app which uses Rails 3.0.7 and the latest gem release (1.2) isn't loading in the app:

/Users/jeroen/.rvm/gems/ruby-1.8.7-p370@manchild/gems/activemodel-3.0.7/lib/active_model/validations/with.rb:70:in `validates_with': undefined method `new' for VatValidator:Module (NoMethodError)

A little digging seems to point out that the VatValidator module (and the include) are causing the error:

ActiveModel::Validations.__send__(:include, VatValidator)

A quick fix for me was to remove that line and move both the VatValidator and VatNumber classes out of the VatValidator module. Doing it like that the validator would load as expected.

I did not have the time yet to look further into it.

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.