def process_hub_request(self, msg): phone = ISO8583Parser.extract_phone(msg) batch_date = self._construct_date_for_batch() amount = ISO8583Parser.extract_amount(msg) amount = amount.rjust(3, '0') amount = 'VVS' + amount batch = phone + batch_date pos = DEFAULT_POS passw = BANELCO_PASS entity = BANELCO_ID checksum = self._hash_info(batch, phone, entity, amount, pos, passw) xml_string = self._ensamble_xml(batch, phone, entity, amount, pos, checksum) response_xml = self.send_xml_request_to_hub(xml_string) return response_xml
def process_request(self, msg): mti = ISO8583Parser.get_MTI(msg) try: handler = self._handlers_mti[mti] except: return "BAD LINE" #The errors should be handled according to doc try: return handler(msg) except AssertionError: return "No esta Logueado" except: return "Error interno"
def process_mti_req(self, msg): # Check time to live against opened since now = datetime.datetime.now() try: assert self._logged, True assert now - self._opened_since < self._ttl except: raise hub_handler = HubHandler() response_unproc = hub_handler.process_hub_request(msg) response_hub = hub_handler.parse_xml_hub_response(response_unproc) result_transaction, importeOut = self.translate_to_ISO8583(response_hub) # Send message parameters based on result_transaction return ISO8583Parser.ensamble_response_req(msg, importeOut, result_transaction)
def process_nmi_echo_test(self, msg): # Renew time to live return ISO8583Parser.ensamble_response_admin_conn(msg, NMI_ECHO_TEST, OK_TRANSACTION)
def process_nmi_logout(self, msg): # After this this particular thread should expire return ISO8583Parser.ensamble_response_admin_conn(msg, NMI_LOGOUT, OK_TRANSACTION)
def process_nmi_login(self, msg): return ISO8583Parser.ensamble_response_admin_conn(msg, NMI_LOGIN, OK_TRANSACTION)
def process_mti_admin_conn(self, msg): nmi = ISO8583Parser.get_NMI(msg) if nmi is not None: return self._handlers_nmi[nmi](msg) else: raise ValueError
def test_extract_amount(self): expected = '10' result = ISO8583Parser.extract_amount(MOCK_MESSAGE_REQ) self.assertEquals(result, expected)
def test_ensamble_response_req(self): expected = MOCK_MESSAGE_RESPONSE_REQ result = ISO8583Parser.ensamble_response_req(MOCK_MESSAGE_REQ, '0', OK_TRANSACTION) self.assertEquals(result, expected)
def test_extract_phone(self): expected = '1144558899' result = ISO8583Parser.extract_phone(MOCK_MESSAGE_REQ) self.assertEquals(result, expected)
def test_ensamble_response_admin(self): expected = MOCK_MESSAGE_RESPONSE_ADMIN_CONN result = ISO8583Parser.ensamble_response_admin_conn(MOCK_MESSAGE_ADMIN_CONN, NMI_LOGIN, \ OK_TRANSACTION) self.assertEquals(result, expected)
def test_get_mti_req_error_len(self): expected = MTI_REQ_ERROR result = ISO8583Parser.get_MTI(MOCK_MESSAGE_REQ_BL) self.assertEquals(result, expected)
def test_get_mti_admin_conn_error_len(self): expected = MTI_ADMIN_CONN_ERROR result = ISO8583Parser.get_MTI(MOCK_MESSAGE_ADMIN_CONN_BL) self.assertEquals(result, expected)
def test_get_nmi_0810(self): expected = NMI_LOGIN result = ISO8583Parser.get_NMI(MOCK_MESSAGE_RESPONSE_ADMIN_CONN) self.assertEquals(result, expected)
def test_get_mti(self): expected = MTI_ADMIN_CONN result = ISO8583Parser.get_MTI(MOCK_MESSAGE_ADMIN_CONN) self.assertEquals(result, expected)