| Line 471... |
Line 471... |
| 471 |
|
471 |
|
| 472 |
return transaction.status
|
472 |
return transaction.status
|
| 473 |
|
473 |
|
| 474 |
def change_transaction_status(transaction_id, new_status, description, pickUp, orderType, source):
|
474 |
def change_transaction_status(transaction_id, new_status, description, pickUp, orderType, source):
|
| 475 |
transaction = get_transaction(transaction_id)
|
475 |
transaction = get_transaction(transaction_id)
|
| 476 |
transaction.status = new_status
|
- |
|
| 477 |
transaction.status_message = description
|
- |
|
| 478 |
expectedDelayMap = {}
|
- |
|
| 479 |
billingWarehouseIdMap = {}
|
- |
|
| 480 |
billingWarehouseTxnMap = {}
|
- |
|
| 481 |
|
476 |
|
| 482 |
if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
|
477 |
if new_status in (TransactionStatus.AUTHORIZED, TransactionStatus.FLAGGED, TransactionStatus.COD_IN_PROCESS):
|
| 483 |
wallet_amount_used = 0.0
|
478 |
wallet_amount_used = 0.0
|
| 484 |
for order in transaction.orders:
|
479 |
for order in transaction.orders:
|
| 485 |
wallet_amount_used = wallet_amount_used + order.wallet_amount
|
480 |
wallet_amount_used = wallet_amount_used + order.wallet_amount
|
| 486 |
if wallet_amount_used > 0:
|
481 |
if wallet_amount_used > 0:
|
| 487 |
user_wallet = get_user_wallet(transaction.orders[0].customer_id)
|
482 |
user_wallet = get_user_wallet(transaction.orders[0].customer_id)
|
| 488 |
if user_wallet and user_wallet.amount < wallet_amount_used:
|
483 |
if user_wallet and user_wallet.amount < wallet_amount_used:
|
| - |
|
484 |
if new_status == TransactionStatus.AUTHORIZED:
|
| - |
|
485 |
try:
|
| - |
|
486 |
captured_amount = __capture_txn(transaction_id)
|
| - |
|
487 |
add_amount_in_wallet(transaction.customer_id, captured_amount, transaction_id, WalletReferenceType.PURCHASE, False, True)
|
| - |
|
488 |
except:
|
| - |
|
489 |
pass
|
| 489 |
return False
|
490 |
return False
|
| 490 |
payment_client = PaymentClient().get_client()
|
491 |
payment_client = PaymentClient().get_client()
|
| 491 |
payments = payment_client.getPaymentForTxnId(order.transaction_id)
|
492 |
payments = payment_client.getPaymentForTxnId(order.transaction_id)
|
| 492 |
wallet_payment_exist = False
|
493 |
wallet_payment_exist = False
|
| 493 |
for payment in payments:
|
494 |
for payment in payments:
|
| Line 496... |
Line 497... |
| 496 |
payment_client.updatePaymentDetails(payment.paymentId, "", "", "SUCCESS", "Payment Received", "", "", "", "", PaymentStatus.SUCCESS, "", None);
|
497 |
payment_client.updatePaymentDetails(payment.paymentId, "", "", "SUCCESS", "Payment Received", "", "", "", "", PaymentStatus.SUCCESS, "", None);
|
| 497 |
if not wallet_payment_exist:
|
498 |
if not wallet_payment_exist:
|
| 498 |
return False
|
499 |
return False
|
| 499 |
consume_wallet(transaction.orders[0].customer_id, wallet_amount_used, transaction_id, WalletReferenceType.PURCHASE)
|
500 |
consume_wallet(transaction.orders[0].customer_id, wallet_amount_used, transaction_id, WalletReferenceType.PURCHASE)
|
| 500 |
|
501 |
|
| - |
|
502 |
|
| - |
|
503 |
transaction.status = new_status
|
| - |
|
504 |
transaction.status_message = description
|
| - |
|
505 |
expectedDelayMap = {}
|
| - |
|
506 |
billingWarehouseIdMap = {}
|
| - |
|
507 |
billingWarehouseTxnMap = {}
|
| - |
|
508 |
|
| - |
|
509 |
|
| - |
|
510 |
|
| 501 |
## Assign runner in case of delhi pincodes
|
511 |
## Assign runner in case of delhi pincodes
|
| 502 |
if transaction.orders[0].pickupStoreId:
|
512 |
if transaction.orders[0].pickupStoreId:
|
| 503 |
logistics_client = LogisticsClient().get_client()
|
513 |
logistics_client = LogisticsClient().get_client()
|
| 504 |
store = logistics_client.getPickupStore(transaction.orders[0].pickupStoreId)
|
514 |
store = logistics_client.getPickupStore(transaction.orders[0].pickupStoreId)
|
| 505 |
if delhi_pincodes.__contains__(store.pin):
|
515 |
if delhi_pincodes.__contains__(store.pin):
|
| Line 2058... |
Line 2068... |
| 2058 |
raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit)+" Suggestion: Split Order!!!")
|
2068 |
raise TransactionServiceException(212, "Logistics Partner "+provider.name+ " Max Prepaid Amount Limit Violated Rs." +str(providerPrepaidLimit)+" Suggestion: Split Order!!!")
|
| 2059 |
|
2069 |
|
| 2060 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
|
2070 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
|
| 2061 |
if not order.cod:
|
2071 |
if not order.cod:
|
| 2062 |
if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option!=capitalFloatPayMethod:
|
2072 |
if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option!=capitalFloatPayMethod:
|
| 2063 |
__capture_txn(order)
|
2073 |
__capture_txn(order.transaction_id)
|
| - |
|
2074 |
change_transaction_status(order.transaction_id, TransactionStatus.IN_PROCESS, "Payment received", PickUpType.COURIER, order.orderType, order.source)
|
| 2064 |
order.status = OrderStatus.ACCEPTED
|
2075 |
order.status = OrderStatus.ACCEPTED
|
| 2065 |
order.statusDescription = "Order Accepted"
|
2076 |
order.statusDescription = "Order Accepted"
|
| 2066 |
order.accepted_timestamp = datetime.datetime.now()
|
2077 |
order.accepted_timestamp = datetime.datetime.now()
|
| 2067 |
txnSeqRequired = 0
|
2078 |
txnSeqRequired = 0
|
| 2068 |
txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==order.transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
|
2079 |
txnShipSeq = TransactionShipmentSequence.query.filter(TransactionShipmentSequence.transactionId==order.transaction_id).order_by(desc(TransactionShipmentSequence.id)).first()
|
| Line 2114... |
Line 2125... |
| 2114 |
return True
|
2125 |
return True
|
| 2115 |
else:
|
2126 |
else:
|
| 2116 |
logging.warning("Accept called for the unacceptable order: " + str(orderId))
|
2127 |
logging.warning("Accept called for the unacceptable order: " + str(orderId))
|
| 2117 |
return False
|
2128 |
return False
|
| 2118 |
|
2129 |
|
| - |
|
2130 |
|
| 2119 |
def __capture_txn(order):
|
2131 |
def __capture_txn(txnId):
|
| 2120 |
txnId = order.transaction_id
|
- |
|
| 2121 |
logging.info("Capturing payment for merchant txn:" + str(txnId))
|
2132 |
logging.info("Capturing payment for merchant txn:" + str(txnId))
|
| - |
|
2133 |
captured_amount = 0
|
| 2122 |
try:
|
2134 |
try:
|
| 2123 |
payment_client = PaymentClient().get_client()
|
2135 |
payment_client = PaymentClient().get_client()
|
| 2124 |
payments = payment_client.getPaymentForTxnId(order.transaction_id)
|
2136 |
payments = payment_client.getPaymentForTxnId(txnId)
|
| 2125 |
for payment in payments:
|
2137 |
for payment in payments:
|
| 2126 |
if payment.gatewayId in (gvGatewayId, walletGatewayId):
|
2138 |
if payment.gatewayId in (gvGatewayId, walletGatewayId):
|
| 2127 |
continue
|
2139 |
continue
|
| 2128 |
capture_result = payment_client.capturePayment(txnId, False)
|
2140 |
capture_result = payment_client.capturePayment(txnId, False)
|
| 2129 |
if capture_result:
|
2141 |
if capture_result:
|
| - |
|
2142 |
captured_amount = captured_amount + payment.amount
|
| 2130 |
logging.info("Successfully captured payment for merchant txn:" + str(txnId))
|
2143 |
logging.info("Successfully captured payment for merchant txn:" + str(txnId))
|
| 2131 |
change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received", PickUpType.COURIER, order.orderType, order.source)
|
2144 |
#change_transaction_status(txnId, TransactionStatus.IN_PROCESS, "Payment received", PickUpType.COURIER, order.orderType, order.source)
|
| 2132 |
else:
|
2145 |
else:
|
| 2133 |
raise TransactionServiceException(115, "Payment capture failed.")
|
2146 |
raise TransactionServiceException(115, "Payment capture failed.")
|
| - |
|
2147 |
return captured_amount
|
| 2134 |
except PaymentException as e:
|
2148 |
except PaymentException as e:
|
| 2135 |
if e.error_code == 106:
|
2149 |
if e.error_code == 106:
|
| 2136 |
order.status = OrderStatus.CAPTURE_IN_PROCESS
|
2150 |
#order.status = OrderStatus.CAPTURE_IN_PROCESS
|
| 2137 |
session.commit()
|
2151 |
#session.commit()
|
| 2138 |
raise TransactionServiceException(122, "Unable to capture payment due to connection issue.")
|
2152 |
raise TransactionServiceException(122, "Unable to capture payment due to connection issue.")
|
| 2139 |
else:
|
2153 |
else:
|
| 2140 |
raise TransactionServiceException(115, "Payment capture failed.")
|
2154 |
raise TransactionServiceException(115, "Payment capture failed.")
|
| 2141 |
|
2155 |
|
| 2142 |
def __amend_fulfilment_warehouse(order):
|
2156 |
def __amend_fulfilment_warehouse(order):
|
| Line 5730... |
Line 5744... |
| 5730 |
## User is trying to play smart. Let us first mark his recharge failed and then credit payment amount to his wallet.
|
5744 |
## User is trying to play smart. Let us first mark his recharge failed and then credit payment amount to his wallet.
|
| 5731 |
recharge_order.status = RechargeOrderStatus.RECHARGE_FAILED
|
5745 |
recharge_order.status = RechargeOrderStatus.RECHARGE_FAILED
|
| 5732 |
recharge_order.responseTimestamp = datetime.datetime.now()
|
5746 |
recharge_order.responseTimestamp = datetime.datetime.now()
|
| 5733 |
session.commit()
|
5747 |
session.commit()
|
| 5734 |
#update_amount_in_wallet(recharge_order.userId, recharge_order.totalAmount - recharge_order.walletAmount - recharge_order.couponAmount, recharge_order.id, 0)
|
5748 |
#update_amount_in_wallet(recharge_order.userId, recharge_order.totalAmount - recharge_order.walletAmount - recharge_order.couponAmount, recharge_order.id, 0)
|
| 5735 |
consume_wallet(recharge_order.userId, recharge_order.totalAmount - recharge_order.walletAmount - recharge_order.couponAmount, recharge_order.id, WalletReferenceType.RECHARGE)
|
5749 |
add_amount_in_wallet(recharge_order.userId, recharge_order.totalAmount - recharge_order.walletAmount - recharge_order.couponAmount, recharge_order.id, WalletReferenceType.RECHARGE,False, True)
|
| 5736 |
raise TransactionServiceException(103, 'Wallet amount has already been used')
|
5750 |
raise TransactionServiceException(103, 'Wallet amount has already been used')
|
| 5737 |
|
5751 |
|
| 5738 |
try:
|
5752 |
try:
|
| 5739 |
if activate_recharge_txn(recharge_order):
|
5753 |
if activate_recharge_txn(recharge_order):
|
| 5740 |
recharge_order.invoiceNumber = get_next_invoice_number(OrderType.RECHARGE)
|
5754 |
recharge_order.invoiceNumber = get_next_invoice_number(OrderType.RECHARGE)
|
| Line 8708... |
Line 8722... |
| 8708 |
|
8722 |
|
| 8709 |
for order in updatedOrders:
|
8723 |
for order in updatedOrders:
|
| 8710 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
|
8724 |
if order.status in [OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.INVENTORY_LOW, OrderStatus.LOW_INV_PO_RAISED, OrderStatus.LOW_INV_REVERSAL_IN_PROCESS, OrderStatus.LOW_INV_NOT_AVAILABLE_AT_HOTSPOT, OrderStatus.CAPTURE_IN_PROCESS]:
|
| 8711 |
if not order.cod:
|
8725 |
if not order.cod:
|
| 8712 |
if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option != capitalFloatPayMethod:
|
8726 |
if order.transaction.status == TransactionStatus.AUTHORIZED and order.transaction.payment_option != capitalFloatPayMethod:
|
| 8713 |
__capture_txn(order)
|
8727 |
__capture_txn(order.transaction_id)
|
| - |
|
8728 |
change_transaction_status(order.transaction_id, TransactionStatus.IN_PROCESS, "Payment received", PickUpType.COURIER, order.orderType, order.source)
|
| - |
|
8729 |
|
| 8714 |
break
|
8730 |
break
|
| 8715 |
''' Change IP using Config Client and Handle Exception '''
|
8731 |
''' Change IP using Config Client and Handle Exception '''
|
| 8716 |
try:
|
8732 |
try:
|
| 8717 |
inventoryDbHost = str(ConfigClient().get_property("inventory_service_db_hostname"))
|
8733 |
inventoryDbHost = str(ConfigClient().get_property("inventory_service_db_hostname"))
|
| 8718 |
conn = getDbConnection(inventoryDbHost,"root", "shop2020", "inventory")
|
8734 |
conn = getDbConnection(inventoryDbHost,"root", "shop2020", "inventory")
|