feat(v2): /api/v2 网关路由 + handler(下单/查/重试/取消/回调)+ main 装配 gateway/notifier

This commit is contained in:
wangjia
2026-07-10 11:36:47 +08:00
parent 63af44bfe1
commit a633b2ac0a
4 changed files with 292 additions and 1 deletions
+24 -1
View File
@@ -11,9 +11,14 @@ import (
"gorm.io/gorm/logger"
"github.com/wangjia/pay/config"
"github.com/wangjia/pay/internal/accounts"
"github.com/wangjia/pay/internal/channel"
"github.com/wangjia/pay/internal/gateway"
"github.com/wangjia/pay/internal/model"
"github.com/wangjia/pay/internal/provider"
"github.com/wangjia/pay/internal/router"
"github.com/wangjia/pay/internal/store"
"github.com/wangjia/pay/internal/webhook"
)
func main() {
@@ -32,6 +37,24 @@ func main() {
orderSvc := router.Setup(r, db, reg)
// v2 统一网关装配(P2):provider 注册表 + gateway + webhook notifier。
pReg := provider.NewRegistry()
// P3 起在此 Register 真实渠道:crypto / alipay / stripe …(fake 仅测试用,不注册进生产)。
orderStore := store.NewOrderStore(db)
webhookStore := store.NewWebhookStore(db)
notifier := webhook.NewNotifier(webhookStore, config.C.BizByName, func(no string) (bool, error) {
o, err := orderStore.GetOrder(no) // 投递门禁:订单已付才发(enqueue-before-flip 不变量)
if err != nil {
return false, err
}
return o.Status == model.OrderPaidV2, nil
})
notifier.Start(60 * time.Second)
productResolver := gateway.NewDBProductResolver(db, "CNY") // 币种按部署区配(cn=CNY / global=USDT)
acctReg := accounts.New(config.C.Accounts)
gw := gateway.New(orderStore, pReg, acctReg, productResolver, notifier, "cn")
router.SetupV2(r, gw)
if config.C.QuerySync.Enabled {
orderSvc.StartQuerySync(
time.Duration(config.C.QuerySync.IntervalSec)*time.Second,
@@ -80,7 +103,7 @@ func autoMigrate(db *gorm.DB) {
&model.Order{},
&model.NotifyLog{},
&model.BizNotifyLog{},
&model.OrderV2{}, &model.Attempt{}, &model.Account{}, &model.Refund{}, // v2
&model.OrderV2{}, &model.Attempt{}, &model.Account{}, &model.Refund{}, &model.WebhookDelivery{}, // v2
); err != nil {
log.Fatalf("自动迁移失败: %v", err)
}