Skip to content

fix(payment): EasyPay 查单以 trade_status 判定支付成功,避免未付订单误判到账#2975

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
wucm667:fix/easypay-queryorder-trade-status
Jun 5, 2026
Merged

fix(payment): EasyPay 查单以 trade_status 判定支付成功,避免未付订单误判到账#2975
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
wucm667:fix/easypay-queryorder-trade-status

Conversation

@wucm667

@wucm667 wucm667 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

背景

EasyPay 主动查单此前只按 status == 1 判定已支付,未读取 trade_status。部分 EasyPay 兼容接口在等待支付或查询失败场景也可能返回 status=1,会导致 sub2api 在轮询/恢复订单时把未付款订单标记为 completed 并给用户充值,而商户侧实际未收款。

本修复将主动查单与 webhook 路径的 trade_status == TRADE_SUCCESS 口径对齐,作为资金安全修复,防止未付订单误充值。

改动

  • QueryOrder 解析顶层与嵌套 data 下的 trade_statusstatusmoneytrade_no
  • 优先以 trade_status == TRADE_SUCCESS 判定支付成功;WAITING、空值或其它非成功值均保持 pending。
  • 仅在顶层和 data 均缺失 trade_status 时,才回退旧版 status == 1 兼容逻辑。
  • 兼容嵌套 data.money / data.trade_no 返回格式。

测试

  • trade_status=TRADE_SUCCESS → paid
  • trade_status=WAITINGstatus=1 → pending
  • trade_status=""status=1 → pending
  • data.trade_status=TRADE_SUCCESS / data.money / data.trade_no → paid 并正确读取嵌套字段
  • 旧版仅返回数字 status=1(无 trade_status)→ paid
  • 旧版 status!=1 且无 trade_status → pending
  • 查询失败/字段缺失 → pending
  • go test -tags=unit ./internal/payment/...
  • go test -tags=unit ./...
  • golangci-lint run ./...

Fixes #2958

@wucm667

wucm667 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

CI 失败看起来是 runner 外部网络问题,不是本 PR 的 EasyPay 逻辑失败:unit tests 已通过,包含 internal/payment/provider;失败发生在 make test-integration 启动 testcontainers 时,Redis/Postgres 镜像拉取访问 Docker Hub 超时(https://registry-1.docker.io/v2/ timeout)。我这边没有 upstream admin 权限触发 rerun,麻烦维护者重跑 failed job。

@Wei-Shaw Wei-Shaw merged commit e080d3f into Wei-Shaw:main Jun 5, 2026
6 of 7 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 5, 2026
@wucm667 wucm667 deleted the fix/easypay-queryorder-trade-status branch June 5, 2026 06:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] EasyPay 查询订单时可能把未支付/查询失败订单误判为已支付

2 participants