-
Notifications
You must be signed in to change notification settings - Fork 288
feat: 新增支付、退款、商家转账批次回调通知解析服务 #381
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: 新增支付、退款、商家转账批次回调通知解析服务 #381
Conversation
|
@MonkeyCode-AI review 一下 |
|
MonkeyCode-AI 正在分析任务... |
MonkeyCode-AI
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我是 MonkeyCode AI 编程助手,你可以在 GitHub 仓库的 PR 中 at @MonkeyCode-AI 来呼唤我。
任务执行细节请参考: https://monkeycode-ai.com/tasks/public?id=15288f23-9694-49dd-b2d8-4bd7642d9a32
代码审查结果
新增三类回调通知解析服务与示例整体一致简洁,但 Builder 缺少 config/parser 校验会触发 NPE,且 TransferBatchNotification 的 CloseReasonType 可能缺失导致编译失败,需修复后再合并。
✨ 代码亮点
- 三个回调解析服务 API 形态一致,封装了 NotificationParser.parse 的类型参数,降低调用方心智负担
- 示例代码包含异常类型区分(MalformedMessageException vs ValidationException),便于用户正确处理回调错误
| 🚨 Critical | 💡 Suggestion | |
|---|---|---|
| 3 | 0 | 0 |
| public PaymentNotificationParseService build() { | ||
| if (parser == null && config != null) { | ||
| return new PaymentNotificationParseService(new NotificationParser(config)); | ||
| } | ||
| return new PaymentNotificationParseService(parser); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
🚨 Builder 在未提供 config/parser 时会导致构造时 NPE
build() 在 parser==null 且 config==null 时,会执行 new PaymentNotificationParseService(parser),随后构造函数 requireNonNull(parser) 直接抛出 NullPointerException。该异常不在方法签名/文档中,且对使用者不友好。应在 build() 中对入参组合进行显式校验并抛出更明确的 IllegalArgumentException/IllegalStateException,或提供默认构造路径。
建议: 在 build() 中增加对 (parser==null && config==null) 的校验并抛出 IllegalArgumentException/IllegalStateException;同时保持现有优先级:显式 parser 优先,否则用 config 创建 parser。
| public PaymentNotificationParseService build() { | |
| if (parser == null && config != null) { | |
| return new PaymentNotificationParseService(new NotificationParser(config)); | |
| } | |
| return new PaymentNotificationParseService(parser); | |
| } | |
| public PaymentNotificationParseService build() { | |
| if (parser != null) { | |
| return new PaymentNotificationParseService(parser); | |
| } | |
| if (config != null) { | |
| return new PaymentNotificationParseService(new NotificationParser(config)); | |
| } | |
| throw new IllegalStateException( | |
| "PaymentNotificationParseService.Builder requires either a NotificationConfig or a NotificationParser"); | |
| } |
| public RefundNotificationParseService build() { | ||
| if (parser == null && config != null) { | ||
| return new RefundNotificationParseService(new NotificationParser(config)); | ||
| } | ||
| return new RefundNotificationParseService(parser); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
🚨 Builder 在未提供 config/parser 时会导致构造时 NPE
与 PaymentNotificationParseService 相同:build() 在 parser==null 且 config==null 时会把 null 传入构造函数并在 requireNonNull 处 NPE。需要显式参数校验。
建议: 同 PaymentNotificationParseService:优先使用显式 parser,否则用 config 构造 parser,否则抛出 IllegalStateException。
| public RefundNotificationParseService build() { | |
| if (parser == null && config != null) { | |
| return new RefundNotificationParseService(new NotificationParser(config)); | |
| } | |
| return new RefundNotificationParseService(parser); | |
| } | |
| public RefundNotificationParseService build() { | |
| if (parser != null) { | |
| return new RefundNotificationParseService(parser); | |
| } | |
| if (config != null) { | |
| return new RefundNotificationParseService(new NotificationParser(config)); | |
| } | |
| throw new IllegalStateException( | |
| "RefundNotificationParseService.Builder requires either a NotificationConfig or a NotificationParser"); | |
| } |
| public TransferBatchNotificationParseService build() { | ||
| if (parser == null && config != null) { | ||
| return new TransferBatchNotificationParseService(new NotificationParser(config)); | ||
| } | ||
| return new TransferBatchNotificationParseService(parser); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caution
🚨 Builder 在未提供 config/parser 时会导致构造时 NPE
与另外两个 ParseService 相同:build() 未对 (parser==null && config==null) 做保护,会在 requireNonNull(parser) 处抛 NPE。
建议: 同上,增加显式校验并抛出清晰异常信息。
| public TransferBatchNotificationParseService build() { | |
| if (parser == null && config != null) { | |
| return new TransferBatchNotificationParseService(new NotificationParser(config)); | |
| } | |
| return new TransferBatchNotificationParseService(parser); | |
| } | |
| public TransferBatchNotificationParseService build() { | |
| if (parser != null) { | |
| return new TransferBatchNotificationParseService(parser); | |
| } | |
| if (config != null) { | |
| return new TransferBatchNotificationParseService(new NotificationParser(config)); | |
| } | |
| throw new IllegalStateException( | |
| "TransferBatchNotificationParseService.Builder requires either a NotificationConfig or a NotificationParser"); | |
| } |
Issues #380