-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi.py
More file actions
92 lines (84 loc) · 2.55 KB
/
Copy pathapi.py
File metadata and controls
92 lines (84 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import json
from datetime import datetime
from static import Intent
def send_transaction(command, **params):
result = []
if command == Intent.ADD_PRODUCT or command == Intent.ADD_BAGS:
result.append(add_command(
'addItem',
itemCode=int(params['code'])
))
elif command == Intent.REQUEST_WEIGHTING:
result.append(add_command(
'subscribe',
frequency=1000,
type='Weight'
))
result.append(add_command(
'addItem',
eventId=generate_eventid(),
itemCode=int(params['code'])
))
result.append(add_command(
'unsubscribe',
eventId=generate_eventid(),
type='Weight'
))
elif command == Intent.REMOVE_PRODUCT or command == Intent.REMOVE_BAGS:
if 'code' in params:
result.append(add_command(
'deleteAll',
itemCode=int(params['code'])
))
else:
result.append(add_command(
'deletePosition',
itemNumber=int(params['position'])
))
elif command == Intent.REQUEST_PAYMENT:
if 'final' in params and params['final']:
result.append(add_command(
'payment',
paymentType='Card'
))
else:
result.append(add_command(
'subTotal'
))
elif command == Intent.PASS_LOYALTY:
result.append(add_command(
'addLoyalty',
type='Card',
itemCode=int(params['code'])
))
elif command == Intent.ADD_PROMO_CODE:
result.append(add_command(
'addLoyalty',
type='Coupon',
itemCode=int(params['code'])
))
elif command == Intent.SPEND_BONUS:
result.append(add_command(
'payment',
paymentType='Loyalty',
amount=params['amount']
))
elif command == Intent.CANCEL_PAYMENT:
result.append(add_command(
'returnAddITem'
))
elif command == Intent.CANCEL_ORDER:
result.append(add_command(
'deleteTransaction'
))
print('——— JSONs to TB ———')
print(' —> ', '\n —> '.join(map(json.dumps, result)), sep='')
print('——————')
def add_command(command, **params):
return {
'action': command,
'eventId': generate_eventid(),
**params
}
def generate_eventid():
return 'sco' + str(int(datetime.now().timestamp() * 100000))