| Line 41... |
Line 41... |
| 41 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
41 |
if ORDER_SUCCESS_URL in orderSuccessUrl or THANKYOU_URL in orderSuccessUrl:
|
| 42 |
try:
|
42 |
try:
|
| 43 |
soup = BeautifulSoup(rawHtml)
|
43 |
soup = BeautifulSoup(rawHtml)
|
| 44 |
orderUrl = soup.find('div', {"id":"thank-you-box-wrapper"}).div.findAll('div', recursive=False)[1].a['href']
|
44 |
orderUrl = soup.find('div', {"id":"thank-you-box-wrapper"}).div.findAll('div', recursive=False)[1].a['href']
|
| 45 |
merchantOrderId = re.findall(r'.*&oid=(.*)&?.*?', orderUrl)[0]
|
45 |
merchantOrderId = re.findall(r'.*&oid=(.*)&?.*?', orderUrl)[0]
|
| 46 |
resp["result"] = 'HTML_REQUIRED'
|
- |
|
| 47 |
order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
|
46 |
order = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl, False)
|
| 48 |
order.orderSuccessUrl = ORDER_REDIRECT_URL % (merchantOrderId)
|
47 |
order.orderSuccessUrl = ORDER_REDIRECT_URL % (merchantOrderId)
|
| 49 |
order.merchantOrderId = merchantOrderId
|
48 |
order.merchantOrderId = merchantOrderId
|
| 50 |
order.requireDetail = True
|
49 |
order.requireDetail = True
|
| 51 |
order.closed = None
|
50 |
order.closed = None
|
| 52 |
self._saveToOrder(todict(order))
|
51 |
if self._saveToOrder(todict(order)):
|
| - |
|
52 |
resp['result'] = 'ORDER_CREATED'
|
| 53 |
resp["url"] = ORDER_REDIRECT_URL % (merchantOrderId)
|
53 |
resp["url"] = ORDER_REDIRECT_URL % (merchantOrderId)
|
| - |
|
54 |
resp["htmlRequired"] = True
|
| - |
|
55 |
resp['orderId'] = orderId
|
| - |
|
56 |
else:
|
| - |
|
57 |
resp['result'] = 'ORDER_ALREADY_CREATED_IGNORED'
|
| - |
|
58 |
|
| 54 |
return resp
|
59 |
return resp
|
| 55 |
except:
|
60 |
except:
|
| 56 |
resp["result"] = 'IGNORED'
|
61 |
resp["result"] = 'ORDER_NOT_CREATED'
|
| 57 |
return resp
|
62 |
return resp
|
| 58 |
|
63 |
|
| 59 |
else:
|
64 |
else:
|
| 60 |
try:
|
65 |
try:
|
| 61 |
merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl)
|
66 |
merchantOrder = Order(orderId, userId, subTagId, self.store_id, orderSuccessUrl)
|
| Line 131... |
Line 136... |
| 131 |
grandAmount += int(float(labelTd.next_sibling.next_sibling.find('span').contents[-1].strip(',','')))
|
136 |
grandAmount += int(float(labelTd.next_sibling.next_sibling.find('span').contents[-1].strip(',','')))
|
| 132 |
if grandAmount < totalAmount:
|
137 |
if grandAmount < totalAmount:
|
| 133 |
diff = totalAmount - grandAmount
|
138 |
diff = totalAmount - grandAmount
|
| 134 |
for subOrder in merchantOrder.subOrders:
|
139 |
for subOrder in merchantOrder.subOrders:
|
| 135 |
subOrder.amountPaid -= int(diff*(1-subOrder.amountPaid/totalAmount))
|
140 |
subOrder.amountPaid -= int(diff*(1-subOrder.amountPaid/totalAmount))
|
| 136 |
|
- |
|
| 137 |
if insert:
|
- |
|
| 138 |
self._saveToOrder(todict(merchantOrder))
|
- |
|
| 139 |
else:
|
141 |
else:
|
| 140 |
self._updateToOrder(todict(merchantOrder))
|
142 |
self._updateToOrder(todict(merchantOrder))
|
| 141 |
resp['result'] = 'ORDER_CREATED'
|
143 |
resp['result'] = 'ORDER_CREATED'
|
| 142 |
return resp
|
144 |
return resp
|
| 143 |
except:
|
145 |
except:
|
| 144 |
print "Error occurred"
|
146 |
print "Error occurred"
|
| 145 |
traceback.print_exc()
|
147 |
traceback.print_exc()
|
| 146 |
resp['result'] = 'PARSE_ERROR'
|
148 |
resp['result'] = 'ORDER_NOT_CREATED'
|
| 147 |
return resp
|
149 |
return resp
|
| 148 |
|
150 |
|
| 149 |
#This should be exposed from api for specific sources
|
151 |
#This should be exposed from api for specific sources
|
| 150 |
def scrapeStoreOrders(self):
|
152 |
def scrapeStoreOrders(self):
|
| 151 |
pass
|
153 |
pass
|
| Line 253... |
Line 255... |
| 253 |
bulk.execute()
|
255 |
bulk.execute()
|
| 254 |
return 'PARSED_SUCCESS'
|
256 |
return 'PARSED_SUCCESS'
|
| 255 |
else:
|
257 |
else:
|
| 256 |
merchantOrderId = re.findall(r'https://www.amazon.in/gp/css/summary/edit.html\?orderID=(.*)?', url, re.IGNORECASE)[0]
|
258 |
merchantOrderId = re.findall(r'https://www.amazon.in/gp/css/summary/edit.html\?orderID=(.*)?', url, re.IGNORECASE)[0]
|
| 257 |
merchantOrder = self.db.merchantOrder.find_one({"merchantOrderId":merchantOrderId})
|
259 |
merchantOrder = self.db.merchantOrder.find_one({"merchantOrderId":merchantOrderId})
|
| 258 |
self.parseOrderRawHtml(merchantOrder['orderId'], merchantOrder['subTagId'], merchantOrder['userId'], rawHtml, url, False)
|
260 |
self.parseOrderRawHtml(merchantOrder['orderId'], merchantOrder['subTagId'], merchantOrder['userId'], rawHtml, url, False)['result']
|
| 259 |
return 'PARSED_SUCCESS'
|
261 |
return 'PARSED_SUCCESS'
|
| 260 |
pass
|
262 |
pass
|
| 261 |
return 'PARSED_SUCCESS_NO_ORDERS'
|
263 |
return 'PARSED_SUCCESS_NO_ORDERS'
|
| 262 |
except:
|
264 |
except:
|
| 263 |
traceback.print_exc()
|
265 |
traceback.print_exc()
|