Subversion Repositories SmartDukaan

Rev

Rev 6219 | Rev 6235 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6147 rajveer 1
#!/usr/bin/python
2
'''
3
It is used to process transactions for which the payment 
4
was received but the order was not processed.
5
 
6
@author: Rajveer
7
'''
8
import optparse
9
import sys
6219 rajveer 10
import datetime
6147 rajveer 11
 
12
 
13
 
6219 rajveer 14
 
6147 rajveer 15
if __name__ == '__main__' and __package__ is None:
16
    import os
17
    sys.path.insert(0, os.getcwd())
18
 
19
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
20
from shop2020.model.v1.order.impl import DataAccessors, DataService
6219 rajveer 21
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus
6147 rajveer 22
 
23
 
24
def main():
25
    parser = optparse.OptionParser()
26
    parser.add_option("-H", "--host", dest="hostname",
27
                      default="localhost",
28
                      type="string", help="The HOST where the DB server is running",
29
                      metavar="HOST")
30
    (options, args) = parser.parse_args()
31
    if len(args) != 0:
32
        parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
33
 
34
    DataService.initialize(db_hostname=options.hostname, echoOn=True)
6219 rajveer 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():
6224 rajveer 38
            status, description = checkTransactionStatus('', str(order.id))
39
            print status, description
6219 rajveer 40
            if status:
6224 rajveer 41
                DataAccessors.update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_SUCCESSFUL)
6219 rajveer 42
            else:
6224 rajveer 43
                DataAccessors.update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_FAILED)
6147 rajveer 44
if __name__ == '__main__':
45
    main()