| 2133 |
chandransh |
1 |
#!/usr/bin/python
|
|
|
2 |
|
|
|
3 |
import optparse
|
|
|
4 |
import sys
|
|
|
5 |
|
| 2185 |
rajveer |
6 |
from thrift.Thrift import TException
|
|
|
7 |
from shop2020.thriftpy.model.v1.user.ttypes import ShoppingCartException,\
|
|
|
8 |
PromotionException
|
|
|
9 |
from shop2020.clients.UserClient import UserClient
|
|
|
10 |
from shop2020.clients.PromotionClient import PromotionClient
|
|
|
11 |
|
| 2133 |
chandransh |
12 |
if __name__ == '__main__' and __package__ is None:
|
|
|
13 |
import os
|
|
|
14 |
sys.path.insert(0, os.getcwd())
|
|
|
15 |
|
|
|
16 |
from shop2020.model.v1.order.impl import DataAccessors, DataService
|
|
|
17 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionStatus
|
|
|
18 |
|
| 2185 |
rajveer |
19 |
def reset_cart(transaction, userServiceClient):
|
|
|
20 |
items = {}
|
|
|
21 |
for order in transaction.orders:
|
|
|
22 |
for line_item in order.lineitems:
|
|
|
23 |
item_id = line_item.item_id
|
|
|
24 |
quantity = items[item_id]
|
|
|
25 |
if quantity is None:
|
|
|
26 |
quantity = line_item.quantity
|
|
|
27 |
else:
|
|
|
28 |
quantity = quantity + line_item.quantity
|
|
|
29 |
items[item_id] = quantity
|
|
|
30 |
|
|
|
31 |
print items
|
|
|
32 |
|
|
|
33 |
try:
|
|
|
34 |
userServiceClient.getClient().resetCart(transaction.shopping_cart_id, items);
|
|
|
35 |
except ShoppingCartException:
|
|
|
36 |
print "Error while resetting the cart in the cart database"
|
|
|
37 |
print sys.exc_info()
|
|
|
38 |
except TException:
|
|
|
39 |
print "Error while updating information in payment database."
|
|
|
40 |
print sys.exc_info()
|
|
|
41 |
except:
|
|
|
42 |
print "Unexpected exception"
|
|
|
43 |
print sys.exc_info()
|
|
|
44 |
|
|
|
45 |
def track_coupon_usage(transaction, userServiceClient):
|
|
|
46 |
try:
|
|
|
47 |
cart = userServiceClient.getClient().getCart(transaction.shopping_cart_id)
|
|
|
48 |
coupon_code = cart.coupon_code
|
|
|
49 |
|
|
|
50 |
if coupon_code is not None and coupon_code != '':
|
|
|
51 |
PromotionClient().get_client().trackCouponUsage(coupon_code, transaction.id, transaction.customer_id);
|
|
|
52 |
except ShoppingCartException:
|
|
|
53 |
print "Error occurred in reading CardId for transaction"
|
|
|
54 |
print sys.exc_info()
|
|
|
55 |
except PromotionException:
|
|
|
56 |
print "Promotion Exception: "
|
|
|
57 |
print sys.exc_info()
|
|
|
58 |
except TException:
|
|
|
59 |
print "Transport from Promotion Service failed:"
|
|
|
60 |
print sys.exc_info()
|
|
|
61 |
except Exception:
|
|
|
62 |
print "Unexpected exception:"
|
|
|
63 |
print sys.exc_info()
|
|
|
64 |
|
| 2133 |
chandransh |
65 |
def main():
|
|
|
66 |
parser = optparse.OptionParser()
|
|
|
67 |
parser.add_option("-t", "--txn-id", dest="txn_id",
|
|
|
68 |
type="int",
|
|
|
69 |
help="mark the transaction TXN_ID and all its orders as successful",
|
|
|
70 |
metavar="TXN_ID")
|
|
|
71 |
(options, args) = parser.parse_args()
|
|
|
72 |
if len(args) != 0:
|
|
|
73 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
|
|
74 |
if options.txn_id == None:
|
|
|
75 |
parser.error("No Transaction id supplied")
|
|
|
76 |
DataService.initialize(echoOn=True)
|
| 2185 |
rajveer |
77 |
transaction = DataAccessors.get_transaction(options.txn_id)
|
| 2133 |
chandransh |
78 |
DataAccessors.change_transaction_status(options.txn_id, TransactionStatus.IN_PROCESS, "Payment received for the order")
|
| 2185 |
rajveer |
79 |
DataAccessors.enqueue_transaction_info_email(options.txn_id)
|
|
|
80 |
|
|
|
81 |
user_service_client = UserClient()
|
|
|
82 |
reset_cart(transaction, user_service_client)
|
|
|
83 |
track_coupon_usage(transaction, user_service_client)
|
| 2133 |
chandransh |
84 |
|
|
|
85 |
if __name__ == '__main__':
|
|
|
86 |
main()
|