Skip to content

Commit

Permalink
First HMRC is working
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Seichter committed Jul 6, 2024
1 parent 83b349d commit 0eeaa50
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
25 changes: 25 additions & 0 deletions src/codes_hmrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,29 @@
"en": "The application did not receive a reply within the allocated time period, try again later",
},
{"status": "zip", "de": "Postleitzahl", "en": "Postalcode"},
{
"status": "targetVrn",
"de": "targetVrn does not match a registered company",
"en": "targetVrn does not match a registered company",
},
{
"status": "requesterVrn",
"de": "requesterVrn does not match a registered company",
"en": "requesterVrn does not match a registered company",
},
{
"status": "Invalid targetVrn",
"de": "Invalid targetVrn - Vrn parameters should be 9 or 12 digits",
"en": "Invalid targetVrn - Vrn parameters should be 9 or 12 digits",
},
{
"status": "Invalid requesterVrn",
"de": "Invalid requesterVrn - Vrn parameters should be 9 or 12 digits",
"en": "Invalid requesterVrn - Vrn parameters should be 9 or 12 digits",
},
{
"status": "Invalid targetVrn and requesterVrn",
"de": "Invalid targetVrn and requesterVrn - Vrn parameters should be 9 or 12 digits",
"en": "Invalid targetVrn and requesterVrn - Vrn parameters should be 9 or 12 digits",
},
]
32 changes: 15 additions & 17 deletions src/validate_hmrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,17 @@ def defaultencode(o):
raise TypeError(repr(o) + " is not JSON serializable")


def load_codes(lang, errorcode):
if errorcode is None:
return None
def load_codes(lang, message):
if message is None:
return message

for code in codes_hmrc.returncodes:
if code["status"] == errorcode:
if message.startswith(code["status"]):
if lang == "de":
return code["de"]
if lang == "en":
return code["en"]
return None
return message


def start_validation(payload):
Expand All @@ -79,32 +79,30 @@ def start_validation(payload):
logger.debug(resp.status, resp.data)
result = json.loads(resp.data)

result["errorcode"] = None

validationresult = {
"key1": payload["key1"],
"key2": payload["key2"],
"ownvat": payload["ownvat"],
"foreignvat": payload["foreignvat"],
"type": 'HMRC',
"valid": resp.status == 200,
"errorcode": result["errorcode"],
"errorcode": result.get('errorcode',''),
"errorcode_description": load_codes(
payload["lang"], result["errorcode"]
payload["lang"], result["message"]
),
"valid_from": "",
"valid_to": "",
"timestamp": datetime.datetime.now(datetime.timezone.utc).strftime(
"%Y-%m-%dT%H:%M:%S"
),
"company": result["target"]["name"],
"address": result["target"]["address"]["line1"]
+ chr(13)
+ result["target"]["address"]["line2"],
"town": "",
"zip": result["target"]["address"]["postcode"],
"street": "",
)
}
if "target" in result:
validationresult["company"]= result["target"]["name"]
validationresult["address"]= result["target"]["address"]["line1"] + chr(13) + result["target"]["address"]["line2"]
validationresult["town"]= ""
validationresult["zip"]= result["target"]["address"]["postcode"]
validationresult["street"]= ""


return validationresult
except Exception as e:
Expand Down

0 comments on commit 0eeaa50

Please sign in to comment.