Subversion Repositories SmartDukaan

Rev

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

Rev 6147 Rev 6219
Line 5... Line 5...
5
 
5
 
6
@author: Rajveer
6
@author: Rajveer
7
'''
7
'''
8
import optparse
8
import optparse
9
import sys
9
import sys
-
 
10
import datetime
-
 
11
 
10
 
12
 
11
 
13
 
12
 
14
 
13
if __name__ == '__main__' and __package__ is None:
15
if __name__ == '__main__' and __package__ is None:
14
    import os
16
    import os
15
    sys.path.insert(0, os.getcwd())
17
    sys.path.insert(0, os.getcwd())
16
 
18
 
17
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
19
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
18
from shop2020.model.v1.order.impl import DataAccessors, DataService
20
from shop2020.model.v1.order.impl import DataAccessors, DataService
-
 
21
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus
19
 
22
 
20
 
23
 
21
def main():
24
def main():
22
    parser = optparse.OptionParser()
25
    parser = optparse.OptionParser()
23
    parser.add_option("-o", "--order_id", dest="order_id",
-
 
24
                   type="int",
-
 
25
                   help="mark the recharge order id ORDER_ID as successful",
-
 
26
                   metavar="ORDER_ID")
-
 
27
    parser.add_option("-H", "--host", dest="hostname",
26
    parser.add_option("-H", "--host", dest="hostname",
28
                      default="localhost",
27
                      default="localhost",
29
                      type="string", help="The HOST where the DB server is running",
28
                      type="string", help="The HOST where the DB server is running",
30
                      metavar="HOST")
29
                      metavar="HOST")
31
    (options, args) = parser.parse_args()
30
    (options, args) = parser.parse_args()
32
    if len(args) != 0:
31
    if len(args) != 0:
33
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
32
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
34
    if options.order_id == None:
-
 
35
        parser.error("No Transaction id supplied")
-
 
36
        
-
 
37
        
33
        
38
    DataService.initialize(db_hostname=options.hostname, echoOn=True)
34
    DataService.initialize(db_hostname=options.hostname, echoOn=True)
-
 
35
    orders = DataAccessors.get_recharge_orders_for_status(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
-
 
36
    for order in orders:
-
 
37
        if order.creationTimestamp + datetime.timedelta(minutes=10) < datetime.datetime.now():
-
 
38
            status, description = checkTransactionStatus('', order.idPrefix + str(id))
-
 
39
            if status:
39
    DataAccessors.update_recharge_order_status(options.order_id, RechargeOrderStatus.PAYMENT_SUCCESSFUL)
40
                DataAccessors.update_recharge_order_status(options.order_id, RechargeOrderStatus.RECHARGE_SUCCESSFUL)
40
 
-
 
-
 
41
            else:
-
 
42
                DataAccessors.update_recharge_order_status(options.order_id, RechargeOrderStatus.RECHARGE_FAILED)
41
if __name__ == '__main__':
43
if __name__ == '__main__':
42
    main()
44
    main()
43
45