feat(v2): webhook v2 outbox + Notifier(event_type + HMAC 双向 + 重试兜底)
This commit is contained in:
@@ -26,7 +26,7 @@ func OpenTestDB(t *testing.T) *gorm.DB {
|
||||
if err != nil {
|
||||
t.Fatalf("open test db: %v", err)
|
||||
}
|
||||
if err := db.AutoMigrate(&OrderV2{}, &Attempt{}, &Account{}, &Refund{}); err != nil {
|
||||
if err := db.AutoMigrate(&OrderV2{}, &Attempt{}, &Account{}, &Refund{}, &WebhookDelivery{}); err != nil {
|
||||
t.Fatalf("migrate: %v", err)
|
||||
}
|
||||
sqlDB, _ := db.DB()
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package model
|
||||
|
||||
// WebhookDelivery 是 pay→业务方 webhook 的 outbox(v2)。unique(out_trade_no,event_type)
|
||||
// 保证同一订单同一事件只入队一次(幂等);后台 Notifier 扫 Delivered=false 重试兜底。
|
||||
type WebhookDelivery struct {
|
||||
Base
|
||||
OutTradeNo string `gorm:"size:64;not null;uniqueIndex:uq_delivery" json:"out_trade_no"`
|
||||
EventType string `gorm:"size:32;not null;uniqueIndex:uq_delivery" json:"event_type"`
|
||||
BizSystem string `gorm:"index;size:32" json:"biz_system"`
|
||||
Payload string `gorm:"type:text" json:"payload"` // 已序列化的领域 JSON(含 event_type)
|
||||
Delivered bool `gorm:"index;default:false" json:"delivered"`
|
||||
Attempts int `json:"attempts"`
|
||||
LastError string `gorm:"size:255" json:"last_error,omitempty"`
|
||||
}
|
||||
Reference in New Issue
Block a user