Subversion Repositories SmartDukaan

Rev

Rev 16473 | Rev 16561 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16473 Rev 16489
Line 16... Line 16...
16
from pymongo.mongo_client import MongoClient
16
from pymongo.mongo_client import MongoClient
17
import json
17
import json
18
import os
18
import os
19
import traceback
19
import traceback
20
 
20
 
21
 
-
 
-
 
21
ORDER_DETAIL_API_URL = 'https://paytm.com/shop/orderdetail/%s?actions=1&channel=web&version=2'
-
 
22
ORDER_DETAIL_URL = "https://paytm.com/myorders/%s"
22
class Store(MStore):
23
class Store(MStore):
23
    OrderStatusMap = {
24
    OrderStatusMap = {
24
                      main.Store.ORDER_PLACED : ['in process', 'ready to be shipped', 'order recieved', 'order received', 'pending confirmation', 'waiting for courier pickup'],
25
                      main.Store.ORDER_PLACED : ['in process', 'ready to be shipped', 'order recieved', 'order received', 'pending confirmation', 'waiting for courier pickup'],
25
                      main.Store.ORDER_DELIVERED : ['delivered'],
26
                      main.Store.ORDER_DELIVERED : ['delivered'],
26
                      main.Store.ORDER_SHIPPED : ['in transit', 'shipped'],
27
                      main.Store.ORDER_SHIPPED : ['in transit', 'shipped'],
27
                      main.Store.ORDER_CANCELLED : ['failed', 'payment failed', 'cancelled']
28
                      main.Store.ORDER_CANCELLED : ['failed', 'payment failed', 'cancelled']                      
28
                      
-
 
29
                      }
29
                      }
-
 
30
    
30
    def __init__(self,store_id):
31
    def __init__(self,store_id):
31
        client = MongoClient('mongodb://localhost:27017/')
32
        client = MongoClient('mongodb://localhost:27017/')
32
        self.db = client.dtr
33
        self.db = client.dtr
33
        super(Store, self).__init__(store_id)
34
        super(Store, self).__init__(store_id)
34
 
35
 
Line 52... Line 53...
52
        #for missingOrder in missingOrders:
53
        #for missingOrder in missingOrders:
53
        #    missingOrderUrls.append(ORDER_REDIRECT_URL%(missingOrder['merchantOrderId']))
54
        #    missingOrderUrls.append(ORDER_REDIRECT_URL%(missingOrder['merchantOrderId']))
54
        orders = self._getActiveOrders({'userId':userId, "subOrders.trackingUrl":{"$exists":False} }, {"merchantOrderId":1})
55
        orders = self._getActiveOrders({'userId':userId, "subOrders.trackingUrl":{"$exists":False} }, {"merchantOrderId":1})
55
        for order in orders:
56
        for order in orders:
56
            print order
57
            print order
57
            missingOrderUrls.append({"url":"https://paytm.com/shop/orderdetail/%s?actions=1&channel=web&version=2"%(order.get("merchantOrderId")), "referer":"https://paytm.com/myorders/%s"%order.get("merchantOrderId")}  )
58
            missingOrderUrls.append({"url":ORDER_DETAIL_API_URL%(order.get("merchantOrderId")), "referer":ORDER_DETAIL_URL%order.get("merchantOrderId")}  )
58
        return missingOrderUrls
59
        return missingOrderUrls
59
 
60
 
60
    def trackOrdersForUser(self, userId, url, rawHtml):
61
    def trackOrdersForUser(self, userId, url, rawHtml):
61
        merchantOrderId = find_between(url, "https://paytm.com/shop/orderdetail/","?actions=1&channel=web&version=2")
62
        merchantOrderId = find_between(url, "https://paytm.com/shop/orderdetail/","?actions=1&channel=web&version=2")
62
        directory = "/PaytmTrack/User" + str(userId)
63
        directory = "/PaytmTrack/User" + str(userId)
Line 127... Line 128...
127
                order.discountApplied = ordermap.get("discount_amount")
128
                order.discountApplied = ordermap.get("discount_amount")
128
                order.paidAmount = ordermap.get("grandtotal")
129
                order.paidAmount = ordermap.get("grandtotal")
129
                order.placedOn = datetime.strftime(getISTDate(ordermap.get("created_at")),"%d-%m-%Y %H:%M:%S") 
130
                order.placedOn = datetime.strftime(getISTDate(ordermap.get("created_at")),"%d-%m-%Y %H:%M:%S") 
130
                order.requireDetail = False
131
                order.requireDetail = False
131
                order.status = 'success'
132
                order.status = 'success'
-
 
133
                order.orderTrackingUrl = ORDER_DETAIL_URL%(order.merchantOrderId)
132
                order.totalAmount = ordermap.get("subtotal")
134
                order.totalAmount = ordermap.get("subtotal")
133
                subOrders = []
135
                subOrders = []
134
                order.subOrders = subOrders
136
                order.subOrders = subOrders
135
                coupon_code = None
137
                coupon_code = None
136
                total_cashback = 0
138
                total_cashback = 0
Line 143... Line 145...
143
                        for s in item.get("promo_text").split(): 
145
                        for s in item.get("promo_text").split(): 
144
                            if s.isdigit():
146
                            if s.isdigit():
145
                                paytmcashback = int(s)
147
                                paytmcashback = int(s)
146
                                total_cashback += paytmcashback
148
                                total_cashback += paytmcashback
147
                                break
149
                                break
148
                    amountPaid = item.get("subtotal") - paytmcashback 
150
                    amountPaid = item.get("subtotal") 
149
                    detailedStatus = item.get("status_text")
151
                    detailedStatus = item.get("status_text")
150
                    status = self._getStatusFromDetailedStatus(detailedStatus)
152
                    status = self._getStatusFromDetailedStatus(detailedStatus)
151
                    if status == None:
153
                    if status == None:
152
                        status = MStore.ORDER_PLACED
154
                        status = MStore.ORDER_PLACED
153
                    subOrder = SubOrder(item.get("title"), shareUrl, order.placedOn, amountPaid, status, item.get("quantity"))
155
                    subOrder = SubOrder(item.get("title"), shareUrl, order.placedOn, amountPaid, status, item.get("quantity"))
-
 
156
                    subOrder.offerDiscount =  paytmcashback
154
                    subOrder.imgUrl = product.get("thumbnail")
157
                    subOrder.imgUrl = product.get("thumbnail")
155
                    subOrder.detailedStatus = detailedStatus
158
                    subOrder.detailedStatus = detailedStatus
156
                    subOrder.productCode = product.get("url").split("?")[0].split("/")[-1]
159
                    subOrder.productCode = product.get("url").split("?")[0].split("/")[-1]
157
                    subOrder.merchantSubOrderId = str(item.get("id"))
160
                    subOrder.merchantSubOrderId = str(item.get("id"))
158
                    if status == MStore.ORDER_PLACED: 
161
                    if status == MStore.ORDER_PLACED: