diff --git a/payment_backend/app.py b/payment_backend/app.py index 30fea6e..e5121d7 100644 --- a/payment_backend/app.py +++ b/payment_backend/app.py @@ -43,5 +43,16 @@ def create_order(): 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__': app.run(debug=True) diff --git a/payment_backend/config/param.yaml b/payment_backend/config/param.yaml index 2c9509f..e5d05aa 100644 --- a/payment_backend/config/param.yaml +++ b/payment_backend/config/param.yaml @@ -1,8 +1,8 @@ order: lifetime: 10min order_status: - - 未支付 - - 支付成功 - - 未转账 - - 金额不对 - - 订单超时 + - Timed Out + - Paid + - Unpaid + - Wrong Amount + - Pending diff --git a/payment_backend/services/order.py b/payment_backend/services/order.py index 55b787c..01912b5 100644 --- a/payment_backend/services/order.py +++ b/payment_backend/services/order.py @@ -24,12 +24,12 @@ class OrderService: 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() - 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)): # 订单超时 - status = 4 + status = 0 else: correct_quant, confirmed = self.payment_service.check_payment(quant, from_address, to_address, @@ -37,12 +37,12 @@ class OrderService: if correct_quant and confirmed: # 支付成功 status = 1 - elif correct_quant < 0: - # 没有转账 - status = 2 elif confirmed: # 金额不对 status = 3 + elif correct_quant: + # 支付尚未成功 + status = 4 if status: self.order_repo.update_status(order_id, status) return status diff --git a/payment_backend/services/payment.py b/payment_backend/services/payment.py index b602376..75a6824 100644 --- a/payment_backend/services/payment.py +++ b/payment_backend/services/payment.py @@ -15,7 +15,7 @@ class PaymentService: from_address=from_address, to_address=to_address, start_timestamp=order_create_timestamp, end_timestamp=end_timestamp) if result['rangeTotal'] == 0: - return -1, 0 + return 0, 0 token_transfers = result['token_transfers'] token_transfer = token_transfers[-1] confirmed = token_transfer['confirmed']