| Line 32... |
Line 32... |
| 32 |
from shop2020.thriftpy.model.v1.catalog.ttypes import ItemType
|
32 |
from shop2020.thriftpy.model.v1.catalog.ttypes import ItemType
|
| 33 |
from shop2020.thriftpy.model.v1.inventory.ttypes import BillingType, \
|
33 |
from shop2020.thriftpy.model.v1.inventory.ttypes import BillingType, \
|
| 34 |
InventoryServiceException, WarehouseType, InventoryType
|
34 |
InventoryServiceException, WarehouseType, InventoryType
|
| 35 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
35 |
from shop2020.thriftpy.model.v1.order.ttypes import TransactionServiceException, \
|
| 36 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
36 |
TransactionStatus, OrderStatus, DelayReason, ExtraTransactionProcessingType, \
|
| 37 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType
|
37 |
HotspotAction, TimeoutSummary, OrderStatusGroups, OrderType,\
|
| - |
|
38 |
RechargeOrderStatus
|
| 38 |
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
|
39 |
from shop2020.thriftpy.model.v1.user.ttypes import VoucherType
|
| 39 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
40 |
from shop2020.thriftpy.payments.ttypes import PaymentException
|
| 40 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
41 |
from shop2020.thriftpy.warehouse.ttypes import ScanType, \
|
| 41 |
WarehouseServiceException
|
42 |
WarehouseServiceException
|
| 42 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
43 |
from shop2020.utils.EmailAttachmentSender import mail, get_attachment_part
|
| Line 53... |
Line 54... |
| 53 |
import sys
|
54 |
import sys
|
| 54 |
import time
|
55 |
import time
|
| 55 |
import traceback
|
56 |
import traceback
|
| 56 |
import urllib
|
57 |
import urllib
|
| 57 |
from shop2020.config.client.ConfigClient import ConfigClient
|
58 |
from shop2020.config.client.ConfigClient import ConfigClient
|
| - |
|
59 |
from shop2020.model.v1.order.impl.model.RechargeOrder import RechargeOrder
|
| - |
|
60 |
from shop2020.model.v1.order.impl.model.UserWallet import UserWallet
|
| - |
|
61 |
from shop2020.model.v1.order.impl.model.UserWalletHistory import UserWalletHistory
|
| 58 |
|
62 |
|
| 59 |
logging.basicConfig(level=logging.DEBUG)
|
63 |
logging.basicConfig(level=logging.DEBUG)
|
| 60 |
|
64 |
|
| 61 |
sourceId = int(ConfigClient().get_property("sourceid"))
|
65 |
sourceId = int(ConfigClient().get_property("sourceid"))
|
| 62 |
mail_user = 'cnc.center@shop2020.in'
|
66 |
mail_user = 'cnc.center@shop2020.in'
|
| Line 3351... |
Line 3355... |
| 3351 |
quantity -= lineitem.quantity
|
3355 |
quantity -= lineitem.quantity
|
| 3352 |
session.commit()
|
3356 |
session.commit()
|
| 3353 |
if not quantity:
|
3357 |
if not quantity:
|
| 3354 |
break
|
3358 |
break
|
| 3355 |
|
3359 |
|
| - |
|
3360 |
def get_recharge_order(rechargeOrderId):
|
| - |
|
3361 |
return RechargeOrder.get_by(id = rechargeOrderId).to_thrift_object()
|
| - |
|
3362 |
|
| - |
|
3363 |
def get_recharge_orders(userId):
|
| - |
|
3364 |
return RechargeOrder.query.filter_by(userId = userId).all()
|
| - |
|
3365 |
|
| - |
|
3366 |
def update_recharge_order_status(rechargeOrderId, rechargeOrderStatus):
|
| - |
|
3367 |
recharge_order = get_recharge_order(rechargeOrderId)
|
| - |
|
3368 |
if rechargeOrderStatus == RechargeOrderStatus.PAYMENT_FAILED:
|
| - |
|
3369 |
recharge_order.status = RechargeOrderStatus.PAYMENT_FAILED
|
| - |
|
3370 |
session.commit()
|
| - |
|
3371 |
return True
|
| - |
|
3372 |
|
| - |
|
3373 |
if rechargeOrderStatus == RechargeOrderStatus.PAYMENT_SUCCESSFUL:
|
| - |
|
3374 |
if recharge_order.walletAmount > 0:
|
| - |
|
3375 |
wallet = get_user_wallet(recharge_order.userId)
|
| - |
|
3376 |
if wallet and wallet.amount >= recharge_order.walletAmount:
|
| - |
|
3377 |
update_amount_in_wallet(recharge_order.userId, -recharge_order.walletAmount, recharge_order.id)
|
| - |
|
3378 |
else:
|
| - |
|
3379 |
update_amount_in_wallet(recharge_order.userId, recharge_order.totalAmount - recharge_order.walletAmount, recharge_order.id)
|
| - |
|
3380 |
recharge_order.status = RechargeOrderStatus.PAYMENT_SUCCESSFUL
|
| - |
|
3381 |
session.commit()
|
| - |
|
3382 |
raise TransactionServiceException(103, 'Wallet amount has already been used')
|
| - |
|
3383 |
|
| - |
|
3384 |
|
| - |
|
3385 |
if activate_recharge_txn(rechargeOrderId):
|
| - |
|
3386 |
rechargeOrderStatus = RechargeOrderStatus.RECHARGE_SUCCESSFUL
|
| - |
|
3387 |
session.commit()
|
| - |
|
3388 |
return True
|
| - |
|
3389 |
else:
|
| - |
|
3390 |
rechargeOrderStatus = RechargeOrderStatus.RECHARGE_FAILED
|
| - |
|
3391 |
update_amount_in_wallet(recharge_order.userId, recharge_order.walletAmount, recharge_order.id)
|
| - |
|
3392 |
update_amount_in_wallet(recharge_order.userId, recharge_order.totalAmount - recharge_order.walletAmount, recharge_order.id)
|
| - |
|
3393 |
session.commit()
|
| - |
|
3394 |
return False
|
| - |
|
3395 |
|
| - |
|
3396 |
def activate_recharge_txn(rechargeOrderId):
|
| - |
|
3397 |
return False
|
| - |
|
3398 |
|
| - |
|
3399 |
def get_user_wallet(userId):
|
| - |
|
3400 |
wallet = UserWallet.get_by(userId = userId)
|
| - |
|
3401 |
if not wallet:
|
| - |
|
3402 |
wallet = UserWallet()
|
| - |
|
3403 |
wallet.amount = 0
|
| - |
|
3404 |
wallet.userId = userId
|
| - |
|
3405 |
return wallet
|
| - |
|
3406 |
|
| - |
|
3407 |
def get_user_wallet_history(userId):
|
| - |
|
3408 |
wallet = get_user_wallet(userId)
|
| - |
|
3409 |
if wallet.id:
|
| - |
|
3410 |
return UserWalletHistory.query.filter_by(wallet = wallet).all()
|
| - |
|
3411 |
else:
|
| - |
|
3412 |
return []
|
| - |
|
3413 |
|
| - |
|
3414 |
|
| - |
|
3415 |
def update_amount_in_wallet(userId, amount, orderId):
|
| - |
|
3416 |
if amount == 0:
|
| - |
|
3417 |
return
|
| - |
|
3418 |
wallet = get_user_wallet(userId)
|
| - |
|
3419 |
wallet.amount = wallet.amount + amount
|
| - |
|
3420 |
|
| - |
|
3421 |
history = UserWalletHistory()
|
| - |
|
3422 |
history.amount = amount
|
| - |
|
3423 |
history.orderId = orderId
|
| - |
|
3424 |
history.wallet = wallet
|
| - |
|
3425 |
history.timestamp = datetime.datetime.now()
|
| - |
|
3426 |
session.commit()
|
| - |
|
3427 |
|
| - |
|
3428 |
|
| 3356 |
def close_session():
|
3429 |
def close_session():
|
| 3357 |
if session.is_active:
|
3430 |
if session.is_active:
|
| 3358 |
print "session is active. closing it."
|
3431 |
print "session is active. closing it."
|
| 3359 |
session.close()
|
3432 |
session.close()
|
| 3360 |
|
3433 |
|