Skip to content

Commit ff68279

Browse files
authored
Merge pull request #59 from GMWalletApp/dev
feat(pay): switch checkout counter to SPA redirect + JSON API
2 parents 785a162 + 9c533a7 commit ff68279

199 files changed

Lines changed: 242 additions & 1810 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/controller/comm/pay_controller.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,35 @@
11
package comm
22

33
import (
4-
"html/template"
54
"net/http"
6-
"path/filepath"
75

8-
"github.com/GMWalletApp/epusdt/config"
96
"github.com/GMWalletApp/epusdt/model/response"
107
"github.com/GMWalletApp/epusdt/model/service"
118
"github.com/labstack/echo/v4"
129
)
1310

1411
// CheckoutCounter 收银台
1512
// @Summary Checkout counter page
16-
// @Description Render the payment checkout counter HTML page for a given trade
13+
// @Description Render the payment checkout counter JSON response for a given trade
1714
// @Tags Payment
18-
// @Produce html
15+
// @Produce json
1916
// @Param trade_id path string true "Trade ID"
20-
// @Success 200 {string} string "HTML page"
21-
// @Router /pay/checkout-counter/{trade_id} [get]
17+
// @Success 200 {object} response.CheckoutCounterResponse
18+
// @Router /pay/checkout-counter-resp/{trade_id} [get]
2219
func (c *BaseCommController) CheckoutCounter(ctx echo.Context) (err error) {
2320
tradeId := ctx.Param("trade_id")
2421
resp, err := service.GetCheckoutCounterByTradeId(tradeId)
2522
if err != nil {
2623
if err == service.ErrOrder {
2724
// Unknown trade id: render the page with empty payload
2825
// (client side shows a friendly "order not found" screen).
29-
tmpl, tmplErr := template.ParseFiles(filepath.Join(config.StaticFilePath, "index.html"))
30-
if tmplErr != nil {
31-
return ctx.String(http.StatusInternalServerError, tmplErr.Error())
32-
}
33-
ctx.Response().Status = http.StatusNotFound
3426
emptyResp := response.CheckoutCounterResponse{}
35-
return tmpl.Execute(ctx.Response(), emptyResp)
27+
return c.SucJson(ctx, emptyResp)
3628
}
3729
return ctx.String(http.StatusInternalServerError, err.Error())
3830
}
39-
tmpl, err := template.ParseFiles(filepath.Join(config.StaticFilePath, "index.html"))
40-
if err != nil {
41-
return ctx.String(http.StatusInternalServerError, err.Error())
42-
}
4331

44-
return tmpl.Execute(ctx.Response(), resp)
32+
return c.SucJson(ctx, resp)
4533
}
4634

4735
// CheckStatus 支付状态检测

src/main.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ import (
1212
"github.com/gookit/color"
1313
)
1414

15-
//go:embed all:static
16-
var staticDir embed.FS
17-
1815
//go:embed all:www
1916
var wwwDir embed.FS
2017

@@ -92,12 +89,6 @@ func releaseStatic(fs embed.FS, target string) (string, error) {
9289
}
9390

9491
func main() {
95-
staticPath, err := releaseStatic(staticDir, "static")
96-
if err != nil {
97-
panic(err)
98-
}
99-
fmt.Println("static released to:", staticPath)
100-
10192
wwwwPath, err := releaseStatic(wwwDir, "www")
10293
if err != nil {
10394
panic(err)

src/route/router.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ func RegisterRoute(e *echo.Echo) {
2727
})
2828

2929
payRoute := e.Group("/pay")
30-
payRoute.GET("/checkout-counter/:trade_id", comm.Ctrl.CheckoutCounter)
30+
payRoute.GET("/checkout-counter/:trade_id", func(ctx echo.Context) error {
31+
tradeId := ctx.Param("trade_id")
32+
33+
targetURL := fmt.Sprintf("/cashier/%s", tradeId)
34+
35+
return ctx.Redirect(http.StatusMovedPermanently, targetURL)
36+
})
37+
38+
payRoute.GET("/checkout-counter-resp/:trade_id", comm.Ctrl.CheckoutCounter)
3139
payRoute.GET("/check-status/:trade_id", comm.Ctrl.CheckStatus)
3240
payRoute.POST("/switch-network", comm.Ctrl.SwitchNetwork)
3341

0 commit comments

Comments
 (0)