{"id":13879857,"url":"https://github.com/yolk/valvat","last_synced_at":"2025-07-16T16:30:24.269Z","repository":{"id":1284181,"uuid":"1223839","full_name":"yolk/valvat","owner":"yolk","description":"Validates european vat numbers. Standalone or as a ActiveModel validator.","archived":false,"fork":false,"pushed_at":"2025-06-07T09:48:36.000Z","size":623,"stargazers_count":323,"open_issues_count":5,"forks_count":81,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-14T01:18:16.493Z","etag":null,"topics":["hmrc","taxes","validation","validator","vat","vat-validation","vies"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yolk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2011-01-05T19:02:48.000Z","updated_at":"2025-06-07T09:48:39.000Z","dependencies_parsed_at":"2024-11-24T08:32:10.815Z","dependency_job_id":"13d3af6e-54b5-4dc3-a4bb-7c7428f3437f","html_url":"https://github.com/yolk/valvat","commit_stats":{"total_commits":523,"total_committers":60,"mean_commits":8.716666666666667,"dds":"0.17782026768642445","last_synced_commit":"e705108fd07eb0bfbcb7e7428cc7cb9ab010b5e1"},"previous_names":[],"tags_count":65,"template":false,"template_full_name":null,"purl":"pkg:github/yolk/valvat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolk%2Fvalvat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolk%2Fvalvat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolk%2Fvalvat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolk%2Fvalvat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yolk","download_url":"https://codeload.github.com/yolk/valvat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yolk%2Fvalvat/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265524592,"owners_count":23782006,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hmrc","taxes","validation","validator","vat","vat-validation","vies"],"created_at":"2024-08-06T08:02:36.164Z","updated_at":"2025-07-16T16:30:24.109Z","avatar_url":"https://github.com/yolk.png","language":"Ruby","funding_links":[],"categories":["Ruby","ActiveRecord Validations","VAT, Customs, and Trade"],"sub_categories":[],"readme":"valvat\n===========\n\n[![rubygems](https://badgen.net/rubygems/v/valvat)](https://rubygems.org/gems/valvat) [![Specs](https://github.com/yolk/valvat/workflows/Specs/badge.svg)](https://github.com/yolk/valvat/actions?query=workflow%3ASpecs)\n\nValidates european vat numbers. Standalone or as a ActiveModel validator.\n\n## A note on Brexit\n\nValvat supports validating VAT-IDs from the UK by syntax, checksum and using the HMRC API v2.0. Validation against the VIES web service stopped working early 2021.\n\nSadly with the deprecation of the HMRC API v1 on January 2025 there is no open accessible web service to validate UK vat numbers anymore. To use the current v2 of the HMRC API you will need to create an account on the [HMRC Developer Hub](https://developer.service.hmrc.gov.uk/developer/registration) and then apply for production credentials. The second step is a little bit more involved and can take up to ten business days. See the configuration section below how to use valvat with your HMRC authentication credentials.\n\nNorthern Ireland received its own VAT number prefix - XI which is supported by VIES web service so any XI-prefixed VAT numbers should be validated as any EU VAT number.\n\n## Features\n\n* Simple syntax verification\n* Lookup via the VIES web service (for EU VAT numbers)\n* Lookup via the HMRC web service (for UK VAT numbers)\n* ActiveModel/Rails integration\n* Works standalone without ActiveModel\n* Minimal runtime dependencies\n* I18n locales for language specific error messages in English, German, French, Spanish, Italian, Portuguese, Polish, Swedish, Dutch, Danish, Czech, Slovakian, Hungarian, Bulgarian, Romanian, Latvian, Catalan, Norwegian, and Finnish.\n* *Experimental* checksum verification\n\nvalvat is tested and works with ruby MRI 2.6/2.7/3.0/3.1/3.2/3.3, jruby and ActiveModel 5/6/7/8. If you need support for ruby down to 1.9.3 and ActiveModel 3 and 4 use [v1.0.1](https://github.com/yolk/valvat/tree/v1.0.1).\n\n## Installation\n\nAdd it to your Gemfile:\n\n```ruby\ngem 'valvat'\n```\n\nAnd run:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install valvat\n\n## Validate the syntax of a VAT number\n\nTo verify the syntax of a vat number:\n\n```ruby\nValvat.new(\"DE345789003\").valid?\n# =\u003e true or false\n```\n\nIt is also possible to bypass initializing a Valvat instance and check the syntax of a vat number string directly with:\n\n```ruby\nValvat::Syntax.validate(\"DE345789003\")\n# =\u003e true or false\n```\n\n## Validate against the VIES / HMRC web service\n\nTo check if the given vat number exists via the VIES or HMRC web service:\n\n```ruby\nValvat.new(\"DE345789003\").exists?\n# =\u003e true or false or nil\n```\n\nOr to lookup a vat number string directly:\n\n```ruby\nValvat::Lookup.validate(\"DE345789003\")\n# =\u003e true or false or nil\n```\n\nBecause the HMRC API requires authentication validation against HMRC is only performed when the option `:uk` is set to a hash containing your authentication credentials. You need to create an account on the [HMRC Developer Hub](https://developer.service.hmrc.gov.uk/developer/registration) and apply for production credentials to validate UK VAT numbers against HMRC.\n\n```ruby\nValvat::Lookup.validate(\n  \"GB553557881\",\n  uk: {\n    client_id: '\u003cclient_id\u003e',\n    client_secret: '\u003cclient_secret\u003e'\n  }\n)\n# =\u003e true or false or nil\n```\n\nWhen `:uk` is not set to a hash containing the required authentication credentials the lookup of UK VAT numbers always returns `false`.\n\n*IMPORTANT* Keep in mind that the web service might be offline at some time for all or some member states. If this happens `exists?` or `Valvat::Lookup.validate` will return `nil`. See *Handling of maintenance errors* for further details.\n\n### Details \u0026 request identifier\n\nIf you need all details and not only if the VAT is valid, pass {detail: true} as second parameter to the lookup call.\n\n```ruby\nValvat.new(\"IE6388047V\").exists?(detail: true)\n=\u003e {\n  :country_code=\u003e \"IE\", :vat_number =\u003e \"6388047V\", :valid =\u003e true,\n  :request_date =\u003e Date.today, :name=\u003e \"GOOGLE IRELAND LIMITED\",\n  :address=\u003e \"1ST \u0026 2ND FLOOR ,GORDON HOUSE ,BARROW STREET ,DUBLIN 4\"\n} or false or nil\n```\n\nAccording to EU law, or at least as Austria sees it, it's mandatory to verify the VAT number of every new customer, but also to check the VAT number periodicaly. To prove that you have checked the VAT number, the web service can return a `request_identifier`.\n\nTo receive a `request_identifier` you need to pass your own VAT number in the options hash. In this example, Google (VAT IE6388047V) is checking the validity of eBays VAT number (LU21416127)\n\n```ruby\nValvat.new(\"LU21416127\").exists?(requester: \"IE6388047V\")\n=\u003e {\n  :country_code=\u003e\"LU\", :vat_number =\u003e \"21416127\", :valid =\u003e true,\n  :request_date =\u003e Date.today, :name=\u003e\"EBAY EUROPE S.A R.L.\",\n  :address =\u003e \"22, BOULEVARD ROYAL\\nL-2449  LUXEMBOURG\",\n  :company_type =\u003e nil, :request_identifier =\u003e \"some_uniq_string\"\n} or false or nil\n```\n\nIf the given `requester` is invalid, a `Valvat::InvalidRequester` error is thrown.\n\nWhen requesting a `request_identifier` for a GB VAT number, the requester must be your own GB number; a EU VAT number won't work.\n\nNote that when validating UK VAT numbers using the HMRC service, the detail output is modified to match the one from VIES more closely with slight differences remaining:\n\n1. The `request_date` will actually be a (more precise) `Time` instead of a `Date`\n2. The `address` string will join lines using `\\n` instead of `,` so it's more acurate and can be displayed nicely.\n\n### Handling of maintenance errors\n\nFrom time to time the VIES web service for one or all member states is down for maintenance. To handle this kind of temporary errors, `Valvat::Lookup#validate` returns `nil` by default to indicate that there is no way at the moment to say if the given VAT is valid or not. You should revalidate the VAT later. If you prefer an error, use the `raise_error` option:\n\n```ruby\nValvat.new(\"IE6388047V\").exists?(raise_error: true)\n```\n\nThis raises `Valvat::ServiceUnavailable` or `Valvat::MemberStateUnavailable` instead of returning `nil`.\n\nVisit [https://ec.europa.eu/taxation_customs/vies/#/help](https://ec.europa.eu/taxation_customs/vies/#/help) for more accurate information at what time the service for a specific member state will be down.\n\n### Handling of other errors\n\nAll other errors accuring while validating against the web service are raised and must be handled by you. These include:\n\n * `Valvat::InvalidRequester`\n * `Valvat::BlockedError`\n * `Valvat::RateLimitError`\n * `Valvat::Timeout`\n * all IO errors\n\nIf you want to suppress all known error cases. Pass in the `raise_error` option set to `false`:\n\n```ruby\nValvat.new(\"IE6388047V\").exists?(raise_error: false)\n```\n\nThis will return `nil` instead of raising a known error.\n\n### Set options for the Net::HTTP client\n\nUse the `:http` key to set options for the http client. These options are directly passed to `Net::HTTP.start`.\n\nFor example to set timeouts:\n\n```ruby\nValvat.new(\"IE6388047V\").exists?(http: { open_timeout: 10, read_timeout: 10 })\n```\n\n### Skip local validation before lookup\n\nTo prevent unnecessary requests, valvat performs a local syntax check before making the request to the web service. If you want to skip this step (for any reason), set the `:skip_local_validation` option to `true`.\n\n## Experimental checksum verification\n\nvalvat allows to check vat numbers from AT, BE, BG, DE, DK, ES, FR, FI, GR, IE, IT, LU, NL, PL, PT, SE and SI against a checksum calculation. All other member states will fall back to a basic syntax check:\n\n```ruby\nValvat.new(\"DE345789003\").valid_checksum?\n# =\u003e true or false\n```\n\nThese results are more valuable than a simple syntax check, but keep in mind: they can not replace a lookup via VIES or HMRC.\n\n*IMPORTANT* This feature was tested against all vat numbers I could get my hand on, but it is still marked as *experimental* because these calculations are not documented and may return wrong results.\n\nTo bypass initializing a Valvat instance:\n\n```ruby\nValvat::Checksum.validate(\"DE345789003\")\n# =\u003e true or false\n```\n\n## Configuration\n\nInstead of passing in the same options again and again, Valvat allows to alter its default configuration. This feature is intended to be used when initializing your application (for example in a Rails initializer file).\n\n```ruby\nValvat.configure(\n  raise_error: true,\n  http: { read_timeout: 5 },\n  uk: {\n    sandbox: true, # Use sandbox mode\n    client_id: \u003cclient_id\u003e # Required for HMRC API v2 authentication\n    client_secret: \u003cclient_secret\u003e # Required for HMRC API v2 authentication\n  }\n)\n```\n\nTo see all options and the defaults, take a look at [valvat/configuration](https://github.com/yolk/valvat/blob/master/lib/valvat/configuration.rb#L25).\n\n## Usage with ActiveModel / Rails\n\n### Loading\n\nWhen the valvat gem is required and ActiveModel is already loaded, everything will work fine out of the box. If your load order differs just add\n\n```ruby\nrequire 'active_model/validations/valvat_validator'\n```\n\nafter ActiveModel has been loaded.\n\n### Simple syntax validation\n\nTo validate the attribute `vat_number` add this to your model:\n\n```ruby\nclass MyModel \u003c ActiveRecord::Base\n  validates :vat_number, valvat: true\nend\n```\n\n### Additional lookup validation\n\nTo additionally perform an lookup via VIES:\n\n```ruby\nvalidates :vat_number, valvat: { lookup: true }\n```\n\nTo also perform an lookup via HMRC for UK VAT numbers:\n\n```ruby\nvalidates :vat_number, valvat: { lookup: { uk: { client_id: '\u003cclient_id\u003e', client_secret: '\u003cclient_secret\u003e' } } }\n```\n\nBy default this will validate to true if the web service is down. To fail in this case simply add the `:fail_if_down` option:\n\n```ruby\nvalidates :vat_number, valvat: { lookup: { fail_if_down: true } }\n```\n\nYou can pass in any options accepted by `Valvat::Lookup#validate`:\n\n```ruby\nvalidates :vat_number, valvat: { lookup: { raise_error: true, http: { read_timeout: 12 } } }\n```\n\n### Additional (and experimental) checksum validation\n\nTo additionally perform a checksum validation:\n\n```ruby\nvalidates :vat_number, valvat: { checksum: true }\n```\n\n### Additional ISO country code validation\n\nIf you want the vat number’s (ISO) country to match another country attribute, use the _match_country_ option:\n\n```ruby\nvalidates :vat_number, valvat: { match_country: :country }\n```\n\nwhere it is supposed that your model has a method named _country_ which returns the country ISO code you want to match.\n\n### Allow blank\n\nBy default blank vat numbers validate to false. To change this add the `:allow_blank` option:\n\n```ruby\nvalidates :vat_number, valvat: { allow_blank: true }\n```\n\n### Allow vat numbers outside of europe\n\nTo allow vat numbers from outside of europe, add something like this to your model (country_code should return a upcase ISO country code):\n\n```ruby\nclass MyModel \u003c ActiveRecord::Base\n  validates :vat_number, valvat: true, if: :eu?\n\n  def eu?\n    Valvat::Utils::EU_MEMBER_STATES.include?(country_code)\n  end\nend\n```\n\n## Utilities\n\nTo split a vat number into the country code and the remaining chars:\n\n```ruby\nValvat::Utils.split(\"ATU345789003\")\n# =\u003e [\"AT\", \"U345789003\"]\n```\n\nor\n\n```ruby\nValvat.new(\"ATU345789003\").to_a\n# =\u003e [\"AT\", \"U345789003\"]\n```\n\nBoth methods always return an array. If it can not detect the country or the given country is located outside of europe it returns `[nil, nil]`. Please note that this does not strictly return the ISO country code: for greek vat numbers this returns the ISO language code 'EL' instead of the ISO country code 'GR'.\n\nTo extract the ISO country code of a given vat number:\n\n```ruby\nValvat.new(\"EL7345789003\").iso_country_code\n# =\u003e \"GR\"\n```\n\nTo extract the vat country code (first two chars in every european vat number):\n\n```ruby\nValvat.new(\"EL7345789003\").vat_country_code\n# =\u003e \"EL\"\n```\n\nTo normalize a vat number:\n\n```ruby\nValvat::Utils.normalize(\"atu345789003\")\n# =\u003e \"ATU345789003\"\n```\n\nThis basically just removes trailing spaces and ensures all chars are uppercase.\n\n## Usage with IPv6\n\nThere seems to be a problem when using the VIES service over IPv6. Sadly this is nothing this gem can address. For details and proposed solutions have a look at [this question on StackOverflow](http://stackoverflow.com/questions/15616833/vies-vat-api-soap-error-ipv6). Thanks to George Palmer for bringing up this issue.\n\n## HMRC API v2.0\n- Version 2 is the recommended version of this API. Version 1 will be removed in January 2025.\n- To use Version 2 of the HMRC API you need to create an account on the [HMRC Developer Hub](https://developer.service.hmrc.gov.uk/developer/registration) and then apply for production credentials. The second step is a little bit more involved and can take up to ten business days.\n- See more details https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-registered-companies-api/2.0.\n- New configuration was added to support API v2.0 with OAuth 2.0 Authentication. See configuration section.\n- Valid VAT numbers for HMRC lookup on Sandbox https://github.com/hmrc/vat-registered-companies-api/blob/main/public/api/conf/2.0/test-data/vrn.csv\n\n## Links\n\n* [VIES web service](http://ec.europa.eu/taxation_customs/vies)\n* [HMRC web service](https://developer.service.hmrc.gov.uk/api-documentation/docs/api/service/vat-registered-companies-api/2.0)\n* [European vat number formats (german)](http://bzst.de/DE/Steuern_International/USt_Identifikationsnummer/Merkblaetter/Aufbau_USt_IdNr.html)\n* [European vat number formats on Wikipedia](http://en.wikipedia.org/wiki/European_Union_Value_Added_Tax)\n\n## Contributions by\n\nhttps://github.com/yolk/valvat/graphs/contributors\n\n## BlaBla\n\nCopyright (c) 2011-2025 mite GmbH\n\nBeyond that, the implementation is licensed under the MIT License.\n\nCode was originally extracted from our time tracking webapp [mite](https://mite.de/en/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyolk%2Fvalvat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyolk%2Fvalvat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyolk%2Fvalvat/lists"}