64 lines
3.6 KiB
Go
64 lines
3.6 KiB
Go
// Package payment contains the payment module contribution to the application
|
|
// catalog.
|
|
package payment
|
|
|
|
import (
|
|
datapayment "kra/internal/data/payment"
|
|
datasystem "kra/internal/data/system"
|
|
"kra/internal/modules/surface"
|
|
"kra/pkg/database/migration"
|
|
"kra/pkg/module"
|
|
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// Definition declares the payment-owned schema and administration surface.
|
|
func Definition() module.Definition {
|
|
menus := []module.Menu{
|
|
{Name: "paymentOrders", Path: "paymentOrders", ParentName: "extensions", Component: "view/systemTools/payment/orders.vue", Title: "支付订单", Icon: "wallet", Sort: 6},
|
|
{Name: "paymentConfig", Path: "paymentConfig", ParentName: "extensions", Component: "view/systemTools/payment/config.vue", Title: "支付配置", Icon: "credit-card", Sort: 7},
|
|
}
|
|
adminSurface := module.Surface{
|
|
Menus: menus,
|
|
APIs: surface.APIsForPrefix("/payment", 12),
|
|
}
|
|
// Keep the contents of shipped migrations immutable. Future payment routes
|
|
// belong in a new migration instead of silently changing this snapshot.
|
|
upgradeSurface := module.Surface{Menus: menus, APIs: []module.API{
|
|
{Path: "/payment/orders", Method: "GET", Group: "支付", Description: "分页查询支付订单"},
|
|
{Path: "/payment/orders/summary", Method: "GET", Group: "支付", Description: "汇总支付订单运营指标"},
|
|
{Path: "/payment/orders/:provider/:tradeNo", Method: "GET", Group: "支付", Description: "按路径查询支付订单"},
|
|
{Path: "/payment/orders/:provider/:tradeNo/events", Method: "GET", Group: "支付", Description: "查询支付订单事件流水"},
|
|
{Path: "/payment/create", Method: "POST", Group: "支付", Description: "创建支付订单"},
|
|
{Path: "/payment/fulfill", Method: "POST", Group: "支付", Description: "重试支付订单发货"},
|
|
{Path: "/payment/order", Method: "POST", Group: "支付", Description: "查询支付订单"},
|
|
{Path: "/payment/orders/:provider/:tradeNo/fulfill", Method: "POST", Group: "支付", Description: "按路径重试支付订单发货"},
|
|
{Path: "/payment/orders/:provider/:tradeNo/refund", Method: "POST", Group: "支付", Description: "按路径申请支付订单退款"},
|
|
{Path: "/payment/providers/:provider/test", Method: "POST", Group: "支付", Description: "测试支付渠道配置与沙箱交易链路"},
|
|
{Path: "/payment/query", Method: "POST", Group: "支付", Description: "同步支付订单状态"},
|
|
{Path: "/payment/refund", Method: "POST", Group: "支付", Description: "申请支付订单退款"},
|
|
}}
|
|
orderReadAPIs := make([]module.API, 0, 4)
|
|
for _, api := range upgradeSurface.APIs {
|
|
if api.Method == "GET" && (api.Path == "/payment/orders" || api.Path == "/payment/orders/summary" || api.Path == "/payment/orders/:provider/:tradeNo" || api.Path == "/payment/orders/:provider/:tradeNo/events") {
|
|
orderReadAPIs = append(orderReadAPIs, api)
|
|
}
|
|
}
|
|
migrations := append(datapayment.Migrations(), migration.Step{ID: "202608290002_payment_admin_surface", Migrate: func(db *gorm.DB) error {
|
|
if err := datasystem.EnsureAdminSurface(db, upgradeSurface, 888); err != nil {
|
|
return err
|
|
}
|
|
if err := datasystem.InheritAPIPolicy(db, "/payment/orders", "GET", "/payment/orders/summary", "GET"); err != nil {
|
|
return err
|
|
}
|
|
return datasystem.InheritAPIPolicy(db, "/payment/orders/:provider/:tradeNo", "GET", "/payment/orders/:provider/:tradeNo/events", "GET")
|
|
}}, migration.Step{ID: "202608290003_payment_order_read_permissions", Migrate: func(db *gorm.DB) error {
|
|
return datasystem.GrantMenuAPIs(db, "paymentOrders", orderReadAPIs)
|
|
}})
|
|
return module.Definition{
|
|
Name: "payment",
|
|
Migrations: migrations,
|
|
Surface: adminSurface,
|
|
}
|
|
}
|