会员积分改版V10
This commit is contained in:
@@ -18,7 +18,8 @@ from app.services.payment import (
|
||||
verify_alipay_callback,
|
||||
process_payment_success_by_order_no,
|
||||
_get_payment_configs,
|
||||
_close_alipay_order,
|
||||
PaymentCloseResult,
|
||||
_resolve_order_for_cancellation,
|
||||
)
|
||||
|
||||
router = APIRouter(prefix="/payments", tags=["payments"])
|
||||
@@ -421,21 +422,28 @@ async def cancel_order(
|
||||
if order.status != "pending":
|
||||
raise HTTPException(status_code=400, detail=f"订单状态为{order.status},无法取消")
|
||||
|
||||
# Alipay/WeChat must confirm remote close before local cancellation.
|
||||
# If close fails or the remote state is uncertain, keep the local order
|
||||
# pending so a later gateway query can still discover a successful payment.
|
||||
# Resolve the authoritative gateway state before local cancellation.
|
||||
# If WeChat explicitly reports ORDERPAID, the payment service queries only
|
||||
# this order once and runs the normal atomic payment-success fulfillment.
|
||||
db_configs = await _get_payment_configs(db)
|
||||
closed = True
|
||||
if order.payment_method == "alipay":
|
||||
closed = await _close_alipay_order(db, order, db_configs)
|
||||
elif order.payment_method == "wechat":
|
||||
from app.services.payment import _close_wechat_order
|
||||
closed = await _close_wechat_order(db, order, db_configs)
|
||||
log_user_id = str(current_user.id)
|
||||
payment_method = str(order.payment_method)
|
||||
close_result = await _resolve_order_for_cancellation(db, order, db_configs)
|
||||
|
||||
if not closed:
|
||||
if close_result == PaymentCloseResult.PAID:
|
||||
logger.info(
|
||||
f"ORDER_CANCEL_PAID_RECOVERED order_no={order_no} "
|
||||
f"user={log_user_id} method={payment_method}"
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
detail="订单已支付并完成支付处理,无法取消",
|
||||
)
|
||||
|
||||
if close_result != PaymentCloseResult.CLOSED:
|
||||
logger.warning(
|
||||
f"ORDER_CANCEL_CLOSE_PENDING order_no={order_no} "
|
||||
f"user={current_user.id} method={order.payment_method}"
|
||||
f"user={log_user_id} method={payment_method}"
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=409,
|
||||
|
||||
Reference in New Issue
Block a user