WINTER SALE!

-10% CODE: P9FC325N

Limited Time Offer!

Chapter: file-LzabtBpy2E7jHQ6qNgoMaE

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

from viesapi import *

# Create client object and establish connection to the production system
# id – API identifier
# key – API key (keep it secret)
# viesapi = VIESAPIClient(‘id’, ‘key’)

# Create client object and establish connection to the test system
viesapi = VIESAPIClient()

euvat = ‘PL7171642051’

# SGet current account status
account = viesapi.get_account_status()

if account:
print(account)
else:
print(‘Error: ‘ + viesapi.get_last_error() + ‘ (code: ‘ + str(viesapi.get_last_error_code()) + ‘)’)

# Get VIES data from VIES system
vies = viesapi.get_vies_data(euvat)

if vies:
print(vies)
else:
print(‘Error: ‘ + viesapi.get_last_error() + ‘ (code: ‘ + str(viesapi.get_last_error_code()) + ‘)’)

Chapter: file-GEoWtbronFtUgzwzufeik9

Chapter: file-Cz3WXjjvAfWGRxZCPdLBPT

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”),
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

import re

from viesapi import NIP

class EUVAT:
“””
EU VAT number verificator
“””

@staticmethod
def normalize(number):
“””
Normalizes form of the VAT number
:param number: input string
:type number: str
:returns: normalized string or False
:rtype: str or False
“””

if not number:
return False

number = re.sub(‘[ -]’, ”, number).upper()

if not re.match(‘[A-Z]{2}[A-Z0-9+*]{2,12}’, number):
return False

return number

@staticmethod
def is_valid(number):
“””
Checks if specified NIP is valid
:param number: input string
:type number: str
:returns: True if NIP is valid
:rtype: bool
“””

number = EUVAT.normalize(number)

if not number:
return False

cmap = {
‘AT’: ‘ATU\\d{8}’,
‘BE’: ‘BE[0-1]{1}\\d{9}’,
‘BG’: ‘BG\\d{9,10}’,
‘CY’: ‘CY\\d{8}[A-Z]{1}’,
‘CZ’: ‘CZ\\d{8,10}’,
‘DE’: ‘DE\\d{9}’,
‘DK’: ‘DK\\d{8}’,
‘EE’: ‘EE\\d{9}’,
‘EL’: ‘EL\\d{9}’,
‘ES’: ‘ES[A-Z0-9]{1}\\d{7}[A-Z0-9]{1}’,
‘FI’: ‘FI\\d{8}’,
‘FR’: ‘FR[A-Z0-9]{2}\\d{9}’,
‘HR’: ‘HR\\d{11}’,
‘HU’: ‘HU\\d{8}’,
‘IE’: ‘IE[A-Z0-9+*]{8,9}’,
‘IT’: ‘IT\\d{11}’,
‘LT’: ‘LT\\d{9,12}’,
‘LU’: ‘LU\\d{8}’,
‘LV’: ‘LV\\d{11}’,
‘MT’: ‘MT\\d{8}’,
‘NL’: ‘NL[A-Z0-9+*]{12}’,
‘PL’: ‘PL\\d{10}’,
‘PT’: ‘PT\\d{9}’,
‘RO’: ‘RO\\d{2,10}’,
‘SE’: ‘SE\\d{12}’,
‘SI’: ‘SI\\d{8}’,
‘SK’: ‘SK\\d{10}’,
‘XI’: ‘XI[A-Z0-9]{5,12}’
}

cc = number[0:2].upper()
num = number[2:].upper()

if cc not in cmap:
return False

if not re.match(cmap[cc], number):
return False

if cc == ‘PL’:
return NIP.is_valid(num)

return True

Chapter: file-SJawK5nsdUfrtuvo3jCWqS

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

class AccountStatus:
“””
Account status
“””

def __init__(self):
self.uid = None

self.type = None
self.valid_to = None
self.billing_plan_name = None

self.subscription_price = None
self.item_price = None
self.item_price_status = None

self.limit = None
self.request_delay = None
self.domain_limit = None
self.over_plan_allowed = None
self.excel_addin = None

self.app = None
self.cli = None
self.stats = None
self.monitor = None

self.func_get_vies_data = None

self.vies_data_count = None
self.total_count = None

def __str__(self):
return ‘AccountStatus: [uid = ‘ + str(self.uid) \
+ ‘, type = ‘ + str(self.type) \
+ ‘, valid_to = ‘ + str(self.valid_to) \
+ ‘, billing_plan_name = ‘ + str(self.billing_plan_name) \
+ ‘, subscription_price = ‘ + str(self.subscription_price) \
+ ‘, item_price = ‘ + str(self.item_price) \
+ ‘, item_price_status = ‘ + str(self.item_price_status) \
+ ‘, limit = ‘ + str(self.limit) \
+ ‘, request_delay = ‘ + str(self.request_delay) \
+ ‘, domain_limit = ‘ + str(self.domain_limit) \
+ ‘, over_plan_allowed = ‘ + str(self.over_plan_allowed) \
+ ‘, excel_addin = ‘ + str(self.excel_addin) \
+ ‘, app = ‘ + str(self.app) \
+ ‘, cli = ‘ + str(self.cli) \
+ ‘, stats = ‘ + str(self.stats) \
+ ‘, monitor = ‘ + str(self.monitor) \
+ ‘, func_get_vies_data = ‘ + str(self.func_get_vies_data) \
+ ‘, vies_data_count = ‘ + str(self.vies_data_count) \
+ ‘, total_count = ‘ + str(self.total_count) \
+ ‘]’

Chapter: file-WhtGJwagMD6whnHRZJYLVg

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

class Number:
“””
Number types
“””

EUVAT = 1
NIP = 2

Chapter: file-WxtXGC6FdrwUqNDMTK6Tf3

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

from viesapi.error import *
from viesapi.number import *
from viesapi.viesdata import *
from viesapi.accountstatus import *
from viesapi.nip import *
from viesapi.euvat import *
from viesapi.viesapiclient import *

__version__ = ‘1.2.6’

Chapter: file-8fa171hRJ8Tz3Tc42kFjq7

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”)
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

class Error:
“””
VIES API error codes
“””

NIP_EMPTY = 1
NIP_UNKNOWN = 2
GUS_LOGIN = 3
GUS_CAPTCHA = 4
GUS_SYNC = 5
NIP_UPDATE = 6
NIP_BAD = 7
CONTENT_SYNTAX = 8
NIP_NOT_ACTIVE = 9
INVALID_PATH = 10
EXCEPTION = 11
NO_PERMISSION = 12
GEN_INVOICES = 13
GEN_SPEC_INV = 14
SEND_INVOICE = 15
PREMIUM_FEATURE = 16
SEND_ANNOUNCEMENT = 17
INVOICE_PAYMENT = 18
REGON_BAD = 19
SEARCH_KEY_EMPTY = 20
KRS_BAD = 21
EUVAT_BAD = 22
VIES_SYNC = 23
CEIDG_SYNC = 24
RANDOM_NUMBER = 25
PLAN_FEATURE = 26
SEARCH_TYPE = 27
PPUMF_SYNC = 28
PPUMF_DIRECT = 29
NIP_FEATURE = 30
REGON_FEATURE = 31
KRS_FEATURE = 32
TEST_MODE = 33
ACTIVITY_CHECK = 34
ACCESS_DENIED = 35
MAINTENANCE = 36
BILLING_PLANS = 37
DOCUMENT_PDF = 38
EXPORT_PDF = 39
RANDOM_TYPE = 40
LEGAL_FORM = 41
GROUP_CHECKS = 42
CLIENT_COUNTERS = 43
URE_SYNC = 44
URE_DATA = 45
DKN_BAD = 46
SEND_REMAINDER = 47
EXPORT_JPK = 48
GEN_ORDER_INV = 49
SEND_EXPIRATION = 50
IBAN_SYNC = 51
ORDER_CANCEL = 52
WHITELIST_CHECK = 53
AUTH_TIMESTAMP = 54
AUTH_MAC = 55
IBAN_BAD = 56

DB_AUTH_IP = 101
DB_AUTH_KEY_STATUS = 102
DB_AUTH_KEY_VALUE = 103
DB_AUTH_OVER_PLAN = 104
DB_CLIENT_LOCKED = 105
DB_CLIENT_TYPE = 106
DB_CLIENT_NOT_PAID = 107
DB_AUTH_KEYID_VALUE = 108

CLI_CONNECT = 201
CLI_RESPONSE = 202
CLI_NUMBER = 203
CLI_NIP = 204
CLI_REGON = 205
CLI_KRS = 206
CLI_EUVAT = 207
CLI_IBAN = 208
CLI_EXCEPTION = 209
CLI_DATEFORMAT = 210
CLI_INPUT = 211

__codes__ = {
CLI_CONNECT: ‘Failed to connect to the VIES API service’,
CLI_RESPONSE: ‘VIES API service response has invalid format’,
CLI_NUMBER: ‘Invalid number type’,
CLI_NIP: ‘NIP is invalid’,
CLI_EUVAT: ‘EU VAT ID is invalid’,
CLI_EXCEPTION: ‘Function generated an exception’,
CLI_DATEFORMAT: ‘Date has an invalid format’,
CLI_INPUT: ‘Invalid input parameter’
}

@staticmethod
def message(code):
“””
Get error message

:param code: error code
:type code: int
:return: error message
:rtype: str
“””

if code < Error.CLI_CONNECT or code > Error.CLI_INPUT:
return None

return Error.__codes__[code]

Chapter: file-BWd1zavvqRpJGRVsZKy71K

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

import re

class NIP:
“””
NIP number validator
“””

@staticmethod
def normalize(nip):
“””
Normalizes form of the NIP number
:param nip: input string
:type nip: str
:returns: normalized string or False
:rtype: str or False
“””

if not nip:
return False

nip = re.sub(‘[ -]’, ”, nip).upper()

if not re.match(‘[0-9]{10}’, nip):
return False

return nip

@staticmethod
def is_valid(nip):
“””
Checks if specified NIP is valid
:param nip: input string
:type nip: str
:returns: True if NIP is valid
:rtype: bool
“””

nip = NIP.normalize(nip)

if not nip:
return False

w = [6, 5, 7, 2, 3, 4, 5, 6, 7]
res = 0

for i in range(0, len(w)):
res += int(nip[i]) * w[i]

res %= 11

if res != int(nip[9]):
return False

return True

 

Chapter: file-Cz3WXjjvAfWGRxZCPdLBPT

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”),
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

import re

from viesapi import NIP

class EUVAT:
“””
EU VAT number verificator
“””

@staticmethod
def normalize(number):
“””
Normalizes form of the VAT number
:param number: input string
:type number: str
:returns: normalized string or False
:rtype: str or False
“””

if not number:
return False

number = re.sub(‘[ -]’, ”, number).upper()

if not re.match(‘[A-Z]{2}[A-Z0-9+*]{2,12}’, number):
return False

return number

@staticmethod
def is_valid(number):
“””
Checks if specified NIP is valid
:param number: input string
:type number: str
:returns: True if NIP is valid
:rtype: bool
“””

number = EUVAT.normalize(number)

if not number:
return False

cmap = {
‘AT’: ‘ATU\\d{8}’,
‘BE’: ‘BE[0-1]{1}\\d{9}’,
‘BG’: ‘BG\\d{9,10}’,
‘CY’: ‘CY\\d{8}[A-Z]{1}’,
‘CZ’: ‘CZ\\d{8,10}’,
‘DE’: ‘DE\\d{9}’,
‘DK’: ‘DK\\d{8}’,
‘EE’: ‘EE\\d{9}’,
‘EL’: ‘EL\\d{9}’,
‘ES’: ‘ES[A-Z0-9]{1}\\d{7}[A-Z0-9]{1}’,
‘FI’: ‘FI\\d{8}’,
‘FR’: ‘FR[A-Z0-9]{2}\\d{9}’,
‘HR’: ‘HR\\d{11}’,
‘HU’: ‘HU\\d{8}’,
‘IE’: ‘IE[A-Z0-9+*]{8,9}’,
‘IT’: ‘IT\\d{11}’,
‘LT’: ‘LT\\d{9,12}’,
‘LU’: ‘LU\\d{8}’,
‘LV’: ‘LV\\d{11}’,
‘MT’: ‘MT\\d{8}’,
‘NL’: ‘NL[A-Z0-9+*]{12}’,
‘PL’: ‘PL\\d{10}’,
‘PT’: ‘PT\\d{9}’,
‘RO’: ‘RO\\d{2,10}’,
‘SE’: ‘SE\\d{12}’,
‘SI’: ‘SI\\d{8}’,
‘SK’: ‘SK\\d{10}’,
‘XI’: ‘XI[A-Z0-9]{5,12}’
}

cc = number[0:2].upper()
num = number[2:].upper()

if cc not in cmap:
return False

if not re.match(cmap[cc], number):
return False

if cc == ‘PL’:
return NIP.is_valid(num)

return True

Chapter: file-SJawK5nsdUfrtuvo3jCWqS

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

class AccountStatus:
“””
Account status
“””

def __init__(self):
self.uid = None

self.type = None
self.valid_to = None
self.billing_plan_name = None

self.subscription_price = None
self.item_price = None
self.item_price_status = None

self.limit = None
self.request_delay = None
self.domain_limit = None
self.over_plan_allowed = None
self.excel_addin = None

self.app = None
self.cli = None
self.stats = None
self.monitor = None

self.func_get_vies_data = None

self.vies_data_count = None
self.total_count = None

def __str__(self):
return ‘AccountStatus: [uid = ‘ + str(self.uid) \
+ ‘, type = ‘ + str(self.type) \
+ ‘, valid_to = ‘ + str(self.valid_to) \
+ ‘, billing_plan_name = ‘ + str(self.billing_plan_name) \
+ ‘, subscription_price = ‘ + str(self.subscription_price) \
+ ‘, item_price = ‘ + str(self.item_price) \
+ ‘, item_price_status = ‘ + str(self.item_price_status) \
+ ‘, limit = ‘ + str(self.limit) \
+ ‘, request_delay = ‘ + str(self.request_delay) \
+ ‘, domain_limit = ‘ + str(self.domain_limit) \
+ ‘, over_plan_allowed = ‘ + str(self.over_plan_allowed) \
+ ‘, excel_addin = ‘ + str(self.excel_addin) \
+ ‘, app = ‘ + str(self.app) \
+ ‘, cli = ‘ + str(self.cli) \
+ ‘, stats = ‘ + str(self.stats) \
+ ‘, monitor = ‘ + str(self.monitor) \
+ ‘, func_get_vies_data = ‘ + str(self.func_get_vies_data) \
+ ‘, vies_data_count = ‘ + str(self.vies_data_count) \
+ ‘, total_count = ‘ + str(self.total_count) \
+ ‘]’

Chapter: file-WhtGJwagMD6whnHRZJYLVg

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

class Number:
“””
Number types
“””

EUVAT = 1
NIP = 2

Chapter: file-WxtXGC6FdrwUqNDMTK6Tf3

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

from viesapi.error import *
from viesapi.number import *
from viesapi.viesdata import *
from viesapi.accountstatus import *
from viesapi.nip import *
from viesapi.euvat import *
from viesapi.viesapiclient import *

__version__ = ‘1.2.6’

Chapter: file-8fa171hRJ8Tz3Tc42kFjq7

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”)
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

class Error:
“””
VIES API error codes
“””

NIP_EMPTY = 1
NIP_UNKNOWN = 2
GUS_LOGIN = 3
GUS_CAPTCHA = 4
GUS_SYNC = 5
NIP_UPDATE = 6
NIP_BAD = 7
CONTENT_SYNTAX = 8
NIP_NOT_ACTIVE = 9
INVALID_PATH = 10
EXCEPTION = 11
NO_PERMISSION = 12
GEN_INVOICES = 13
GEN_SPEC_INV = 14
SEND_INVOICE = 15
PREMIUM_FEATURE = 16
SEND_ANNOUNCEMENT = 17
INVOICE_PAYMENT = 18
REGON_BAD = 19
SEARCH_KEY_EMPTY = 20
KRS_BAD = 21
EUVAT_BAD = 22
VIES_SYNC = 23
CEIDG_SYNC = 24
RANDOM_NUMBER = 25
PLAN_FEATURE = 26
SEARCH_TYPE = 27
PPUMF_SYNC = 28
PPUMF_DIRECT = 29
NIP_FEATURE = 30
REGON_FEATURE = 31
KRS_FEATURE = 32
TEST_MODE = 33
ACTIVITY_CHECK = 34
ACCESS_DENIED = 35
MAINTENANCE = 36
BILLING_PLANS = 37
DOCUMENT_PDF = 38
EXPORT_PDF = 39
RANDOM_TYPE = 40
LEGAL_FORM = 41
GROUP_CHECKS = 42
CLIENT_COUNTERS = 43
URE_SYNC = 44
URE_DATA = 45
DKN_BAD = 46
SEND_REMAINDER = 47
EXPORT_JPK = 48
GEN_ORDER_INV = 49
SEND_EXPIRATION = 50
IBAN_SYNC = 51
ORDER_CANCEL = 52
WHITELIST_CHECK = 53
AUTH_TIMESTAMP = 54
AUTH_MAC = 55
IBAN_BAD = 56

DB_AUTH_IP = 101
DB_AUTH_KEY_STATUS = 102
DB_AUTH_KEY_VALUE = 103
DB_AUTH_OVER_PLAN = 104
DB_CLIENT_LOCKED = 105
DB_CLIENT_TYPE = 106
DB_CLIENT_NOT_PAID = 107
DB_AUTH_KEYID_VALUE = 108

CLI_CONNECT = 201
CLI_RESPONSE = 202
CLI_NUMBER = 203
CLI_NIP = 204
CLI_REGON = 205
CLI_KRS = 206
CLI_EUVAT = 207
CLI_IBAN = 208
CLI_EXCEPTION = 209
CLI_DATEFORMAT = 210
CLI_INPUT = 211

__codes__ = {
CLI_CONNECT: ‘Failed to connect to the VIES API service’,
CLI_RESPONSE: ‘VIES API service response has invalid format’,
CLI_NUMBER: ‘Invalid number type’,
CLI_NIP: ‘NIP is invalid’,
CLI_EUVAT: ‘EU VAT ID is invalid’,
CLI_EXCEPTION: ‘Function generated an exception’,
CLI_DATEFORMAT: ‘Date has an invalid format’,
CLI_INPUT: ‘Invalid input parameter’
}

@staticmethod
def message(code):
“””
Get error message

:param code: error code
:type code: int
:return: error message
:rtype: str
“””

if code < Error.CLI_CONNECT or code > Error.CLI_INPUT:
return None

return Error.__codes__[code]

Chapter: file-BWd1zavvqRpJGRVsZKy71K

#
# -*- coding: utf-8 -*-
#
# Copyright 2022-2023 NETCAT (www.netcat.pl)
#
# Licensed under the Apache License, Version 2.0 (the “License”);
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# @author NETCAT <firma@netcat.pl>
# @copyright 2022-2023 NETCAT (www.netcat.pl)
# @license https://www.apache.org/licenses/LICENSE-2.0
#

import re

class NIP:
“””
NIP number validator
“””

@staticmethod
def normalize(nip):
“””
Normalizes form of the NIP number
:param nip: input string
:type nip: str
:returns: normalized string or False
:rtype: str or False
“””

if not nip:
return False

nip = re.sub(‘[ -]’, ”, nip).upper()

if not re.match(‘[0-9]{10}’, nip):
return False

return nip

@staticmethod
def is_valid(nip):
“””
Checks if specified NIP is valid
:param nip: input string
:type nip: str
:returns: True if NIP is valid
:rtype: bool
“””

nip = NIP.normalize(nip)

if not nip:
return False

w = [6, 5, 7, 2, 3, 4, 5, 6, 7]
res = 0

for i in range(0, len(w)):
res += int(nip[i]) * w[i]

res %= 11

if res != int(nip[9]):
return False

return True