def authenticate(self): auth_req = su.sanitize_msg(AUTH_REQ) auth_resp = self.client.exchange_msg(auth_req) # try: xml_msg = self.extract_xml_from_msg(auth_resp) # except Exception: # raise Exception('Invalid xml') try: msg_dict = xmltodict.parse(xml_msg) # log.msg(msg_dict) except Exception: raise Exception("Invalid xml") print(auth_resp) return auth_resp
if self.is_payment(): print('msg is payment') try: self.validate_payment(data) print('payment passed validation') except Exception, e: #should create a specific ParseException raise e #todo: translate to tsys message #todo: make the payment happen if self.is_refund(): print('msg is refund') return su.sanitize_msg(SALE_APPROVED_RSP) def calc_lrc(self, msg): lrc = 0 for i in msg: lrc ^= ord(i) return lrc def construct_msg(self, msg): tmp_msg = REC_FORM + APP_TYPE + DELIM + ROUTE_ID + msg + ETX lrc = self.calc_lrc(tmp_msg) final_msg = STX + tmp_msg + chr(lrc)