def load_keys(self): print("load_keys") obj = TransactionData() cmd = STX + "0800" + ETX cmd_hex = posutils.hex_string(cmd, crc=True) try: results = obj.set_response(self.__execute(cmd_hex)) for result in results: if result == ACK: break results = obj.set_response(self.__wait_data(30)) flag = self.__get_flags(results[0], TX_RESPUESTA) obj.set_response_code(flag) if flag == "00": obj.result = True obj.add_content( "codigo_comercio", self.__get_flags(results[0], TX_CODIGO_COMERCIO)) obj.add_content("terminal_id", self.__get_flags(results[0], TX_TERMINAL_ID)) except Exception as err: print("More errors: {}".format(err)) self.ack() return obj
def ack(self, nowait=False): obj = TransactionData() cmd = ACK cmd_hex = posutils.hex_string(cmd) try: obj.set_response(self.__execute(cmd_hex, nowait=nowait)) obj.result = True except IOError as err: print("More errors: {}".format(err)) return obj
def close(self): obj = TransactionData() cmd = STX + "0500|0" + ETX cmd_hex = posutils.hex_string(cmd, crc=True) try: results = obj.set_response(self.__execute(cmd_hex)) for result in results: obj.set_response_code(result[7:9]) obj.set_text(self.__get_properties(result[7:9])) except IOError as err: print("More errors: {}".format(err)) return obj
def all_transactions(self): obj = TransactionData() cmd = STX + "0700|0" + ETX cmd_hex = posutils.hex_string(cmd, crc=True) try: result = obj.set_response(self.__execute(cmd_hex)) while result == ACK: result = obj.set_response(self.__execute(cmd_hex)) flag = self.__get_flags(result, TX_RESPUESTA) obj.set_text(self.__get_properties(flag)) obj.set_response_code(flag) except IOError as err: print("More errors: {}".format(err)) return obj
def sale_detail(self): # TODO check return data obj = TransactionData() cmd = STX + "0260|0" + ETX + "K" cmd_hex = posutils.hex_string(cmd) try: result = obj.set_response(self.__execute(cmd_hex)) if result == ACK: obj.result = True obj.set_response_code("00") obj.set_text( "Detalle de ventas en Pos solicitado exitosamente.") else: obj.set_text("Error al obtener detalle de ventas.") except IOError as err: print("More errors: {}".format(err)) return obj
def resp_init(self): print("response initialization...") obj = TransactionData() cmd = STX + "0080" + ETX cmd_hex = posutils.hex_string(cmd, crc=True) try: results = obj.set_response(self.__execute(cmd_hex)) for result in results: obj.set_text("Problema al conectar") if result == ACK: obj.result = True obj.set_text("Inicializado") break except IOError as err: print("More errors: {}".format(err)) return obj
def polling(self): print("POS POLLING...") obj = TransactionData() cmd = STX + "0100" + ETX cmd_hex = posutils.hex_string(cmd, crc=True) try: results = obj.set_response(self.__execute(cmd_hex)) if len(results) == 0: raise IOError("Empty result") if results[0] == ACK: obj.result = True obj.set_text("Conexion establecida en puerto: {}".format( str(self.device))) else: obj.set_text("Puerto incorrecto, intente con otro puerto.") except IOError as err: print("More errors: {}".format(err)) self.ack(nowait=True) return obj
def cancel_transaction(self): # , **kwargs): obj = TransactionData() cmd = STX + "1200" + ETX cmd_hex = posutils.hex_string(cmd, crc=True) try: result = obj.set_response(self.__execute(cmd_hex)) while result == ACK: result = obj.set_response(self.__execute(cmd_hex)) flag = self.__get_flags(result, TX_RESPUESTA) obj.set_response_code(flag) obj.set_text(self.__get_properties(flag)) if flag == "00": obj.result = True obj.add_content("codigo_comercio", self.__get_flags(result, TX_CODIGO_COMERCIO)) obj.add_content("terminal_id", self.__get_flags(result, TX_TERMINAL_ID)) obj.add_content( "codigo_autorizacion", self.__get_flags(result, ANULA_TX_CODIGO_AUTORIZACION)) self.ack() except IOError as err: print("More errors: {}".format(err)) return obj
def sale_init(self, amount, voucher='0', dummy=False): # , **kwargs): voucher = "" + str(voucher) print("sale_init({}, {}, {})".format(amount, voucher, dummy)) obj = TransactionData() cmd = STX + "0200|" + str(amount) + "|" + str( voucher[-6:]) + "|0|1" + ETX cmd_hex = posutils.hex_string(cmd, crc=True) flag = False res_type = None try: results = obj.set_response(self.__execute(cmd_hex)) print("Sends the sale") if results[0] == ACK: print("wait for more data") results = obj.set_response(self.__wait_data(30)) result = None for res in results: res_type = self.__get_flags(res, TX_MENSAJE) flag = self.__get_flags(res, TX_RESPUESTA) print("status data: {}".format(res)) if flag in STOP_TOKENS: result = res break while flag not in STOP_TOKENS: res = obj.set_response(self.__wait_data(30)) for data in res: res_type = self.__get_flags(data, TX_MENSAJE) flag = self.__get_flags(data, TX_RESPUESTA) print("current flag: {}".format(flag)) if flag not in STOP_TOKENS: result = res break self.ack(nowait=True) print("current result: {}".format(result)) if result is not None and flag == "00" and res_type == "0210": print("result: {}".format(result)) if isinstance(result, list): result = result[0] result = result.split('|') obj.add_content("num_voucher", voucher) obj.add_content("codigo_comercio", result[TX_CODIGO_COMERCIO]) obj.add_content("terminal_id", result[TX_TERMINAL_ID]) obj.add_content("num_voucher_mapfre", result[VENTA_TX_NUM_VOUCHER_MAPFRE]) obj.add_content("codigo_autorizacion", result[VENTA_TX_CODIGO_AUTORIZACION]) obj.add_content("monto", result[VENTA_TX_MONTO]) obj.add_content("ult_4_numeros", result[VENTA_TX_ULT_4_DIGITOS]) obj.add_content("codigo_operacion", result[VENTA_TX_CODIGO_OPERACION]) obj.add_content("tipo_tarjeta", result[VENTA_TX_TIPO_TARJETA]) obj.add_content("numero_cuenta", result[VENTA_TX_CUENTA]) obj.add_content("codigo_tarjeta", result[VENTA_TX_CODIGO_TARJETA]) obj.add_content("fecha", result[VENTA_TX_FECHA_TRANSAC]) obj.add_content("hora", result[VENTA_TX_HORA_TRANSAC]) obj.add_content("num_cuotas", result[VENTA_OP_NUM_CUOTA]) obj.add_content("monto_cuota", result[VENTA_OP_MONTO_CUOTA]) obj.add_content("status", "OK") obj.set_text(self.__get_properties(flag)) obj.set_response_code(flag) obj.result = True elif flag == "00" and res_type != "210": obj.set_response_code(flag) obj.set_text(self.__get_properties(flag)) obj.add_content("status", "WAIT") obj.add_content("debug", results) else: obj.set_response_code(flag) obj.set_text(self.__get_properties(flag)) obj.add_content("status", "FAIL") obj.add_content("debug", results) except Exception as err: print("More errors: {}".format(err)) return obj