validate-vat icon indicating copy to clipboard operation
validate-vat copied to clipboard

Convert to ES6 JS with await; HTTPS; Deal with server down

Open benbucksch opened this issue 5 years ago • 17 comments

Summary:

  • Reformat as ES6 JS instead of Coffee script, removing further dependencies
  • Support await
  • Do simple syntax check first, before asking server
  • If state server is down, return valid, if syntax check passes
  • Use HTTPS

Reformat as ES6 JS instead of Coffee script, removing further dependencies

I don't really expect you to merge this. -- But you might, who knows. Coffee script annoyed me personally, because it was a dependency and a compilation.

await

As part of the ES6 rewrite, I also used a Promise, so the caller can simply await the call instead of using callbacks. Errors are thrown as normal exceptions.

Do simple syntax check first, before asking server

I've added a little regexp that checks the number a little further. There need to be between 2 and 13 numbers or letters in the VAT number.

If state server is down, return valid, if syntax check passes

Now, that one was annoying. Just when I worked on it, the German server was down. I verified with other VAT check pages, they also say "server down" for German VAT IDs. I'm actually glad I caught this during development rather than in production.

I don't want my corporate customers to be unable to buy my products just because the state can't keep its server up.

I worked around it by returning valid in such cases, and added another return value, in case any caller wants to only accept really server-validated numbers or add special handling.

The syntax validation helps a little bit in this case.

HTTPS

The old code (probably survived from 2013) used a non-SSL HTTP URL. That's no longer appropriate in 2019. Luckily, the server accepts HTTPS, so I changed the URL to that.

API changes

  • Pass in full VAT ID as single string, e.g. 'FR60421938861', instead of separate country and number.
  • Trim spaces in name and address fields. I got such garbage e.g. for FR60421938861.
  • Do not return name and address as '---', but empty string.

Obviously, this is a breaking API change, due to promises.

benbucksch avatar Jul 01 '19 23:07 benbucksch