예제 #1
0
    def test_as_dict(self):
        c = Registration('777777', 0xa0)

        self.assertEqual({
            'password': '******',
            'config_byte': 0xa0
        }, c.as_dict())
예제 #2
0
 def register_unlocked(self):
     """
     registers to the PT, not locking the master menu on it.
     do not use in production environment.
     """
     ret = self.transmit(
         Registration(
             password=self.password,
             config_byte=Registration.generate_config(
                 ecr_controls_admin=False),
         ))
     if ret == TRANSMIT_OK:
         self._state_registered = True
     return ret
예제 #3
0
    def test_del(self):
        c = Registration(service_byte=0x1)

        c.password = '******'

        self.assertEqual('123456', c.password)
        self.assertIsNotNone(c.service_byte)

        del c.password
        del c.service_byte

        self.assertIsNone(c.password)
        self.assertIsNone(c.service_byte)

        c.password = '******'

        self.assertEqual('234567', c.password)
예제 #4
0
    def register(self, config_byte, **kwargs):
        """
        registers this ECR at the PT, locking menus
        for real world conditions.
        """
        kwargs = dict(kwargs)
        if self.password:
            kwargs['password'] = self.password
        if config_byte is not None:
            kwargs['config_byte'] = config_byte

        ret = self.transmit(Registration(**kwargs))

        if ret == TRANSMIT_OK:
            # get the terminal-id if its there.
            for inc, packet in self.transmitter.last_history:
                if inc and isinstance(packet, Completion):
                    self.terminal_id = packet.as_dict().get('tid', '00' * 4)
            # remember this.
            self._state_registered = True
        return ret
예제 #5
0
                #    return self.send_message(message, tries + 1, no_answer)
                #else:
                raise common.TransportLayerException("Could not send message")
            elif not acknowledge:
                # this happens quite a lot with the ingenico devices.
                # possibly a workaround would be nice.
                raise common.TransportTimeoutException(
                    "No Answer, Possible Timeout")
            else:
                raise common.TransportLayerException(
                    "Unknown Acknowledgment Byte %s" % conv.bs2hl(acknowledge))

    def send(self, apdu, tries=0, no_wait=False):
        """
            automatically converts an apdu into a message.
        """
        return self.send_message(SerialMessage(apdu), tries, no_wait)


# self test
if __name__ == '__main__':
    c = SerialTransport('/dev/ttyUSB0')
    from ecrterm.packets.base_packets import Registration
    if c.connect():
        print("connected to usb0")
    else:
        exit()
    # register
    answer = c.send_serial(Registration())
    print(answer)
예제 #6
0
result['data'] = 1

sys.stdout.write(json.dumps(result, indent=1))
sys.stdout.write("\n")
sys.stdout.close()

if __name__ == '__main__':
    e = ECR(device='socket://' + data['ip'] + ':' + data['port'],
            password=data['passwd'])
    # reenable logging:
    #e.transport.slog = ecr_log
    #print(e.detect_pt())
    if e.detect_pt():
        e.register(config_byte=Registration.generate_config(
            ecr_prints_receipt=False,
            ecr_prints_admin_receipt=False,
            ecr_controls_admin=True,
            ecr_controls_payment=True))
        if data['action'] == 'end_of_day':
            e.end_of_day()
            e.wait_for_status()
            #status = e.status()
            #print( status )
        if data['action'] == 'pay':
            if e.payment(amount_cent=data['amount']):
                printer(e.last_printout())
                e.wait_for_status()
                e.show_text(lines=[
                    'Auf Wiedersehen ' + data['name'] + '! ', ' ',
                    'Zahlung erfolgt'
                ],
 def test_Anmeldung(self):
     # Register Packet std.
     data_expected = '10 02 06 00 06 12 34 56 BA 09 78 10 03 24 C3'
     pk = Registration()
     self.assertEqual(data_expected, list_of_bytes(pk))
예제 #8
0
    def test_simple_create_serialize(self):
        c = Registration('777777', 0xa0, cc='0978')
        c.service_byte = 0x0a

        self.assertEqual(bytearray.fromhex('060008777777a00978030a'),
                         c.serialize())
예제 #9
0
 def test_serialize_fixed_no_optional(self):
     c = Registration('987654', config_byte=0x41)
     self.assertEqual(bytearray.fromhex('06000498765441'), c.serialize())
예제 #10
0
    def test_get(self):
        c = Registration('123456')

        self.assertEqual('123456', c.get('password'))
        self.assertEqual(None, c.get('password1', None))
예제 #11
0
    def test_nonexisting_attributes(self):
        c = Registration('123456')

        self.assertRaises(AttributeError, lambda: c.foobarbaz)
        self.assertIsNone(c.cc)