Subversion Repositories SmartDukaan

Rev

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

Rev 14697 Rev 14698
Line 55... Line 55...
55
                    merchantOrderId = soup.find(id="orders-list").div.span.b.text
55
                    merchantOrderId = soup.find(id="orders-list").div.span.b.text
56
                order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
56
                order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
57
                order.orderSuccessUrl = ORDER_REDIRECT_URL % (merchantOrderId)
57
                order.orderSuccessUrl = ORDER_REDIRECT_URL % (merchantOrderId)
58
                order.merchantOrderId = merchantOrderId
58
                order.merchantOrderId = merchantOrderId
59
                order.requireDetail = True
59
                order.requireDetail = True
-
 
60
                order.status = 'html_required'
60
                order.closed = None
61
                order.closed = None
61
                if self._saveToOrder(todict(order)):
62
                if self._saveToOrder(todict(order)):
62
                    resp['result'] = 'ORDER_CREATED'
63
                    resp['result'] = 'ORDER_CREATED'
63
                    resp["url"] = ORDER_REDIRECT_URL % (merchantOrderId)
64
                    resp["url"] = ORDER_REDIRECT_URL % (merchantOrderId)
64
                    resp["htmlRequired"] = True
65
                    resp["htmlRequired"] = True
Line 85... Line 86...
85
                        traceback.print_exc()
86
                        traceback.print_exc()
86
                        self.parseCancelled(merchantOrder, soup)
87
                        self.parseCancelled(merchantOrder, soup)
87
                resp['result'] = 'ORDER_CREATED'
88
                resp['result'] = 'ORDER_CREATED'
88
                return resp    
89
                return resp    
89
            except:
90
            except:
90
                order = self.db.merchant.findOne({"orderId":orderId})
91
                order = self.db.merchantOrder.findOne({"orderId":orderId})
91
                if order is not None:
92
                if order is not None:
92
                    self.db.merchantOrder.update({"orderId":orderId}, {"$set":{"status":"ParseError"}})
93
                    self.db.merchantOrder.update({"orderId":orderId}, {"$set":{"status":"parse_failed"}})
93
                print "Error occurred"
94
                print "Error occurred"
94
                traceback.print_exc()
95
                traceback.print_exc()
95
                resp['result'] = 'ORDER_NOT_CREATED'
96
                resp['result'] = 'ORDER_NOT_CREATED'
96
                return resp    
97
                return resp    
97
                    
98
                    
Line 204... Line 205...
204
                grandAmount += int(float(labelTd.next_sibling.next_sibling.find('span').contents[-1].replace(',','')))
205
                grandAmount += int(float(labelTd.next_sibling.next_sibling.find('span').contents[-1].replace(',','')))
205
        if grandAmount < totalAmount:
206
        if grandAmount < totalAmount:
206
            diff = totalAmount - grandAmount
207
            diff = totalAmount - grandAmount
207
            for subOrder in merchantOrder.subOrders:
208
            for subOrder in merchantOrder.subOrders:
208
                subOrder.amountPaid -= int(diff*(1-subOrder.amountPaid/totalAmount))
209
                subOrder.amountPaid -= int(diff*(1-subOrder.amountPaid/totalAmount))
-
 
210
        merchantOrder.status='success'
209
        self._updateToOrder(todict(merchantOrder))
211
        self._updateToOrder(todict(merchantOrder))
210
 
212
 
211
    def parseNewStlye(self, merchantOrder, soup):
213
    def parseNewStlye(self, merchantOrder, soup):
212
        merchantOrder.orderTrackingUrl = merchantOrder.orderSuccessUrl
214
        merchantOrder.orderTrackingUrl = merchantOrder.orderSuccessUrl
213
        orderDetailsContainer = soup.body.find(id="orderDetails")
215
        orderDetailsContainer = soup.body.find(id="orderDetails")
Line 277... Line 279...
277
                subOrder.cashBackStatus = cashbackStatus
279
                subOrder.cashBackStatus = cashbackStatus
278
                subOrder.cashBackAmount = cashbackAmount
280
                subOrder.cashBackAmount = cashbackAmount
279
                if percentage > 0:
281
                if percentage > 0:
280
                    subOrder.cashBackPercentage = percentage
282
                    subOrder.cashBackPercentage = percentage
281
                subOrders.append(subOrder)
283
                subOrders.append(subOrder)
-
 
284
        merchantOrder.status='success'
282
        self._updateToOrder(todict(merchantOrder))
285
        self._updateToOrder(todict(merchantOrder))
283
        
286
        
284
    def parseCancelled(self, merchantOrder,soup):
287
    def parseCancelled(self, merchantOrder,soup):
285
        fonts = soup.body.findAll("table", recursive=False)[1].findAll("font")
288
        fonts = soup.body.findAll("table", recursive=False)[1].findAll("font")
286
        if fonts[0].text == "Important Message":
289
        if fonts[0].text == "Important Message":
287
            if fonts[1].text=="This order has been cancelled.":
290
            if fonts[1].text=="This order has been cancelled.":
288
                merchantOrder.closed = True
291
                merchantOrder.closed = True
289
                merchantOrder.status = "Cancelled"
292
                merchantOrder.status = "cancelled"
290
                merchantOrder.requireDetail = False
293
                merchantOrder.requireDetail = False
291
                self._updateToOrder(todict(merchantOrder))
294
                self._updateToOrder(todict(merchantOrder))
292
            else:
295
            else:
293
                raise ParseException("parseCancelled", "Found detailed status" + fonts[1].text)
296
                raise ParseException("parseCancelled", "Found detailed status" + fonts[1].text)
294
        else:
297
        else:
295
            orderDetails = soup.body.find(id="orderDetails")
298
            orderDetails = soup.body.find(id="orderDetails")
296
            if orderDetails is not None and orderDetails.h4.text == "This order has been cancelled.":
299
            if orderDetails is not None and orderDetails.h4.text == "This order has been cancelled.":
297
                merchantOrder.closed = True
300
                merchantOrder.closed = True
298
                merchantOrder.status = "Cancelled"
301
                merchantOrder.status = "cancelled"
299
                merchantOrder.requireDetail = False
302
                merchantOrder.requireDetail = False
300
                self._updateToOrder(todict(merchantOrder))
303
                self._updateToOrder(todict(merchantOrder))
301
            else:
304
            else:
302
                raise ParseException("parseCancelled", "Found detailed status" + fonts[1].text)
305
                raise ParseException("parseCancelled", "Found detailed status" + fonts[1].text)
303
 
306