Subversion Repositories SmartDukaan

Rev

Rev 13927 | Rev 13990 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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")
29
        result = Mongo.getMerchantOrdersByUser(int(userId), page, window)
13868 amit.gupta 30
        resp.body = json.dumps(result, encoding='utf-8')
31
 
32
class Track():
13939 amit.gupta 33
    def on_post(self, req, resp, userId):
13868 amit.gupta 34
        try:
35
            string1 = req.stream.read()
36
            req_json = json.loads(string1, encoding='utf-8')
37
        except ValueError:
38
            raise falcon.HTTPError(falcon.HTTP_400,
39
                'Malformed JSON',
40
                'Could not decode the request body. The '
41
                'JSON was incorrect.')
13927 amit.gupta 42
        try:
43
            store = main.getStore(req.get_param_as_int("storeId"))
44
            if req.get_param_as_int("storeId") == 1:
13939 amit.gupta 45
                result = store.trackOrdersForUser(int(userId),req_json['url'],req_json['html'])
13927 amit.gupta 46
                resp.body = json.dumps({'result':result}, encoding='utf-8')
47
            else:
48
                resp.body = json.dumps({'result':'NOT_IMPLEMENTED'}, encoding='utf-8')
49
        except:
50
            resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
13868 amit.gupta 51
 
13939 amit.gupta 52
    def on_get(self, req, resp, userId):
13868 amit.gupta 53
        try:
54
            storeId = req.get_param_as_int("storeId")
13939 amit.gupta 55
            result = main.getStore(storeId).getTrackingUrls(int(userId))
13887 amit.gupta 56
            resp.body = json.dumps({'result':result}, encoding='utf-8')
13868 amit.gupta 57
        except ValueError:
58
            raise falcon.HTTPError(falcon.HTTP_400,
59
                'Malformed JSON',
60
                'Could not decode the request body. The '
61
                'JSON was incorrect.')
62
 
13927 amit.gupta 63
class Refunds():
64
    def on_get(self, req, resp):
65
        try:
66
            userId = req.get_param_as_int("userId")
67
            page = req.get_param_as_int("page")
68
            window = req.get_param_as_int("window")
69
            result = Mongo.getRefunds(userId,page,window)
70
            resp.body = json.dumps(result, encoding='utf-8')
71
        except ValueError:
72
            raise falcon.HTTPError(falcon.HTTP_400,
73
                'Malformed JSON',
74
                'Could not decode the request body. The '
75
                'JSON was incorrect.')
76
 
77
class PendingRefunds():
78
    def on_get(self, req, resp,userId):
79
        try:
80
            page = req.get_param_as_int("page")
81
            window = req.get_param_as_int("window")
82
            result = Mongo.getPendingRefunds(int(userId))
83
            resp.body = json.dumps(result, encoding='utf-8')
84
        except ValueError:
85
            raise falcon.HTTPError(falcon.HTTP_400,
86
                'Malformed JSON',
87
                'Could not decode the request body. The '
88
                'JSON was incorrect.')