更新日志
This commit is contained in:
parent
04679ac6c8
commit
ab7d4bed72
|
@ -1,5 +1,7 @@
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from custom_decorators import singleton
|
from custom_decorators import singleton
|
||||||
from models import Order
|
from models import Order
|
||||||
from repositories.order import OrderRepository
|
from repositories.order import OrderRepository
|
||||||
|
@ -64,7 +66,7 @@ class OrderService:
|
||||||
now = current_timestamp()
|
now = current_timestamp()
|
||||||
quant, from_address, to_address, create_timestamp = self.order_repo.get_order_info(order_id)
|
quant, from_address, to_address, create_timestamp = self.order_repo.get_order_info(order_id)
|
||||||
if is_time_difference_greater_than(create_timestamp, now, milliseconds=self.config.order.lifetime):
|
if is_time_difference_greater_than(create_timestamp, now, milliseconds=self.config.order.lifetime):
|
||||||
# 订单超时
|
logger.debug('Timed Out')
|
||||||
status = 0
|
status = 0
|
||||||
else:
|
else:
|
||||||
correct_quant, confirmed = self.payment_service.check_payment(int(quant),
|
correct_quant, confirmed = self.payment_service.check_payment(int(quant),
|
||||||
|
@ -72,14 +74,16 @@ class OrderService:
|
||||||
# 减去十秒, 避免网络延迟导致的订单创建时间太晚
|
# 减去十秒, 避免网络延迟导致的订单创建时间太晚
|
||||||
create_timestamp - 10000, now)
|
create_timestamp - 10000, now)
|
||||||
if correct_quant and confirmed:
|
if correct_quant and confirmed:
|
||||||
# 支付成功
|
logger.debug('Paid')
|
||||||
status = 1
|
status = 1
|
||||||
elif confirmed:
|
elif confirmed:
|
||||||
# 金额不对
|
logger.debug('Wrong Amount')
|
||||||
status = 3
|
status = 3
|
||||||
elif correct_quant:
|
elif correct_quant:
|
||||||
# 支付尚未成功
|
logger.debug('Pending')
|
||||||
status = 4
|
status = 4
|
||||||
|
else:
|
||||||
|
logger.debug('Unpaid')
|
||||||
if status != 2:
|
if status != 2:
|
||||||
self.order_repo.update_status(order_id, status)
|
self.order_repo.update_status(order_id, status)
|
||||||
return status
|
return status
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
from api import Tronscan
|
from api import Tronscan
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
from custom_decorators import singleton
|
from custom_decorators import singleton
|
||||||
from utils.datetime import current_timestamp
|
from utils.datetime import current_timestamp
|
||||||
|
|
||||||
|
@ -17,9 +19,11 @@ class PaymentService:
|
||||||
from_address=from_address, to_address=to_address,
|
from_address=from_address, to_address=to_address,
|
||||||
start_timestamp=order_create_timestamp, end_timestamp=end_timestamp)
|
start_timestamp=order_create_timestamp, end_timestamp=end_timestamp)
|
||||||
if result['rangeTotal'] == 0:
|
if result['rangeTotal'] == 0:
|
||||||
|
logger.debug('No payments found')
|
||||||
return 0, 0
|
return 0, 0
|
||||||
token_transfers = result['token_transfers']
|
token_transfers = result['token_transfers']
|
||||||
token_transfer = token_transfers[-1]
|
token_transfer = token_transfers[-1]
|
||||||
confirmed = token_transfer['confirmed']
|
confirmed = token_transfer['confirmed']
|
||||||
correct_quant = int(quant == (token_transfer['quant'] / 6))
|
correct_quant = int(quant == (token_transfer['quant'] / 6))
|
||||||
|
logger.debug(f'correct_quant: {correct_quant} confirmed: {confirmed}')
|
||||||
return correct_quant, confirmed
|
return correct_quant, confirmed
|
||||||
|
|
Loading…
Reference in New Issue