Skip to content

Commit

Permalink
More data printed when debug mode is enabled. +deps hexdump.
Browse files Browse the repository at this point in the history
+ prevent io exception when using raspberry pi.
  • Loading branch information
TAHRI Ahmed committed Aug 18, 2017
1 parent be826b9 commit 00902e1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
test_suite='test',
url='https://github.com/Ousret/pyTeliumManager',
download_url='https://github.com/Ousret/pyTeliumManager/archive/2.2.2.tar.gz',
install_requires=['pyserial>=3.3', 'pycountry>=17.0', 'payment_card_identifier>=0.1.2'],
install_requires=['pyserial>=3.3', 'pycountry>=17.0', 'payment_card_identifier>=0.1.2', 'hexdump'],
tests_require=['Faker'],
keywords=['ingenico', 'telium manager', 'telium', 'payment', 'credit card', 'debit card', 'visa', 'mastercard',
'merchant', 'pos'],
Expand Down
17 changes: 12 additions & 5 deletions telium/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from serial import Serial
from glob import glob
import curses.ascii
from hexdump import hexdump
from telium.constant import *
from telium.payment import TeliumResponse

Expand All @@ -13,7 +14,7 @@ class DataFormatUnsupportedException(TypeError):
pass


class TerminalSerialLinkClosed(IOError):
class TerminalSerialLinkClosedException(IOError):
pass


Expand Down Expand Up @@ -172,6 +173,11 @@ def _read_answer(self, expected_size=TERMINAL_ANSWER_COMPLETE_SIZE):
raw_data = self._device.read(size=expected_size)
data_len = len(raw_data)

if self._debugging:
print('<---------------------------- Chunk from Terminal :: {0} byte(s).'.format(data_len))
hexdump(raw_data)
print('----------------------------> End of Chunk from Terminal')

if data_len != expected_size:
raise TerminalUnexpectedAnswerException('Raw read expect size = {0} '
'but actual size = {1}.'.format(expected_size, data_len))
Expand All @@ -196,7 +202,7 @@ def ask(self, telium_ask, raspberry_pi=False):
"""

if not self.is_open:
raise TerminalSerialLinkClosed("Your device isn\'t opened yet.")
raise TerminalSerialLinkClosedException("Your device isn\'t opened yet.")

if raspberry_pi:
self._device.timeout = 0.3
Expand All @@ -223,17 +229,18 @@ def ask(self, telium_ask, raspberry_pi=False):

return True

def verify(self, telium_ask, waiting_timeout=DELAY_TERMINAL_ANSWER_TRANSACTION):
def verify(self, telium_ask, waiting_timeout=DELAY_TERMINAL_ANSWER_TRANSACTION, raspberry_pi=False):
"""
Wait for answer and convert it for you.
:param telium.TeliumAsk telium_ask: Payment info
:param float waiting_timeout: Custom waiting delay in seconds before giving up on waiting ENQ signal.
:param bool raspberry_pi: Set it to True if you'r running Raspberry PI
:return: TeliumResponse, None or Exception
:rtype: telium.TeliumResponse|None
"""

if not self.is_open:
raise TerminalSerialLinkClosed("Your device isn\'t opened yet.")
raise TerminalSerialLinkClosedException("Your device isn\'t opened yet.")

answer = None # Initializing null variable.

Expand All @@ -256,7 +263,7 @@ def verify(self, telium_ask, waiting_timeout=DELAY_TERMINAL_ANSWER_TRANSACTION):
self._send_signal('ACK') # Notify terminal that we've received it all.

# The terminal should respond with EOT aka. End of Transmission.
if not self._wait_signal('EOT'):
if not self._wait_signal('EOT') and not raspberry_pi:
raise TerminalUnexpectedAnswerException(
"Terminal should have ended the communication with 'EOT'. Something's obviously wrong.")

Expand Down

0 comments on commit 00902e1

Please sign in to comment.