Comments (16)
I can disclose my VAT number: (removed since its not necessary anymore)
from vies.
from vies.
That's my plan . I will validate the TIN against both algo. If the first one fails -> will try the new one
from vies.
Waiting for code review ....
from vies.
Sorry being late at the game, this holiday time is for me the only time I can truly spend with my family in full. But now when they're off playing games themselves, I can have a look at this.
from vies.
Many thanks for the fast fix! 🥇
from vies.
@Smitsel Could You provide an example VAT number that validates in VIES and does not pass a checksum test ?
from vies.
Yes, for example: NL000099998B57
I can not disclose any real VAT numbers ofcourse.
from vies.
@MollieRick thx. Yep Your number validates in VIES but there is no information on the new algorithm to calculate the checksum. I'll try to google a little bit more but i may be easier to look for it in Dutch rather than in English ;)
from vies.
We've looked for it as well, could not find any information about calculating the checksum.
I will try to find a contact with the dutch government.
from vies.
Yep it works 23210023426721142 % 97 = 1 - so it's correct. Now I just need to find a way to distinguish old numbers from the new one's so that both validate ;)
from vies.
If they can't be differentiated you could do it by doing this check when the first one fails.
So in a failover kind of way.
from vies.
We can totally review your PR once you have something too btw.
from vies.
Awesome, i left some not super important comments. It works as intended, i've tried it out in our fork.
from vies.
@Smitsel should be fine now. I did add a regex expression to check if the number has only valid characters before calculating checksum [0-9A-Z+*]. This way it should be safer. In the older version there was a small % of chance that a number with an invalid char would validate :) It would then error on VIES but still :)
from vies.
Found this page in google, thanks to all participants for the information.
To those who also gets to this page, here is my version of this algorithm in C#. The simple conversion of VAT number to integer can cause overflow error, because the maximum length of converted VAT number is 26, while the max length of ulong type in C# is 20. Therefore I write converted VAT number to a string first and then subsequently convert the string to an integer and divide it by 97.
// Positions 1-2 must be NL, positions 13-14 must be digits. Positions 3-12 can contain digits, uppercase letters, '+' and '*'.
// Each letter is replaced by two-digit number, where 'A' = 10, 'B' = 11, ..., 'Z' = 35; '+' = 36, '*' = 37.
// Remainder of division the converted VAT number by 97 must be equal to 1.
// Example: NL123456789B13 is converted to 2321 123456789 11 13, i.e. to 23211234567891113 integer number. 23211234567891113 mod 97 = 1, it is a valid VAT number.
public void ValidateVatMod97Algorithm(string vat) {
if (vat.Length != 14) {
throw new System.Exception("VAT must have exactly 14 chars");
}
if (vat.Substring(0, 2) != "NL") {
throw new System.FormatException("First two chars must be NL");
}
if (!char.IsDigit(vat[12]) || !char.IsDigit(vat[13])) {
throw new System.FormatException("Last two chars must be digits");
}
// we can also check that the two-digit number in the end is between 02 and 98.
var sb = new StringBuilder();
foreach (char ch in vat) {
int currNumber = 0;
if (char.IsDigit(ch)) currNumber = ch - '0';
else if (char.IsUpper(ch)) currNumber = ch - 55;
else if (ch == '+') currNumber = 36;
else if (ch == '*') currNumber = 37;
else throw new System.FormatException("VAT contains incorrect chars");
sb.Append(currNumber);
}
string vatDigitString = sb.ToString();
int remainder = 0;
foreach (char ch in vatDigitString) {
int digit = ch - '0';
remainder = (remainder * 10 + digit) % 97;
}
if (remainder != 1) {
throw new System.FormatException("VAT is not valid according to the Modulus-97 checksum algorithm.");
}
}
from vies.
Related Issues (20)
- Validation of Irish VAT ID failed for valid VAT ID HOT 7
- Making VIES package more inclusive
- Missing BG checksum validation for foreign natual persons
- VIES_EU_COUNTRY_LIST Visibility HOT 1
- Package upgrade to composer 2.0
- Ensure this package can be installed with Composer 2.0
- Implementing a Symfony constraint based on this library HOT 2
- Remove support for the United Kingdom ("GB") HOT 16
- Add support for United Kingdom (Northern Ireland) ("GB-NIR") HOT 7
- Support php8
- Validation failed for valid VAT numbers HOT 8
- 32 Bit Support HOT 1
- The service moved to SSL endpoint. HOT 1
- use of ::VIES_EXCLUDED_COUNTRY_CODES
- ValidatorLV results inconsistent with official EU validation
- heartbeat is not working anymore HOT 12
- Cannot populate CheckVatResponse after using `toArray`
- Optional Argument Validation Fails for ® HOT 2
- Heathbeat check always false HOT 1
- GetAddress non getting separated city, zip
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vies.