Exemplo n.º 1
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var end = vat.Length - 1;

            var controlDigit = vat[end].ToInt();

            var slice = vat.Slice(0, end);

            vat = slice.PadLeft(9, '0');

            var sum = vat.Sum(Multipliers);

            var checkDigit = sum * 10 % 11;

            if (checkDigit == 10)
            {
                checkDigit = 0;
            }

            var isValid = checkDigit == controlDigit;

            return(!isValid
                ? VatValidationResult.Failed("Invalid RO vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 2
0
        protected override VatValidationResult OnValidate(string vat)
        {
            if (RegexType2.IsMatch(vat))
            {
                vat = "0" + vat.Substring(2, 7)
                      + vat.Substring(0, 1)
                      + vat.Substring(7, 8);
            }

            var sum = vat.Sum(Multipliers);

            // If the number is type 3 then we need to include the trailing A or H in the calculation
            if (RegexType3.IsMatch(vat))
            {
                // Add in a multiplier for the character A (1*9=9) or H (8*9=72)
                if (vat[8] == 'H')
                {
                    sum += 72;
                }
                else
                {
                    sum += 9;
                }
            }

            var checkDigit = sum % 23;

            var isValid = vat[7] == (checkDigit == 0 ? 'W' : (char)(checkDigit + 64));

            return(!isValid
                ? VatValidationResult.Failed("Invalid IE vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 3
0
        protected override VatValidationResult OnValidate(string vat)
        {
            // Only do check digit validation for standard VAT numbers
            if (vat.Length != 8)
            {
                return(VatValidationResult.Success());
            }

            var sum = vat.Sum(Multipliers);

            var checkDigit = 11 - sum % 11;

            if (checkDigit == 10)
            {
                checkDigit = 0;
            }

            if (checkDigit == 11)
            {
                checkDigit = 1;
            }

            var isValid = checkDigit == vat[7].ToInt();

            return(!isValid
                ? VatValidationResult.Failed("Invalid CZ vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 4
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var product = 10;

            for (var index = 0; index < 8; index++)
            {
                var sum = (vat[index].ToInt() + product) % 10;
                if (sum == 0)
                {
                    sum = 10;
                }

                product = 2 * sum % 11;
            }

            var val        = 11 - product;
            var checkDigit = val == 10
                ? 0
                : val;

            var isValid = checkDigit == vat[8].ToInt();

            return(!isValid
                ? VatValidationResult.Failed("Invalid DE vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 5
0
        private static VatValidationResult TemporarilyRegisteredTaxPayers(string vat)
        {
            if (vat[10] != '1')
            {
                return(VatValidationResult.Failed("Temporarily Registered Tax Payers should have 11th character one"));
            }

            var total = vat.Sum(MultipliersTemporarily);

            // double check digit calculation
            if (total % 11 == 10)
            {
                total = vat.Sum(MultipliersDoubleCheck);
            }

            // Establish check digit.
            total %= 11;
            if (total == 10)
            {
                total = 0;
            }

            var isValid = total == vat[11].ToInt();

            return(!isValid
                ? VatValidationResult.Failed("Invalid LT vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 6
0
        protected override VatValidationResult OnValidate(string vat)
        {
            if (vat.Length == 9)
            {
                if (vat[7] != '1')
                {
                    return(VatValidationResult.Failed("9 character VAT numbers should have 1 in 8th position."));
                }

                var sum = 0;
                for (var index = 0; index < 8; index++)
                {
                    sum += vat[index].ToInt() * (index + 1);
                }

                var checkDigit = sum % 11;
                if (checkDigit == 10)
                {
                    checkDigit = vat.Sum(Multipliers);
                }

                if (checkDigit == 10)
                {
                    checkDigit = 0;
                }

                var isValid = checkDigit == vat[8].ToInt();

                return(!isValid
                    ? VatValidationResult.Failed("Invalid LT vat: checkValue")
                    : VatValidationResult.Success());
            }

            return(TemporarilyRegisteredTaxPayers(vat));
        }
Exemplo n.º 7
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var sum = vat.Sum(Multipliers);

            // Old VAT numbers (pre 2020) - Modulus 11 test
            var checkMod11 = sum % 11;

            if (checkMod11 > 9)
            {
                checkMod11 = 0;
            }
            var isValidMod11 = checkMod11 == vat[8].ToInt();

            if (isValidMod11)
            {
                return(VatValidationResult.Success());
            }


            // New VAT numbers (post 2020) - Modulus 97 test
            const string stringValueNl = "2321";
            const string stringValueB  = "11";

            vat = vat.Replace("B", stringValueB);

            var isValidMod97 = long.Parse(stringValueNl + vat) % 97 == 1;

            return(!isValidMod97
                ? VatValidationResult.Failed("Invalid NL vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 8
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var isValid = int.Parse(vat.Substring(0, 6)) % 89 == int.Parse(vat.Substring(6, 2));

            return(!isValid
                ? VatValidationResult.Failed("Invalid LU vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 9
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var nr      = ulong.Parse(vat);
            var isValid = nr % 11 == 0;

            return(!isValid
                ? VatValidationResult.Failed("Invalid SK vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 10
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var sum = vat.Sum(Multipliers);

            var isValid = sum % 11 == 0;

            return(!isValid
                ? VatValidationResult.Failed("Invalid DK vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 11
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var sum = vat.Sum(Multipliers);

            var checkDigit = 37 - sum % 37;

            var isValid = checkDigit == int.Parse(vat.Substring(6, 2));

            return(!isValid
                ? VatValidationResult.Failed("Invalid MT vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 12
0
        protected override VatValidationResult OnValidate(string vat)
        {
            if (int.Parse(vat.Substring(0, 2)) == 12)
            {
                return(VatValidationResult.Failed("CY vat first 2 characters cannot be 12"));
            }

            var result = 0;

            for (var index = 0; index < 8; index++)
            {
                var temp = vat[index].ToInt();

                if (index % 2 == 0)
                {
                    switch (temp)
                    {
                    case 0:
                        temp = 1;
                        break;

                    case 1:
                        temp = 0;
                        break;

                    case 2:
                        temp = 5;
                        break;

                    case 3:
                        temp = 7;
                        break;

                    case 4:
                        temp = 9;
                        break;

                    default:
                        temp = temp * 2 + 3;
                        break;
                    }
                }
                result += temp;
            }

            var checkDigit = result % 26;
            var isValid    = vat[8].ToInt() == checkDigit + 65;

            return(!isValid
                ? VatValidationResult.Failed("Invalid CY vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 13
0
        public VatValidationResult ValidateCustomerVatNumber()
        {
            var vatNumber   = this.vatDataProvider.VatNumber;
            var countryCode = this.vatDataProvider.CountryCode;
            var result      = new VatValidationResult {
                VatNumber = vatNumber, CountryCode = countryCode
            };

            if (!String.IsNullOrEmpty(vatNumber))
            {
                // Billing API method does not handle country prefix numbers, remove if exists
                if (vatNumber.ToLowerInvariant().StartsWith(countryCode.ToLowerInvariant()))
                {
                    vatNumber = vatNumber.Substring(countryCode.Length);
                }

                var validationResult = BillingApi.ValidateVatNumber(countryCode, vatNumber);

                switch (validationResult)
                {
                case VatNumberValidationResultType.Valid:
                    result.Valid             = true;
                    result.ValidationDetail  = VatValidationDetail.Valid;
                    result.ValidationMessage = String.Empty;
                    break;

                case VatNumberValidationResultType.Invalid:
                    result.Valid             = false;
                    result.ValidationDetail  = VatValidationDetail.Invalid;
                    result.ValidationMessage = resourceProvider.GetResource("InvalidVatNumber");
                    break;

                case VatNumberValidationResultType.ValidationError:
                default:
                    result.Valid             = false;
                    result.ValidationDetail  = VatValidationDetail.ServiceError;
                    result.ValidationMessage = resourceProvider.GetResource("CouldNotValidateVatNumber");
                    break;
                }
            }
            else
            {
                result.Valid             = false;
                result.ValidationDetail  = VatValidationDetail.NoVatNumber;
                result.ValidationMessage = resourceProvider.GetResource("NoVatNumber");
            }

            return(result);
        }
Exemplo n.º 14
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var sum = vat.Sum(Multipliers);

            var checkDigit = 11 - sum % 11;

            if (checkDigit > 9)
            {
                checkDigit = 0;
            }
            var isValid = checkDigit == vat[8].ToInt();

            return(!isValid
                ? VatValidationResult.Failed("Invalid PT vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 15
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var validationKey = vat.Substring(0, 2);
            var val           = int.Parse(vat.Substring(2));

            if (!int.TryParse(validationKey, out var temp))
            {
                return(VatValidationResult.Success());
            }

            var checkDigit = (12 + 3 * (val % 97)) % 97;

            var isValid = checkDigit == temp;

            return(!isValid
                ? VatValidationResult.Failed("Invalid FR vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 16
0
        protected override VatValidationResult OnValidate(string vat)
        {
            // Only check the legal bodies
            if (Regex.IsMatch(vat, "/^[0-3]/"))
            {
                var result = Regex.IsMatch(vat, "^[0-3][0-9][0-1][0-9]");
                return(!result
                    ? VatValidationResult.Failed("Invalid LV vat: checkValue")
                    : VatValidationResult.Success());
            }
            var sum = vat.Sum(Multipliers);

            var checkDigit = sum % 11;

            if (checkDigit == 4 && vat[0] == '9')
            {
                checkDigit -= 45;
            }

            if (checkDigit == 4)
            {
                checkDigit = 4 - checkDigit;
            }
            else
            {
                if (checkDigit > 4)
                {
                    checkDigit = 14 - checkDigit;
                }
                else
                {
                    if (checkDigit < 4)
                    {
                        checkDigit = 3 - checkDigit;
                    }
                }
            }

            var isValid = checkDigit == vat[10].ToInt();

            return(!isValid
                ? VatValidationResult.Failed("Invalid LV vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 17
0
        protected override VatValidationResult OnValidate(string vat)
        {
            if (vat.Length == 10 && vat[0] != '0')
            {
                return(VatValidationResult.Failed("First character of 10 digit numbers should be 0."));
            }

            if (vat.Length == 9)
            {
                vat = vat.PadLeft(10, '0');
            }

            // Modulus 97 check on last nine digits
            var isValid = 97 - int.Parse(vat.Substring(0, 8)) % 97 == int.Parse(vat.Substring(8, 2));

            return(!isValid
                ? VatValidationResult.Failed("Invalid BE vat: checkValue.")
                : VatValidationResult.Success());
        }
Exemplo n.º 18
0
        protected override VatValidationResult OnValidate(string vat)
        {
            bool isValid;
            if (vat.Length == 9)
            {
                isValid = Bg9DigitsVat(vat);
                return isValid ? VatValidationResult.Success() : VatValidationResult.Failed("Invalid 9 digits vat.");
            }

            if (BgPhysicalPerson(vat))
            {
                return VatValidationResult.Success();
            }

            isValid = BgForeignerPhysicalPerson(vat) || BgMiscellaneousVatNumber(vat);

            return !isValid
                ? VatValidationResult.Failed("")
                : VatValidationResult.Success();
        }
Exemplo n.º 19
0
        protected override VatValidationResult OnValidate(string vat)
        {
            // The last three digits are the issuing office, and cannot exceed more 201
            if (int.Parse(vat.Substring(0, 7)) == 0)
            {
                return(VatValidationResult.Failed(""));
            }

            var temp = int.Parse(vat.Substring(7, 3));

            if ((temp < 1 || temp > 201) && temp != 999 && temp != 888)
            {
                return(VatValidationResult.Failed(""));
            }

            var index = 0;
            var sum   = 0;

            foreach (var m in Multipliers)
            {
                temp = vat[index++].ToInt() * m;
                sum += temp > 9
                    ? (int)Math.Floor(temp / 10D) + temp % 10
                    : temp;
            }

            var checkDigit = 10 - sum % 10;

            if (checkDigit > 9)
            {
                checkDigit = 0;
            }

            var isValid = checkDigit == vat[10].ToInt();

            return(!isValid
                ? VatValidationResult.Failed("Invalid IT vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 20
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var index = 0;
            var sum   = 0;

            foreach (var m in Multipliers)
            {
                var temp = vat[index++].ToInt() * m;
                sum += temp > 9 ? (int)Math.Floor(temp / 10D) + temp % 10 : temp;
            }

            var checkDigit = 10 - sum % 10;

            if (checkDigit == 10)
            {
                checkDigit = 0;
            }

            var isValid = checkDigit == vat[9].ToInt();

            return(!isValid
                ? VatValidationResult.Failed("Invalid SE vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 21
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var index = 1;
            var sum   = 0;

            foreach (var digit in Multipliers)
            {
                var temp = vat[index++].ToInt() * digit;
                sum += temp > 9 ? (int)Math.Floor(temp / 10D) + temp % 10 : temp;
            }

            var checkDigit = 10 - (sum + 4) % 10;

            if (checkDigit == 10)
            {
                checkDigit = 0;
            }

            var isValid = checkDigit == vat[8].ToInt();

            return(!isValid
                ? VatValidationResult.Failed($"Invalid {CountryCode} vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 22
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var product = 10;

            for (var index = 0; index < 10; index++)
            {
                int sum = (vat[index].ToInt() + product) % 10;

                if (sum == 0)
                {
                    sum = 10;
                }

                product = 2 * sum % 11;
            }

            var checkDigit = (product + vat[10].ToInt()) % 10;

            var isValid = checkDigit == 1;

            return(!isValid
                ? VatValidationResult.Failed("Invalid HR vat: checkValue")
                : VatValidationResult.Success());
        }
Exemplo n.º 23
0
 protected override VatValidationResult OnValidate(string vat)
 {
     return(VatValidationResult.Success());
 }
Exemplo n.º 24
0
        protected override VatValidationResult OnValidate(string vat)
        {
            var prefix = vat.Substring(0, 2);
            int no;

            if (prefix == "GD" && int.TryParse(vat.Substring(2, 3), out no))
            {
                //    return no < 500;
            }

            if (prefix == "HA" && int.TryParse(vat.Substring(2, 3), out no))
            {
                //  return no > 499;
            }

            if (prefix == "HA")
            {
                return(VatValidationResult.Failed(""));
            }


            if (vat[0].ToInt() == 0)
            {
                return(VatValidationResult.Failed("0 VAT numbers disallowed"));
            }

            // Check range is OK for modulus 97 calculation
            no = int.Parse(vat.Substring(0, 7));

            var total = vat.Sum(Multipliers);

            // Old numbers use a simple 97 modulus, but new numbers use an adaptation of that (less 55). Our

            // Establish check digits by subtracting 97 from total until negative.
            var cd = total;

            while (cd > 0)
            {
                cd -= 97;
            }

            // Get the absolute value and compare it with the last two characters of the VAT number. If the
            // same, then it is a valid traditional check digit. However, even then the number must fit within
            // certain specified ranges.
            cd = Math.Abs(cd);
            if (cd == int.Parse(vat.Substring(7, 2)) && no < 9990001 && (no < 100000 || no > 999999) &&
                (no < 9490001 || no > 9700000))
            {
                return(VatValidationResult.Success());
            }

            // Now try the new method by subtracting 55 from the check digit if we can - else add 42
            if (cd >= 55)
            {
                cd -= 55;
            }
            else
            {
                cd += 42;
            }

            var isValid = cd == int.Parse(vat.Substring(7, 2)) && no > 1000000;

            return(!isValid
                ? VatValidationResult.Failed("Invalid GB vat: checkValue")
                : VatValidationResult.Success());
        }