feat(v2): outbox 退款感知(refund_id 进唯一键)+ 投递门禁放行退款态 + Enqueue 贯通 refundID
This commit is contained in:
@@ -43,13 +43,14 @@ func NewNotifier(ws *store.WebhookStore, bizConfig BizConfigFunc, orderPaid Orde
|
||||
}
|
||||
|
||||
// Enqueue implements gateway.WebhookEnqueuer: serialize the domain payload and
|
||||
// idempotently persist it to the outbox (delivery happens async).
|
||||
func (n *Notifier) Enqueue(outTradeNo, bizSystem, eventType string, data map[string]any) error {
|
||||
// idempotently persist it to the outbox (delivery happens async). refundID is
|
||||
// the refund's idempotency dimension (payment events pass "").
|
||||
func (n *Notifier) Enqueue(outTradeNo, bizSystem, eventType, refundID string, data map[string]any) error {
|
||||
body, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
return fmt.Errorf("webhook.Enqueue marshal: %w", err)
|
||||
}
|
||||
return n.deliveries.EnqueueDelivery(outTradeNo, bizSystem, eventType, string(body))
|
||||
return n.deliveries.EnqueueDelivery(outTradeNo, bizSystem, eventType, refundID, string(body))
|
||||
}
|
||||
|
||||
// DeliverPending flushes undelivered rows; returns how many succeeded this pass.
|
||||
|
||||
@@ -37,7 +37,7 @@ func TestNotifierDeliversSignedEvent(t *testing.T) {
|
||||
n := webhook.NewNotifier(ws, bizCfg, alwaysPaid)
|
||||
|
||||
// 经 Enqueuer 接口入队(gateway 就是这么调的)。
|
||||
err := n.Enqueue("PAY-1", "pangolin", "payment.succeeded", map[string]any{
|
||||
err := n.Enqueue("PAY-1", "pangolin", "payment.succeeded", "", map[string]any{
|
||||
"event_type": "payment.succeeded", "out_trade_no": "PAY-1", "amount_minor": 29990000, "currency": "USDT",
|
||||
})
|
||||
if err != nil {
|
||||
@@ -84,7 +84,7 @@ func TestNotifierRetriesOnFailure(t *testing.T) {
|
||||
n := webhook.NewNotifier(ws, func(string) (config.BizSystemConfig, bool) {
|
||||
return config.BizSystemConfig{CallbackURL: srv.URL, Secret: "x"}, true
|
||||
}, func(string) (bool, error) { return true, nil })
|
||||
_ = n.Enqueue("PAY-3", "pangolin", "payment.succeeded", map[string]any{"event_type": "payment.succeeded"})
|
||||
_ = n.Enqueue("PAY-3", "pangolin", "payment.succeeded", "", map[string]any{"event_type": "payment.succeeded"})
|
||||
|
||||
if sent, _ := n.DeliverPending(10); sent != 0 {
|
||||
t.Fatalf("失败不应算投递成功, got %d", sent)
|
||||
@@ -115,7 +115,7 @@ func TestNotifierGateSkipsUnpaidOrder(t *testing.T) {
|
||||
n := webhook.NewNotifier(ws, func(string) (config.BizSystemConfig, bool) {
|
||||
return config.BizSystemConfig{CallbackURL: srv.URL, Secret: "x"}, true
|
||||
}, func(string) (bool, error) { return paid, nil })
|
||||
_ = n.Enqueue("PAY-4", "pangolin", "payment.succeeded", map[string]any{"event_type": "payment.succeeded"})
|
||||
_ = n.Enqueue("PAY-4", "pangolin", "payment.succeeded", "", map[string]any{"event_type": "payment.succeeded"})
|
||||
|
||||
if sent, _ := n.DeliverPending(10); sent != 0 || hits != 0 {
|
||||
t.Fatalf("未付单不应投递, sent=%d hits=%d", sent, hits)
|
||||
|
||||
Reference in New Issue
Block a user