| Line 6... |
Line 6... |
| 6 |
@author: Rajveer
|
6 |
@author: Rajveer
|
| 7 |
'''
|
7 |
'''
|
| 8 |
import optparse
|
8 |
import optparse
|
| 9 |
import sys
|
9 |
import sys
|
| 10 |
import datetime
|
10 |
import datetime
|
| - |
|
11 |
from elixir import *
|
| 11 |
|
12 |
|
| 12 |
|
13 |
|
| 13 |
|
14 |
|
| 14 |
|
15 |
|
| 15 |
if __name__ == '__main__' and __package__ is None:
|
16 |
if __name__ == '__main__' and __package__ is None:
|
| 16 |
import os
|
17 |
import os
|
| 17 |
sys.path.insert(0, os.getcwd())
|
18 |
sys.path.insert(0, os.getcwd())
|
| 18 |
|
19 |
|
| 19 |
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
|
20 |
from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatus
|
| - |
|
21 |
from shop2020.model.v1.order.impl.DataAccessors import get_recharge_orders_for_status, update_recharge_order_status
|
| 20 |
from shop2020.model.v1.order.impl import DataAccessors, DataService
|
22 |
from shop2020.model.v1.order.impl import DataService
|
| - |
|
23 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
| 21 |
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus
|
24 |
from shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefunds
|
| 22 |
|
25 |
|
| 23 |
|
26 |
|
| 24 |
def main():
|
27 |
def main():
|
| 25 |
parser = optparse.OptionParser()
|
28 |
parser = optparse.OptionParser()
|
| 26 |
parser.add_option("-H", "--host", dest="hostname",
|
29 |
parser.add_option("-H", "--host", dest="hostname",
|
| 27 |
default="localhost",
|
30 |
default="localhost",
|
| 28 |
type="string", help="The HOST where the DB server is running",
|
31 |
type="string", help="The HOST where the DB server is running",
|
| 29 |
metavar="HOST")
|
32 |
metavar="HOST")
|
| - |
|
33 |
parser.add_option("-r", "--refund", dest="refund",
|
| - |
|
34 |
action="store_true",
|
| - |
|
35 |
help="")
|
| - |
|
36 |
parser.add_option("-u", "--unknown", dest="unknown",
|
| - |
|
37 |
action="store_true",
|
| - |
|
38 |
help="")
|
| - |
|
39 |
|
| 30 |
(options, args) = parser.parse_args()
|
40 |
(options, args) = parser.parse_args()
|
| 31 |
if len(args) != 0:
|
41 |
if len(args) != 0:
|
| 32 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
42 |
parser.error("You've supplied extra arguments. Are you sure you want to run this program?")
|
| - |
|
43 |
|
| - |
|
44 |
if options.refund:
|
| 33 |
|
45 |
processRefunds()
|
| - |
|
46 |
if options.unknown:
|
| - |
|
47 |
processUnknownTransactions()
|
| - |
|
48 |
|
| - |
|
49 |
def processRefunds():
|
| - |
|
50 |
DataService.initialize(db_hostname=options.hostname, echoOn=True)
|
| - |
|
51 |
todate = datetime.datetime.now()
|
| - |
|
52 |
for i in range(15):
|
| - |
|
53 |
orderDate = todate + datetime.timedelta(days= -i)
|
| - |
|
54 |
refunds = getRefunds(orderDate)
|
| - |
|
55 |
for key in refunds.keys():
|
| - |
|
56 |
refund = refunds.get(key)
|
| - |
|
57 |
refundAmount = refund[0]
|
| - |
|
58 |
refundDate = refund[1]
|
| - |
|
59 |
order = RechargeOrder.get_by(spiceTID = key)
|
| - |
|
60 |
if order.status == RechargeOrderStatus.RECHARGE_FAILED_REFUNDED:
|
| - |
|
61 |
print "Refund is already processed."
|
| - |
|
62 |
continue
|
| - |
|
63 |
if order.status != RechargeOrderStatus.RECHARGE_SUCCESSFUL:
|
| - |
|
64 |
print "Recharge is not successful. There is something wrong."
|
| - |
|
65 |
continue
|
| - |
|
66 |
if order.totalAmount != refundAmount:
|
| - |
|
67 |
print "Refund amount is not same as transaction amount"
|
| - |
|
68 |
continue
|
| - |
|
69 |
order.status = RechargeOrderStatus.RECHARGE_FAILED_REFUNDED
|
| - |
|
70 |
order.responseTimestamp = refundDate
|
| - |
|
71 |
session.commit()
|
| - |
|
72 |
|
| - |
|
73 |
def processUnknownTransactions():
|
| 34 |
DataService.initialize(db_hostname=options.hostname, echoOn=True)
|
74 |
DataService.initialize(db_hostname=options.hostname, echoOn=True)
|
| 35 |
orders = DataAccessors.get_recharge_orders_for_status(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
|
75 |
orders = get_recharge_orders_for_status(RechargeOrderStatus.PAYMENT_SUCCESSFUL)
|
| 36 |
for order in orders:
|
76 |
for order in orders:
|
| 37 |
if order.creationTimestamp + datetime.timedelta(minutes=10) < datetime.datetime.now():
|
77 |
if order.creationTimestamp + datetime.timedelta(minutes=10) < datetime.datetime.now():
|
| 38 |
status, description = checkTransactionStatus('', str(order.id))
|
78 |
status, description = checkTransactionStatus('', str(order.id))
|
| 39 |
print status, description
|
79 |
print status, description
|
| 40 |
if status:
|
80 |
if status:
|
| 41 |
DataAccessors.update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_SUCCESSFUL)
|
81 |
update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_SUCCESSFUL)
|
| 42 |
else:
|
82 |
else:
|
| 43 |
DataAccessors.update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_FAILED)
|
83 |
update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_FAILED)
|
| - |
|
84 |
|
| 44 |
if __name__ == '__main__':
|
85 |
if __name__ == '__main__':
|
| 45 |
main()
|
86 |
main()
|
| 46 |
|
87 |
|