Add user and state to payment pages.

This commit is contained in:
Yang Luo
2022-03-12 20:03:48 +08:00
parent 37a26e2a91
commit c906f1e5d2
6 changed files with 70 additions and 11 deletions

View File

@ -16,6 +16,7 @@ package controllers
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego/utils/pagination"
"github.com/casdoor/casdoor/object"
@ -127,7 +128,19 @@ func (c *ApiController) BuyProduct() {
providerId := c.Input().Get("providerId")
host := c.Ctx.Request.Host
payUrl, err := object.BuyProduct(id, providerId, host)
userId := c.GetSessionUsername()
if userId == "" {
c.ResponseError("Please login first")
return
}
user := object.GetUser(userId)
if user == nil {
c.ResponseError(fmt.Sprintf("The user: %s doesn't exist", userId))
return
}
payUrl, err := object.BuyProduct(id, providerId, user, host)
if err != nil {
c.ResponseError(err.Error())
return