-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLemonWay.py
More file actions
65 lines (53 loc) · 1.92 KB
/
LemonWay.py
File metadata and controls
65 lines (53 loc) · 1.92 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
import socket, json, requests
# Put the Directkit JSON2 here (your should see 'json2' in your URL)
# Make sure your server is whitelisted, otherwise you will receive 403-forbidden
DIRECTKIT_JSON2 = 'https://sandbox-api.lemonway.fr/mb/demo/dev/directkitjson2/Service.asmx'
LOGIN = 'society'
PASSWORD = '123456'
VERSION = '1.8'
LANGUAGE = 'en'
SSL_VERIFICATION = False
UA = 'ua'
class LWException(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return 'LWException: ' + self.value
# IP of end-user
def getUserIP():
hostname = socket.gethostname()
ip = socket.gethostbyname(hostname)
return ip if ip != '' else '127.0.0.1'
def callService(serviceName, parameters):
# add missing required parameters
parameters['wlLogin'] = LOGIN
parameters['wlPass'] = PASSWORD
parameters['version'] = VERSION
parameters['walletIp'] = getUserIP()
parameters['walletUa'] = UA
# wrap to 'p'
request = json.dumps({'p': parameters})
serviceUrl = DIRECTKIT_JSON2 + '/' + serviceName
headers = {
'Content-type': 'application/json;charset=utf-8',
'Accept': 'application/json',
'Cache-Control': 'no-cache',
'Pragma': 'no-cache'
}
response = requests.post(
serviceUrl,
data=request,
headers=headers,
json=None,
verify=SSL_VERIFICATION
)
httpStatus = response.status_code
if httpStatus == 200:
unwrapResponse = json.loads(response.content)['d']
businessErr = unwrapResponse['E']
if businessErr:
#logging.error(businessErr['Code'] + ' - ' + businessErr['Msg'] + ' - Technical info: ' + businessErr['Error'])
raise LWException(businessErr['Code'] + ' - ' + businessErr['Msg'])
return unwrapResponse
else:
raise Exception('HTTP Status = ' + str(httpStatus))