developing
This commit is contained in:
parent
6a28a8fb97
commit
d32c4cc67a
|
@ -43,5 +43,16 @@ def create_order():
|
||||||
return jsonify({"order_id": order_id}), 200
|
return jsonify({"order_id": order_id}), 200
|
||||||
|
|
||||||
|
|
||||||
|
order_status = config.order.order_status
|
||||||
|
@app.route('/finishOrder', methods=['GET'])
|
||||||
|
def finish_order():
|
||||||
|
data = request.get_json()
|
||||||
|
order_id = data.get('order_id', None)
|
||||||
|
status = order_service.finish_order(order_id)
|
||||||
|
return jsonify({"order_id": order_id,
|
||||||
|
"status": status,
|
||||||
|
"msg": order_status[status]}), 200
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
order:
|
order:
|
||||||
lifetime: 10min
|
lifetime: 10min
|
||||||
order_status:
|
order_status:
|
||||||
- 未支付
|
- Timed Out
|
||||||
- 支付成功
|
- Paid
|
||||||
- 未转账
|
- Unpaid
|
||||||
- 金额不对
|
- Wrong Amount
|
||||||
- 订单超时
|
- Pending
|
||||||
|
|
|
@ -24,12 +24,12 @@ class OrderService:
|
||||||
|
|
||||||
def finish_order(self, order_id):
|
def finish_order(self, order_id):
|
||||||
# 判断支付时间是否超过订单存活时间
|
# 判断支付时间是否超过订单存活时间
|
||||||
quant, from_address, to_address, create_timestamp = self.order_repo.get_order_info(order_id)
|
status = 2
|
||||||
now = current_timestamp()
|
now = current_timestamp()
|
||||||
status = 0
|
quant, from_address, to_address, create_timestamp = self.order_repo.get_order_info(order_id)
|
||||||
if is_time_difference_greater_than(create_timestamp, now, **parse_time_string(self.config.order.lifetime)):
|
if is_time_difference_greater_than(create_timestamp, now, **parse_time_string(self.config.order.lifetime)):
|
||||||
# 订单超时
|
# 订单超时
|
||||||
status = 4
|
status = 0
|
||||||
else:
|
else:
|
||||||
correct_quant, confirmed = self.payment_service.check_payment(quant,
|
correct_quant, confirmed = self.payment_service.check_payment(quant,
|
||||||
from_address, to_address,
|
from_address, to_address,
|
||||||
|
@ -37,12 +37,12 @@ class OrderService:
|
||||||
if correct_quant and confirmed:
|
if correct_quant and confirmed:
|
||||||
# 支付成功
|
# 支付成功
|
||||||
status = 1
|
status = 1
|
||||||
elif correct_quant < 0:
|
|
||||||
# 没有转账
|
|
||||||
status = 2
|
|
||||||
elif confirmed:
|
elif confirmed:
|
||||||
# 金额不对
|
# 金额不对
|
||||||
status = 3
|
status = 3
|
||||||
|
elif correct_quant:
|
||||||
|
# 支付尚未成功
|
||||||
|
status = 4
|
||||||
if status:
|
if status:
|
||||||
self.order_repo.update_status(order_id, status)
|
self.order_repo.update_status(order_id, status)
|
||||||
return status
|
return status
|
||||||
|
|
|
@ -15,7 +15,7 @@ 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:
|
||||||
return -1, 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']
|
||||||
|
|
Loading…
Reference in New Issue