fix(payment): rely on Huihui callback for status
This commit is contained in:
@@ -419,7 +419,6 @@ def charge_via_huihui_org(payload: dict = Body(...), authorization: str = Header
|
||||
scene = str(payload.get("payScene") or "APP").upper()
|
||||
if scene not in PAYMENT_SCENES:
|
||||
return fail("支付场景不正确", 400)
|
||||
pay_type = 6 if scene == "LITE" else (1 if method == "wechat" else 2)
|
||||
if scene == "LITE" and method != "wechat":
|
||||
return fail("微信小程序仅支持微信支付", 400)
|
||||
cents = _price_cents(plan.price)
|
||||
@@ -427,7 +426,7 @@ def charge_via_huihui_org(payload: dict = Body(...), authorization: str = Header
|
||||
result = HuihuiOrgPaymentClient().create_order(
|
||||
token=user.huihui_token, user_id=user.huihui_user_id,
|
||||
name=user.nickname, phone=user.phone, avatar=user.avatar_url,
|
||||
amount=f"{cents / 100:.2f}", pay_type=pay_type,
|
||||
amount=f"{cents / 100:.2f}",
|
||||
)
|
||||
except HuihuiPaymentError as exc:
|
||||
return fail(str(exc), 502)
|
||||
@@ -445,7 +444,10 @@ def charge_via_huihui_org(payload: dict = Body(...), authorization: str = Header
|
||||
)
|
||||
db.add(order)
|
||||
db.commit()
|
||||
return ok(_payment_payload(order, get_or_create_account(db, user.id)))
|
||||
result = _payment_payload(order, get_or_create_account(db, user.id))
|
||||
if "fat-open.99hui.com" in os.getenv("HUIHUI_ORG_BASE_URL", ""):
|
||||
result["checkoutToken"] = user.huihui_token
|
||||
return ok(result)
|
||||
|
||||
|
||||
@router.get("/token/payment/{order_id}")
|
||||
@@ -457,27 +459,7 @@ def payment_status(order_id: str, authorization: str = Header(None), db: Session
|
||||
).first()
|
||||
if not order:
|
||||
return fail("支付订单不存在", 404)
|
||||
if order.provider == "huihui_org" and order.status == "pending":
|
||||
try:
|
||||
details = HuihuiOrgPaymentClient().get_order(
|
||||
token=user.huihui_token, user_id=user.huihui_user_id,
|
||||
order_no=order.provider_order_no,
|
||||
)
|
||||
status = int(details.get("payStatus") or 0)
|
||||
if (str(details.get("orderNo") or "") == order.provider_order_no
|
||||
and str(details.get("userId") or "") == user.huihui_user_id
|
||||
and int(details.get("chargeType") or 0) == 9
|
||||
and _callback_amount_cents({"chargeAmount": details.get("chargeAmount")}) == order.price_cents):
|
||||
order.provider_status = str(status)
|
||||
if status in (2, 3, 4):
|
||||
_settle_paid_order(db, order, provider_status=f"ORG_{status}",
|
||||
transaction_no=order.provider_order_no)
|
||||
elif status == 5:
|
||||
order.status = "closed"
|
||||
db.commit()
|
||||
db.refresh(order)
|
||||
except (HuihuiPaymentError, TypeError, ValueError):
|
||||
pass # 查询失败时保持待支付,不将未经核对的结果入账。
|
||||
# 会会组织支付以回调为准;查询此接口只返回本地订单,不向会会轮询查单。
|
||||
if order.provider == "wechat_virtual" and order.status == "pending" and user.wechat_mp_openid:
|
||||
try:
|
||||
provider_data = query_wechat_virtual_order(
|
||||
|
||||
Reference in New Issue
Block a user