| 13804 |
amit.gupta |
1 |
'''
|
|
|
2 |
Created on Feb 12, 2015
|
|
|
3 |
|
|
|
4 |
@author: amit
|
|
|
5 |
'''
|
|
|
6 |
from dtr import main
|
|
|
7 |
from dtr.storage import Mongo
|
|
|
8 |
import falcon
|
|
|
9 |
import json
|
|
|
10 |
class StoreOrder():
|
|
|
11 |
def on_post(self, req, resp):
|
|
|
12 |
|
|
|
13 |
try:
|
|
|
14 |
string1 = req.stream.read()
|
|
|
15 |
req_json = json.loads(string1, encoding='utf-8')
|
|
|
16 |
except ValueError:
|
|
|
17 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
18 |
'Malformed JSON',
|
|
|
19 |
'Could not decode the request body. The '
|
|
|
20 |
'JSON was incorrect.')
|
|
|
21 |
|
|
|
22 |
store = main.getStore(int(req_json['sourceId']))
|
|
|
23 |
result = store.parseOrderRawHtml(int(req_json['orderId']), req_json['subTagId'], int(req_json['userId']), req_json['rawHtml'], req_json['orderSuccessUrl'])
|
|
|
24 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
25 |
|
|
|
26 |
def on_get(self, req, resp, userId):
|
|
|
27 |
page = req.get_param_as_int("page")
|
|
|
28 |
window = req.get_param_as_int("window")
|
| 14003 |
amit.gupta |
29 |
string1 = req.get_param("searchMap")
|
| 14004 |
amit.gupta |
30 |
searchMap={}
|
| 14006 |
amit.gupta |
31 |
if string1 is None or string1 == "":
|
| 14007 |
amit.gupta |
32 |
pass
|
|
|
33 |
else:
|
| 14006 |
amit.gupta |
34 |
try:
|
| 14007 |
amit.gupta |
35 |
searchMap = json.loads(string1, encoding='utf-8')
|
| 14006 |
amit.gupta |
36 |
except:
|
|
|
37 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
38 |
'Malformed JSON',
|
|
|
39 |
'Could not decode the request body. The '
|
|
|
40 |
'JSON was incorrect.')
|
| 14003 |
amit.gupta |
41 |
result = Mongo.getMerchantOrdersByUser(int(userId), page, window, searchMap)
|
| 13868 |
amit.gupta |
42 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
43 |
|
|
|
44 |
class Track():
|
| 13939 |
amit.gupta |
45 |
def on_post(self, req, resp, userId):
|
| 13868 |
amit.gupta |
46 |
try:
|
| 14013 |
amit.gupta |
47 |
string1 = req.stream.read()
|
|
|
48 |
print string1
|
|
|
49 |
except ValueError:
|
|
|
50 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
51 |
'Malformed JSON',
|
|
|
52 |
'Could not decode the request body. The '
|
|
|
53 |
'JSON was incorrect.')
|
|
|
54 |
try:
|
| 13927 |
amit.gupta |
55 |
store = main.getStore(req.get_param_as_int("storeId"))
|
|
|
56 |
if req.get_param_as_int("storeId") == 1:
|
| 14013 |
amit.gupta |
57 |
result = store.trackOrdersForUser(int(userId),1,2)
|
| 13927 |
amit.gupta |
58 |
resp.body = json.dumps({'result':result}, encoding='utf-8')
|
|
|
59 |
else:
|
|
|
60 |
resp.body = json.dumps({'result':'NOT_IMPLEMENTED'}, encoding='utf-8')
|
|
|
61 |
except:
|
|
|
62 |
resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
|
| 13868 |
amit.gupta |
63 |
|
| 13939 |
amit.gupta |
64 |
def on_get(self, req, resp, userId):
|
| 13868 |
amit.gupta |
65 |
try:
|
|
|
66 |
storeId = req.get_param_as_int("storeId")
|
| 13939 |
amit.gupta |
67 |
result = main.getStore(storeId).getTrackingUrls(int(userId))
|
| 13887 |
amit.gupta |
68 |
resp.body = json.dumps({'result':result}, encoding='utf-8')
|
| 13868 |
amit.gupta |
69 |
except ValueError:
|
|
|
70 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
71 |
'Malformed JSON',
|
|
|
72 |
'Could not decode the request body. The '
|
|
|
73 |
'JSON was incorrect.')
|
|
|
74 |
|
| 13927 |
amit.gupta |
75 |
class Refunds():
|
| 13990 |
amit.gupta |
76 |
def on_get(self, req, resp, userId):
|
| 13927 |
amit.gupta |
77 |
try:
|
|
|
78 |
page = req.get_param_as_int("page")
|
|
|
79 |
window = req.get_param_as_int("window")
|
| 13990 |
amit.gupta |
80 |
result = Mongo.getRefunds(int(userId),page,window)
|
| 13927 |
amit.gupta |
81 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
82 |
except ValueError:
|
|
|
83 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
84 |
'Malformed JSON',
|
|
|
85 |
'Could not decode the request body. The '
|
|
|
86 |
'JSON was incorrect.')
|
|
|
87 |
|
|
|
88 |
class PendingRefunds():
|
|
|
89 |
def on_get(self, req, resp,userId):
|
|
|
90 |
try:
|
|
|
91 |
result = Mongo.getPendingRefunds(int(userId))
|
|
|
92 |
resp.body = json.dumps(result, encoding='utf-8')
|
|
|
93 |
except ValueError:
|
|
|
94 |
raise falcon.HTTPError(falcon.HTTP_400,
|
|
|
95 |
'Malformed JSON',
|
|
|
96 |
'Could not decode the request body. The '
|
|
|
97 |
'JSON was incorrect.')
|