Rev 6452 | Rev 7127 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/python'''It is used to process transactions for which the paymentwas received but the order was not processed.@author: Rajveer'''import optparseimport sysimport datetimefrom elixir import *if __name__ == '__main__' and __package__ is None:import ossys.path.insert(0, os.getcwd())from shop2020.thriftpy.model.v1.order.ttypes import RechargeOrderStatusfrom shop2020.model.v1.order.impl.DataAccessors import get_recharge_orders_for_status, update_recharge_order_status,\update_amount_in_walletfrom shop2020.model.v1.order.impl import DataServicefrom shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrderfrom shop2020.model.v1.order.impl.RechargeService import checkTransactionStatus, getRefundsdef main():parser = optparse.OptionParser()parser.add_option("-H", "--host", dest="hostname",default="localhost",type="string", help="The HOST where the DB server is running",metavar="HOST")parser.add_option("-r", "--refund", dest="refund",action="store_true",help="")parser.add_option("-u", "--unknown", dest="unknown",action="store_true",help="")parser.add_option("-a", "--authorized", dest="authorized",action="store_true",help="")parser.add_option("-t", "--txn-id", dest="txn_id",type="int",help="mark the transaction(recharge order id) TXN_ID as successful",metavar="TXN_ID")(options, args) = parser.parse_args()if len(args) != 0:parser.error("You've supplied extra arguments. Are you sure you want to run this program?")DataService.initialize(db_hostname=options.hostname, echoOn=True)if options.refund:processRefunds()if options.unknown:processUnknownTransactions()if options.authorized:processAuthorizedTransactions(options.txn_id)def processRefunds():todate = datetime.datetime.now()for i in range(15):orderDate = todate + datetime.timedelta(days= -i)refunds = getRefunds(orderDate)for key in refunds.keys():refund = refunds.get(key)refundAmount = refund[0]refundDate = refund[1]order = RechargeOrder.get_by(spiceTID = key)if order.status == RechargeOrderStatus.RECHARGE_FAILED_REFUNDED:print "Refund is already processed."continueif order.status not in (RechargeOrderStatus.RECHARGE_SUCCESSFUL, RechargeOrderStatus.PAYMENT_SUCCESSFUL):print "Recharge/Payment is not successful. There is something wrong."continueif order.totalAmount != refundAmount:print "Refund amount is not same as transaction amount"continueupdate_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_FAILED_REFUNDED, refundDate)def processUnknownTransactions():orders = get_recharge_orders_for_status(RechargeOrderStatus.PAYMENT_SUCCESSFUL)for order in orders:try:if order.creationTimestamp + datetime.timedelta(minutes=10) < datetime.datetime.now():status, description = checkTransactionStatus('', str(order.id))print status, descriptionif status:update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_SUCCESSFUL)else:update_recharge_order_status(order.id, RechargeOrderStatus.RECHARGE_FAILED)except:print "Do Nothing"def processAuthorizedTransactions(txn_id):update_recharge_order_status(txn_id, RechargeOrderStatus.PAYMENT_SUCCESSFUL)if __name__ == '__main__':main()