Refactor ISO8583Processor to improve MTI handling and logging; include invoice I…

…D in performance logs
1 parent 3c485e6c
......@@ -40,17 +40,23 @@ class ISO8583Processor:
# print(f"[process_file] db_config: {db_config}")
iso = ISO8583(iso=data)
print(iso.showBitmap())
# print(iso.showBitmap())
# try:
# invoice_id = iso.getBit(61) if iso.getBit(61) else None
# log.info(f"Processing file: {filename}, MTI: {iso.getMTI()}, Invoice ID (Bit 61): {invoice_id}")
# except Exception as e:
# log.error(f"Error parsing ISO8583 message from {filename}: {e}")
bit39 = '00'
mti = iso.getMTI() if iso.getMTI() else '0000'
log.info(f"MTI detected: {mti}")
response = b''
invoice_id = ""
if mti == '0800':
log.info(f"Handling network management MTI: {mti}")
iso.setMTI('0810')
elif mti in ('0200', '0210'):
logging.info(f"Handling transaction MTI: {mti}")
func = iso.getBit(3) if iso.getBit(3) else '000000'
invid = iso.getBit(61) if iso.getBit(37) else None
invoice_id = re.sub(r'\D', '', invid) if invid else '000000'
......@@ -109,19 +115,16 @@ class ISO8583Processor:
logging.info(f"Handling reversal MTI: {mti}")
response = b'RESP:0400/0420' # Add bit 7, 4, 62, 39 as needed
else:
logging.warning(f"Unknown MTI: {mti}")
response = b'UNKNOWN MTI'
if response == b'UNKNOWN MTI':
logging.info(f"Removed unprocessable file: {filename}")
return response
else:
logging.error(f"Unknown MTI: {mti}")
bit39 = '96' # System malfunction
iso.setBit(7, self.get_bit7())
iso.setBit(39, bit39)
response = iso.getRawIso()
log.info(
f"[WRITE] Prepared response for {filename}, data: {response.hex() if isinstance(response, bytes) else response}")
return response
end_time = time.time()
elapsed = end_time - start_time
log.info(
f"[PERF] Processed {filename} in {elapsed:.3f} seconds (MTI={mti})")
f"[PERF] Processed {filename} {invoice_id} in {elapsed:.3f} seconds (MTI={mti})")
return response
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!