PaymentCenter/app/http/controllers/front/pay_page.go

68 lines
1.8 KiB
Go

package front
import (
"PaymentCenter/app/http/controllers"
"PaymentCenter/app/http/entities/front"
"PaymentCenter/app/models/paychannelmodel"
"PaymentCenter/app/services"
"PaymentCenter/app/services/thirdpay"
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
"net/http"
"strconv"
)
// 预支付接口V2, 返回收银台页面
func PayUrlV2(c *gin.Context) {
var res front.ApiResponse
req := controllers.GetRequest(c).(*front.PayReqsV2)
appCheckInfo := controllers.GetAppCheckInfo(c).(*services.AppCheck)
result, code := services.NewPayUrl(*req).
WithApp(appCheckInfo).
WithClientIp(c.ClientIP()).
PayUrlV2Service()
if result.Order != nil {
res.Order = thirdpay.NewOrdersResp(result.Order)
res.Url = result.Url
}
controllers.ApiRes(c, res, code)
return
}
// V2 下单接口
// 收银台页面
func PayPage(c *gin.Context) {
c.HTML(http.StatusOK, "payPage.html", gin.H{
//"host": config.GetConf().PayService.Host + common.PayPageChannelList,
})
}
// 收银台获取支付渠道列表
func PayChannelList(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*front.PayChannelListRequest)
req.UserAgent = c.Request.UserAgent()
data, code := services.PayPageChannelList(*req)
result := []front.PayChannelListResponse{}
linq.From(data).SelectT(func(payChannel paychannelmodel.PayChannel) front.PayChannelListResponse {
return front.PayChannelListResponse{
ChannelType: payChannel.ChannelType,
PayName: payChannel.PayName,
PayChannelId: strconv.Itoa(int(payChannel.Id)),
}
}).ToSlice(&result)
controllers.HandCodeRes(c, result, code)
}
// 获取付款链接
func GetPayLink(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*front.GetPayLinkRequest)
result, code := services.GetPayLinkService(*req)
controllers.HandCodeRes(c, result, code)
}