feat(pay-v2): P8 Task7 业务方事件集声明 + 装配收尾 + 契约文档

This commit is contained in:
wangjia
2026-07-10 18:59:03 +08:00
parent b0714ca758
commit 2a4be0117d
4 changed files with 122 additions and 8 deletions
+19
View File
@@ -83,6 +83,10 @@ func (n *Notifier) deliverOne(d *store.WebhookDeliveryRow) bool {
_ = n.deliveries.MarkFailed(d.ID, "biz system not configured")
return false
}
if !eventSupported(cfg.SupportedEvents, d.EventType) {
_ = n.deliveries.MarkDelivered(d.ID) // 业务方未订阅该事件:视为已受理,不投递、不重试
return true
}
ts := strconv.FormatInt(time.Now().Unix(), 10)
nonce := uuid.NewString()
sign := util.HMACSign(cfg.Secret, d.BizSystem, ts, nonce, d.Payload)
@@ -115,6 +119,21 @@ func (n *Notifier) deliverOne(d *store.WebhookDeliveryRow) bool {
return false
}
// eventSupported 判断业务方是否声明支持该 event_type(设计 §「接入方显式声明支持事件
// 集」):list 为空 → 仅 payment.succeeded 为真(v1/P2 接入方向后兼容,不会突然收到
// subscription.*/chargeback.received 等新事件把它们搞崩);非空则按声明集精确匹配。
func eventSupported(list []string, ev string) bool {
if len(list) == 0 {
return ev == "payment.succeeded"
}
for _, e := range list {
if e == ev {
return true
}
}
return false
}
// truncate safely truncates a string to n bytes without splitting UTF-8 runes.
func truncate(s string, n int) string {
if len(s) <= n {