refactor: migrate legacy API routes to /legacy prefix for backward compatibility
This commit is contained in:
@@ -7,12 +7,19 @@ import (
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// CreateTransaction 创建交易
|
||||
func (c *BaseCommController) CreateTransaction(ctx echo.Context) (err error) {
|
||||
// LegecyCreateTransaction 创建交易
|
||||
func (c *BaseCommController) LegecyCreateTransaction(ctx echo.Context) (err error) {
|
||||
req := new(request.CreateTransactionRequest)
|
||||
if err = ctx.Bind(req); err != nil {
|
||||
return c.FailJson(ctx, constant.ParamsMarshalErr)
|
||||
}
|
||||
// 兼容旧版本插件:如果未传递 token 和 currency,使用默认值
|
||||
if req.Token == "" {
|
||||
req.Token = "usdt"
|
||||
}
|
||||
if req.Currency == "" {
|
||||
req.Currency = "cny"
|
||||
}
|
||||
if err = c.ValidateStruct(ctx, req); err != nil {
|
||||
return c.FailJson(ctx, err)
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package comm
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/assimon/luuu/config"
|
||||
"github.com/assimon/luuu/model/response"
|
||||
"github.com/assimon/luuu/model/service"
|
||||
"github.com/labstack/echo/v4"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// CheckoutCounter 收银台
|
||||
func (c *BaseCommController) CheckoutCounter(ctx echo.Context) (err error) {
|
||||
// LegecyCheckoutCounter 收银台
|
||||
func (c *BaseCommController) LegecyCheckoutCounter(ctx echo.Context) (err error) {
|
||||
tradeId := ctx.Param("trade_id")
|
||||
resp, err := service.GetCheckoutCounterByTradeId(tradeId)
|
||||
if err != nil {
|
||||
@@ -21,11 +22,12 @@ func (c *BaseCommController) CheckoutCounter(ctx echo.Context) (err error) {
|
||||
if err != nil {
|
||||
return ctx.String(http.StatusOK, err.Error())
|
||||
}
|
||||
resp.Token = resp.ReceiveAddress // only for legacy checkout counter, token is the receive address
|
||||
return tmpl.Execute(ctx.Response(), resp)
|
||||
}
|
||||
|
||||
// CheckStatus 支付状态检测
|
||||
func (c *BaseCommController) CheckStatus(ctx echo.Context) (err error) {
|
||||
// LegecyCheckStatus 支付状态检测
|
||||
func (c *BaseCommController) LegecyCheckStatus(ctx echo.Context) (err error) {
|
||||
tradeId := ctx.Param("trade_id")
|
||||
order, err := service.GetOrderInfoByTradeId(tradeId)
|
||||
if err != nil {
|
||||
|
||||
@@ -2,15 +2,16 @@ package middleware
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/assimon/luuu/config"
|
||||
"github.com/assimon/luuu/util/constant"
|
||||
"github.com/assimon/luuu/util/json"
|
||||
"github.com/assimon/luuu/util/sign"
|
||||
"github.com/labstack/echo/v4"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
func CheckApiSign() echo.MiddlewareFunc {
|
||||
func LegecyCheckApiSign() echo.MiddlewareFunc {
|
||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(ctx echo.Context) error {
|
||||
params, err := ioutil.ReadAll(ctx.Request().Body)
|
||||
|
||||
+6
-6
@@ -14,15 +14,15 @@ func RegisterRoute(e *echo.Echo) {
|
||||
return c.String(http.StatusOK, "hello epusdt, https://github.com/GMwalletApp/epusdt")
|
||||
})
|
||||
// ==== 支付相关=====
|
||||
payRoute := e.Group("/pay")
|
||||
payRoute := e.Group("/legacy/pay")
|
||||
// 收银台
|
||||
payRoute.GET("/checkout-counter/:trade_id", comm.Ctrl.CheckoutCounter)
|
||||
payRoute.GET("/checkout-counter/:trade_id", comm.Ctrl.LegecyCheckoutCounter)
|
||||
// 状态检测
|
||||
payRoute.GET("/check-status/:trade_id", comm.Ctrl.CheckStatus)
|
||||
payRoute.GET("/check-status/:trade_id", comm.Ctrl.LegecyCheckStatus)
|
||||
|
||||
apiV1Route := e.Group("/api/v1")
|
||||
apiV1Route := e.Group("/legacy/api/v1")
|
||||
// ====订单相关====
|
||||
orderRoute := apiV1Route.Group("/order", middleware.CheckApiSign())
|
||||
orderRoute := apiV1Route.Group("/order", middleware.LegecyCheckApiSign())
|
||||
// 创建订单
|
||||
orderRoute.POST("/create-transaction", comm.Ctrl.CreateTransaction)
|
||||
orderRoute.POST("/create-transaction", comm.Ctrl.LegecyCreateTransaction)
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
url: "/pay/check-status/{{.TradeId}}",
|
||||
url: "/legacy/pay/check-status/{{.TradeId}}",
|
||||
timeout: 10000,
|
||||
success: function (response, status) {
|
||||
if (response.data.status == 2) {
|
||||
|
||||
Reference in New Issue
Block a user