player Info fix
This commit is contained in:
parent
68ac9f6a96
commit
5cd5d2f143
|
|
@ -52,7 +52,7 @@ func (s *service) GenerateGameLaunchURL(ctx context.Context, userID int64, gameI
|
||||||
sessionId := fmt.Sprintf("%d-%s-%d", userID, gameID, time.Now().UnixNano())
|
sessionId := fmt.Sprintf("%d-%s-%d", userID, gameID, time.Now().UnixNano())
|
||||||
token, err := jwtutil.CreatePopOKJwt(
|
token, err := jwtutil.CreatePopOKJwt(
|
||||||
userID,
|
userID,
|
||||||
user.PhoneNumber,
|
user.FirstName,
|
||||||
currency,
|
currency,
|
||||||
"en",
|
"en",
|
||||||
mode,
|
mode,
|
||||||
|
|
@ -166,6 +166,8 @@ func (s *service) HandleCallback(ctx context.Context, callback *domain.PopOKCall
|
||||||
|
|
||||||
func (s *service) GetPlayerInfo(ctx context.Context, req *domain.PopOKPlayerInfoRequest) (*domain.PopOKPlayerInfoResponse, error) {
|
func (s *service) GetPlayerInfo(ctx context.Context, req *domain.PopOKPlayerInfoRequest) (*domain.PopOKPlayerInfoResponse, error) {
|
||||||
claims, err := jwtutil.ParsePopOKJwt(req.ExternalToken, s.config.PopOK.SecretKey)
|
claims, err := jwtutil.ParsePopOKJwt(req.ExternalToken, s.config.PopOK.SecretKey)
|
||||||
|
fmt.Printf("\n\nClaims: %+v\n\n", claims)
|
||||||
|
fmt.Printf("\n\nExternal token: %+v\n\n", req.ExternalToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to parse JWT", "error", err)
|
s.logger.Error("Failed to parse JWT", "error", err)
|
||||||
return nil, fmt.Errorf("invalid token")
|
return nil, fmt.Errorf("invalid token")
|
||||||
|
|
@ -232,10 +234,12 @@ func (s *service) ProcessBet(ctx context.Context, req *domain.PopOKBetRequest) (
|
||||||
func (s *service) ProcessWin(ctx context.Context, req *domain.PopOKWinRequest) (*domain.PopOKWinResponse, error) {
|
func (s *service) ProcessWin(ctx context.Context, req *domain.PopOKWinRequest) (*domain.PopOKWinResponse, error) {
|
||||||
// 1. Validate token and get user ID
|
// 1. Validate token and get user ID
|
||||||
claims, err := jwtutil.ParsePopOKJwt(req.ExternalToken, s.config.PopOK.SecretKey)
|
claims, err := jwtutil.ParsePopOKJwt(req.ExternalToken, s.config.PopOK.SecretKey)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// s.logger.Error("Invalid token in win request", "error", err)
|
s.logger.Error("Invalid token in win request", "error", err)
|
||||||
// return nil, fmt.Errorf("invalid token")
|
return nil, fmt.Errorf("invalid token")
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\n\nClaims: %+v\n\n", claims)
|
||||||
|
|
||||||
// 2. Check for duplicate transaction (idempotency)
|
// 2. Check for duplicate transaction (idempotency)
|
||||||
existingTx, err := s.repo.GetVirtualGameTransactionByExternalID(ctx, req.TransactionID)
|
existingTx, err := s.repo.GetVirtualGameTransactionByExternalID(ctx, req.TransactionID)
|
||||||
|
|
|
||||||
|
|
@ -94,7 +94,7 @@ func (h *Handler) HandlePlayerInfo(c *fiber.Ctx) error {
|
||||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.WriteJSON(c, fiber.StatusOK, "Player info retrieved", resp, nil)
|
return c.Status(fiber.StatusOK).JSON(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) HandleBet(c *fiber.Ctx) error {
|
func (h *Handler) HandleBet(c *fiber.Ctx) error {
|
||||||
|
|
|
||||||
|
|
@ -57,24 +57,20 @@ func CreateJwt(userId int64, Role domain.Role, CompanyID domain.ValidInt64, key
|
||||||
func CreatePopOKJwt(userID int64, username, currency, lang, mode, sessionID, key string, expiry time.Duration) (string, error) {
|
func CreatePopOKJwt(userID int64, username, currency, lang, mode, sessionID, key string, expiry time.Duration) (string, error) {
|
||||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, PopOKClaim{
|
token := jwt.NewWithClaims(jwt.SigningMethodHS256, PopOKClaim{
|
||||||
RegisteredClaims: jwt.RegisteredClaims{
|
RegisteredClaims: jwt.RegisteredClaims{
|
||||||
Issuer: "github.com/lafetz/snippitstash",
|
Issuer: "fortune-bet",
|
||||||
IssuedAt: jwt.NewNumericDate(time.Now()),
|
|
||||||
Audience: jwt.ClaimStrings{"popokgaming.com"},
|
Audience: jwt.ClaimStrings{"popokgaming.com"},
|
||||||
|
IssuedAt: jwt.NewNumericDate(time.Now()),
|
||||||
NotBefore: jwt.NewNumericDate(time.Now()),
|
NotBefore: jwt.NewNumericDate(time.Now()),
|
||||||
ExpiresAt: jwt.NewNumericDate(time.Now().Add(expiry)),
|
ExpiresAt: jwt.NewNumericDate(time.Now().Add(expiry)),
|
||||||
},
|
},
|
||||||
UserID: userID,
|
UserID: userID,
|
||||||
Username: username,
|
Username: username, // ✅ Must be a valid string
|
||||||
Currency: currency,
|
Currency: currency,
|
||||||
Lang: lang,
|
Lang: lang,
|
||||||
Mode: mode,
|
Mode: mode,
|
||||||
SessionID: sessionID,
|
SessionID: sessionID,
|
||||||
})
|
})
|
||||||
jwtToken, err := token.SignedString([]byte(key))
|
return token.SignedString([]byte(key))
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return jwtToken, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func ParseJwt(jwtToken string, key string) (*UserClaim, error) {
|
func ParseJwt(jwtToken string, key string) (*UserClaim, error) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user