diff --git a/internal/services/virtualGame/service.go b/internal/services/virtualGame/service.go index 2bc4f9e..6f60fef 100644 --- a/internal/services/virtualGame/service.go +++ b/internal/services/virtualGame/service.go @@ -171,7 +171,7 @@ func (s *service) HandleCallback(ctx context.Context, callback *domain.PopOKCall } walletID := wallets[0].ID - amount := int64(callback.Amount * 100) // Convert to cents + amount := int64(callback.Amount) // Convert to cents transactionType := callback.Type switch transactionType { @@ -230,7 +230,7 @@ func (s *service) GetPlayerInfo(ctx context.Context, req *domain.PopOKPlayerInfo return &domain.PopOKPlayerInfoResponse{ Country: "ET", Currency: claims.Currency, - Balance: float64(wallets[0].Balance) / 100, // Convert cents to currency + Balance: float64(wallets[0].Balance), // Convert cents to currency PlayerID: fmt.Sprintf("%d", claims.UserID), }, nil } @@ -243,7 +243,7 @@ func (s *service) ProcessBet(ctx context.Context, req *domain.PopOKBetRequest) ( } // Convert amount to cents (assuming wallet uses cents) - amountCents := int64(req.Amount * 100) + amountCents := int64(req.Amount) // Deduct from wallet @@ -278,7 +278,7 @@ func (s *service) ProcessBet(ctx context.Context, req *domain.PopOKBetRequest) ( return &domain.PopOKBetResponse{ TransactionID: req.TransactionID, ExternalTrxID: fmt.Sprintf("%v", tx.ID), // Your internal transaction ID - Balance: float64(userWallets[0].Balance) / 100, + Balance: float64(userWallets[0].Balance), }, nil } @@ -304,7 +304,7 @@ func (s *service) ProcessWin(ctx context.Context, req *domain.PopOKWinRequest) ( wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID) balance := 0.0 if len(wallets) > 0 { - balance = float64(wallets[0].Balance) / 100 + balance = float64(wallets[0].Balance) } return &domain.PopOKWinResponse{ TransactionID: req.TransactionID, @@ -314,7 +314,7 @@ func (s *service) ProcessWin(ctx context.Context, req *domain.PopOKWinRequest) ( } // 3. Convert amount to cents - amountCents := int64(req.Amount * 100) + amountCents := int64(req.Amount) // 4. Credit to wallet @@ -374,7 +374,7 @@ func (s *service) ProcessTournamentWin(ctx context.Context, req *domain.PopOKWin wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID) balance := 0.0 if len(wallets) > 0 { - balance = float64(wallets[0].Balance) / 100 + balance = float64(wallets[0].Balance) } return &domain.PopOKWinResponse{ TransactionID: req.TransactionID, @@ -384,7 +384,7 @@ func (s *service) ProcessTournamentWin(ctx context.Context, req *domain.PopOKWin } // 3. Convert amount to cents - amountCents := int64(req.Amount * 100) + amountCents := int64(req.Amount) // 4. Credit user wallet if _, err := s.walletSvc.AddToWallet(ctx, claims.UserID, domain.Currency(amountCents), domain.ValidInt64{}, domain.TRANSFER_DIRECT, domain.PaymentDetails{}); err != nil { @@ -417,7 +417,7 @@ func (s *service) ProcessTournamentWin(ctx context.Context, req *domain.PopOKWin return &domain.PopOKWinResponse{ TransactionID: req.TransactionID, ExternalTrxID: fmt.Sprintf("%v", tx.ID), - Balance: float64(wallets[0].Balance) / 100, + Balance: float64(wallets[0].Balance), }, nil } @@ -438,7 +438,7 @@ func (s *service) ProcessPromoWin(ctx context.Context, req *domain.PopOKWinReque wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID) balance := 0.0 if len(wallets) > 0 { - balance = float64(wallets[0].Balance) / 100 + balance = float64(wallets[0].Balance) } return &domain.PopOKWinResponse{ TransactionID: req.TransactionID, @@ -447,7 +447,7 @@ func (s *service) ProcessPromoWin(ctx context.Context, req *domain.PopOKWinReque }, nil } - amountCents := int64(req.Amount * 100) + amountCents := int64(req.Amount) if _, err := s.walletSvc.AddToWallet(ctx, claims.UserID, domain.Currency(amountCents), domain.ValidInt64{}, domain.TRANSFER_DIRECT, domain.PaymentDetails{}); err != nil { s.logger.Error("Failed to credit wallet for promo", "userID", claims.UserID, "error", err) @@ -477,7 +477,7 @@ func (s *service) ProcessPromoWin(ctx context.Context, req *domain.PopOKWinReque return &domain.PopOKWinResponse{ TransactionID: req.TransactionID, ExternalTrxID: fmt.Sprintf("%v", tx.ID), - Balance: float64(wallets[0].Balance) / 100, + Balance: float64(wallets[0].Balance), }, nil } @@ -543,7 +543,7 @@ func (s *service) ProcessCancel(ctx context.Context, req *domain.PopOKCancelRequ wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID) balance := 0.0 if len(wallets) > 0 { - balance = float64(wallets[0].Balance) / 100 + balance = float64(wallets[0].Balance) } return &domain.PopOKCancelResponse{ TransactionID: req.TransactionID, @@ -602,7 +602,7 @@ func (s *service) ProcessCancel(ctx context.Context, req *domain.PopOKCancelRequ return &domain.PopOKCancelResponse{ TransactionID: req.TransactionID, ExternalTrxID: fmt.Sprintf("%v", cancelTx.ID), - Balance: float64(userWallets[0].Balance) / 100, + Balance: float64(userWallets[0].Balance), }, nil } @@ -651,32 +651,46 @@ func (s *service) GetGameCounts(ctx context.Context, filter domain.ReportFilter) func (s *service) ListGames(ctx context.Context, currency string) ([]domain.PopOKGame, error) { now := time.Now().Format("02-01-2006 15:04:05") // dd-mm-yyyy hh:mm:ss - // Calculate hash: sha256(privateKey + time) - rawHash := s.config.PopOK.SecretKey + now - hash := fmt.Sprintf("%x", sha256.Sum256([]byte(rawHash))) - - // Construct request payload - payload := map[string]interface{}{ + // Step 1: Construct payload without the hash + data := map[string]interface{}{ "action": "gameList", "platform": s.config.PopOK.Platform, "partnerId": s.config.PopOK.ClientID, "currency": currency, "time": now, - "hash": hash, } - bodyBytes, err := json.Marshal(payload) + // Step 2: Marshal data to JSON for hash calculation + // dataBytes, err := json.Marshal(data) + // if err != nil { + // s.logger.Error("Failed to marshal data for hash generation", "error", err) + // return nil, err + // } + + // Step 3: Calculate hash: sha256(privateKey + time + json(data)) + rawHash := s.config.PopOK.SecretKey + now + hash := fmt.Sprintf("%x", sha256.Sum256([]byte(rawHash))) + + // Step 4: Add the hash to the payload + data["hash"] = hash + + // Step 5: Marshal full payload with hash + bodyBytes, err := json.Marshal(data) if err != nil { - s.logger.Error("Failed to marshal game list request", "error", err) + s.logger.Error("Failed to marshal final payload with hash", "error", err) return nil, err } + // Step 6: Create and send the request req, err := http.NewRequestWithContext(ctx, "POST", s.config.PopOK.BaseURL+"/serviceApi.php", bytes.NewReader(bodyBytes)) if err != nil { s.logger.Error("Failed to create game list request", "error", err) return nil, err } req.Header.Set("Content-Type", "application/json") + req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36") + req.Header.Set("Accept", "application/json, text/plain, */*") + req.Header.Set("Accept-Language", "en-US,en;q=0.9") client := &http.Client{Timeout: 10 * time.Second} resp, err := client.Do(req) @@ -686,6 +700,7 @@ func (s *service) ListGames(ctx context.Context, currency string) ([]domain.PopO } defer resp.Body.Close() + // Step 7: Handle response if resp.StatusCode != http.StatusOK { b, _ := io.ReadAll(resp.Body) return nil, fmt.Errorf("PopOK game list failed with status %d: %s", resp.StatusCode, string(b))