Skip to content

Commit f64520f

Browse files
committed
Added README.md
1 parent 284bed6 commit f64520f

8 files changed

+133
-0
lines changed

β€ŽREADME.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**For detailed information on the SDK visit the [overview](https://cards.app/Developers/CardReader/Overview), [requirements](https://cards.app/Developers/CardReader/Requirements) and [getting started](https://cards.app/Developers/CardReader/GettingStarted) pages in our website.**

β€Žcards/CardDetails.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class CardDetails:
2+
"""Card Details Class"""
3+
def __init__(self, user_id):
4+
self.user_id = user_id

β€Žcards/CardReader.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from cards.ReaderSettings import ReaderSettings
2+
from cards.ReaderCredentials import ReaderCredentials
3+
from cards.NativeBaseDriver import *
4+
from cards.CardDetails import CardDetails
5+
from cards.CardTapResponse import CardTapResponse
6+
7+
8+
class ReaderStatus:
9+
"""Card Tap Error Enum"""
10+
Disconnected = 1
11+
Connected = 2
12+
AlreadyInUse = 3
13+
14+
15+
class CardReader:
16+
def __init__(self, reader_settings, reader_credentials):
17+
self.reader_credentials = reader_credentials
18+
self.on_card_tap = None
19+
self.on_status_change = None
20+
21+
if reader_settings is None:
22+
self.reader_settings = ReaderSettings(get_devices_list()[0])
23+
else:
24+
self.reader_settings = reader_settings
25+
26+
self.__instance = create_instance_by_name(self.reader_settings.device_name, self.reader_credentials.api_key)
27+
28+
def __del__(self):
29+
destroy_instance(self.__instance)
30+
31+
def listen(self):
32+
run_on_card_present(self.__instance, self.__get_internal_card_tap_handler(), self.on_status_change)
33+
34+
def __get_internal_card_tap_handler(self):
35+
def internal_card_tap_handler(card_tap_response):
36+
response = CardTapResponse(card_tap_response.isSuccess, card_tap_response.errorCode, CardDetails(card_tap_response.uid[:24].decode()))
37+
38+
self.on_card_tap(response)
39+
40+
return internal_card_tap_handler

β€Žcards/CardTapResponse.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class CardTapError:
2+
"""Card Tap Error Enum"""
3+
InternetError = 1
4+
ApiKeyInvalid = 2
5+
TransactionTokenInvalid = 3
6+
UserNotAssociatedWithCardReader = 4
7+
NoSuchTPID = 5
8+
TransactionTokenMissing = 6
9+
TransactionTokenDoesntExist = 7
10+
TransactionTokenAlreadyUsed = 8
11+
TransactionTokenAlreadyValidated = 9
12+
13+
14+
class CardTapResponse:
15+
"""Card Tap Response Class"""
16+
def __init__(self, is_success, error, card_details):
17+
self.is_success = is_success
18+
self.error = error
19+
self.card_details = card_details

β€Žcards/NativeBaseDriver.py

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from ctypes import *
2+
3+
4+
class DevicesList(Structure):
5+
_fields_ = [("names", POINTER(c_char_p)),
6+
("count", c_int)]
7+
8+
9+
class CardTapResponse(Structure):
10+
_fields_ = [("isSuccess", c_int),
11+
("errorCode", c_int),
12+
("uid", c_char*32)]
13+
14+
15+
CardsBase = windll.LoadLibrary('CardsBase.dll')
16+
17+
createInstanceByName = CardsBase.createInstanceByName
18+
destroyInstance = CardsBase.destroyInstance
19+
runOnCardPresent = CardsBase.runOnCardPresent
20+
getDevicesList = CardsBase.getDevicesList
21+
freeDevicesList = CardsBase.freeDevicesList
22+
23+
getDevicesList.restype = DevicesList
24+
createInstanceByName.restype = c_void_p
25+
destroyInstance.restype = c_int
26+
runOnCardPresent.restype = None
27+
freeDevicesList.restype = None
28+
29+
CARD_TAP_FUNC = WINFUNCTYPE(None, CardTapResponse)
30+
STATUS_CHANGE_FUNC = WINFUNCTYPE(None, c_int)
31+
32+
33+
def get_devices_list():
34+
devices_list_struct = getDevicesList()
35+
devices_list = []
36+
37+
for i in range(devices_list_struct.count):
38+
devices_list.append(devices_list_struct.names[i].decode())
39+
40+
freeDevicesList(devices_list_struct)
41+
42+
return devices_list
43+
44+
45+
def create_instance_by_name(device_name, api_key):
46+
return createInstanceByName(c_char_p(device_name.encode()), c_char_p(api_key.encode()))
47+
48+
49+
def destroy_instance(instance):
50+
return destroyInstance(instance)
51+
52+
53+
def run_on_card_present(instance, card_tap_handler, status_change_handler):
54+
runOnCardPresent(instance, CARD_TAP_FUNC(card_tap_handler), STATUS_CHANGE_FUNC(status_change_handler))

β€Žcards/ReaderCredentials.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ReaderCredentials:
2+
"""Reader Credentials Class"""
3+
def __init__(self, api_key):
4+
self.api_key = api_key

β€Žcards/ReaderSettings.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class ReaderSettings:
2+
"""Reader Settings Class"""
3+
def __init__(self, device_name):
4+
self.device_name = device_name

β€Žcards/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from cards.CardReader import ReaderStatus, CardReader
2+
from cards.ReaderCredentials import ReaderCredentials
3+
from cards.ReaderSettings import ReaderSettings
4+
from cards.CardTapResponse import CardTapResponse, CardTapError
5+
6+
7+
__all__ = ['ReaderStatus', 'CardReader', 'ReaderCredentials', 'ReaderSettings', 'CardTapResponse']

0 commit comments

Comments
Β (0)