tk120404 / gst

GSTIN regex and GST checksum validation. Verify/Validate the gstin number using the regex and checksum functions available in various programming languages
Apache License 2.0
10 stars 3 forks source link

Checksum Fails #3

Open patelnav opened 5 years ago

patelnav commented 5 years ago

I've had the checksum fail on some valid GST numbers. Please check your algo with well known GST numbers

jainprashul commented 4 years ago

on js or py

nirmalraghavan commented 3 years ago

JS will fail for 32AADCK5978M1Z0

EFFICIENTCORPORATES commented 2 years ago

The check sum which has been calculated is not comprehensive. There are different types of GSTIN and each has a different Regex. A single GST number can actually comply Regex of different Type GSTIN.

Below are the REGEX for GST Number. using regex in python. (Would be glad to discuss on any Python-related automation for GST)

norm_com_isd = re.compile("[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[Zz1-9A-Ja-j]{1}[0-9a-zA-Z]{1}")

unbody = re.compile("[0-9]{4}[A-Z]{3}[0-9]{5}[UO]{1}[N][A-Z0-9]{1}")

govt_depid = re.compile("[0-9]{2}[a-zA-Z]{4}[0-9]{5}[a-zA-Z]{1}[0-9]{1}[Z]{1}[0-9]{1}")

nri_id = re.compile("[0-9]{4}[a-zA-Z]{3}[0-9]{5}[N][R][0-9a-zA-Z]{1}")

tds_id = re.compile("[0-9]{2}[a-zA-Z]{4}[a-zA-Z0-9]{1}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[D]{1}[0-9a-zA-Z]{1}")

tcs_id = re.compile("[0-9]{2}[a-zA-Z]{5}[0-9]{4}[a-zA-Z]{1}[1-9A-Za-z]{1}[C]{1}[0-9a-zA-Z]{1}")

oidar_id = re.compile("[9][9][0-9]{2}[a-zA-Z]{3}[0-9]{5}[O][S][0-9a-zA-Z]{1}")
tk120404 commented 2 years ago

@EFFICIENTCORPORATES Please share the details or link to understand the GSTIN

EFFICIENTCORPORATES commented 2 years ago

The Break Up of GSTIN is very well explained by you in your README file... But one thing which we need to understand is that there are different types of GSTIN. A single entity can have its TDS GSTIN, Normal GSTIN and an ISD GSTIN for complying with different rules of GST.

Similarly, the GST Number allocated to Govt Department or a United Nations body is different. Also, a Non-Resident Taxable Person (NRTP) has a different GSTIN. Companies like Amazon Prime, Hotstar, Netflix come under the category of OIDAR and have different GSTIN..

Regex for each one of these GSTIN will be different... For further details you can visit the GST developers site:

https://developer.gst.gov.in/apiportal/taxpayer/returns

nithinprabhu commented 1 month ago

The checksum validation is failing because there is an edge condition that needs to handled i.e. when the final checksum code is 36 we need to attribute it to 0.

def checksum(gst):
    check = gst[-1]
    gst = gst[:-1]
    l = [int(c) if c.isdigit() else ord(c)-55 for c in gst]
    l = [val*(ind % 2 + 1) for (ind, val) in list(enumerate(l))]
    l = [(int(x/36) + x%36) for x in l]
    csum = (36 - sum(l)%36)
    if(csum == 36):
        csum = "0"
    else:
        csum = str(csum) if (csum < 10) else chr(csum + 55)
    return True if (check == csum) else False