popok game list browser-like header fix
This commit is contained in:
parent
95499cea7a
commit
7b728abac6
|
|
@ -171,7 +171,7 @@ func (s *service) HandleCallback(ctx context.Context, callback *domain.PopOKCall
|
||||||
}
|
}
|
||||||
|
|
||||||
walletID := wallets[0].ID
|
walletID := wallets[0].ID
|
||||||
amount := int64(callback.Amount * 100) // Convert to cents
|
amount := int64(callback.Amount) // Convert to cents
|
||||||
transactionType := callback.Type
|
transactionType := callback.Type
|
||||||
|
|
||||||
switch transactionType {
|
switch transactionType {
|
||||||
|
|
@ -230,7 +230,7 @@ func (s *service) GetPlayerInfo(ctx context.Context, req *domain.PopOKPlayerInfo
|
||||||
return &domain.PopOKPlayerInfoResponse{
|
return &domain.PopOKPlayerInfoResponse{
|
||||||
Country: "ET",
|
Country: "ET",
|
||||||
Currency: claims.Currency,
|
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),
|
PlayerID: fmt.Sprintf("%d", claims.UserID),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
@ -243,7 +243,7 @@ func (s *service) ProcessBet(ctx context.Context, req *domain.PopOKBetRequest) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert amount to cents (assuming wallet uses cents)
|
// Convert amount to cents (assuming wallet uses cents)
|
||||||
amountCents := int64(req.Amount * 100)
|
amountCents := int64(req.Amount)
|
||||||
|
|
||||||
// Deduct from wallet
|
// Deduct from wallet
|
||||||
|
|
||||||
|
|
@ -278,7 +278,7 @@ func (s *service) ProcessBet(ctx context.Context, req *domain.PopOKBetRequest) (
|
||||||
return &domain.PopOKBetResponse{
|
return &domain.PopOKBetResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
ExternalTrxID: fmt.Sprintf("%v", tx.ID), // Your internal transaction ID
|
ExternalTrxID: fmt.Sprintf("%v", tx.ID), // Your internal transaction ID
|
||||||
Balance: float64(userWallets[0].Balance) / 100,
|
Balance: float64(userWallets[0].Balance),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -304,7 +304,7 @@ func (s *service) ProcessWin(ctx context.Context, req *domain.PopOKWinRequest) (
|
||||||
wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID)
|
wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID)
|
||||||
balance := 0.0
|
balance := 0.0
|
||||||
if len(wallets) > 0 {
|
if len(wallets) > 0 {
|
||||||
balance = float64(wallets[0].Balance) / 100
|
balance = float64(wallets[0].Balance)
|
||||||
}
|
}
|
||||||
return &domain.PopOKWinResponse{
|
return &domain.PopOKWinResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
|
|
@ -314,7 +314,7 @@ func (s *service) ProcessWin(ctx context.Context, req *domain.PopOKWinRequest) (
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Convert amount to cents
|
// 3. Convert amount to cents
|
||||||
amountCents := int64(req.Amount * 100)
|
amountCents := int64(req.Amount)
|
||||||
|
|
||||||
// 4. Credit to wallet
|
// 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)
|
wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID)
|
||||||
balance := 0.0
|
balance := 0.0
|
||||||
if len(wallets) > 0 {
|
if len(wallets) > 0 {
|
||||||
balance = float64(wallets[0].Balance) / 100
|
balance = float64(wallets[0].Balance)
|
||||||
}
|
}
|
||||||
return &domain.PopOKWinResponse{
|
return &domain.PopOKWinResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
|
|
@ -384,7 +384,7 @@ func (s *service) ProcessTournamentWin(ctx context.Context, req *domain.PopOKWin
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. Convert amount to cents
|
// 3. Convert amount to cents
|
||||||
amountCents := int64(req.Amount * 100)
|
amountCents := int64(req.Amount)
|
||||||
|
|
||||||
// 4. Credit user wallet
|
// 4. Credit user wallet
|
||||||
if _, err := s.walletSvc.AddToWallet(ctx, claims.UserID, domain.Currency(amountCents), domain.ValidInt64{}, domain.TRANSFER_DIRECT, domain.PaymentDetails{}); err != nil {
|
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{
|
return &domain.PopOKWinResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
ExternalTrxID: fmt.Sprintf("%v", tx.ID),
|
ExternalTrxID: fmt.Sprintf("%v", tx.ID),
|
||||||
Balance: float64(wallets[0].Balance) / 100,
|
Balance: float64(wallets[0].Balance),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -438,7 +438,7 @@ func (s *service) ProcessPromoWin(ctx context.Context, req *domain.PopOKWinReque
|
||||||
wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID)
|
wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID)
|
||||||
balance := 0.0
|
balance := 0.0
|
||||||
if len(wallets) > 0 {
|
if len(wallets) > 0 {
|
||||||
balance = float64(wallets[0].Balance) / 100
|
balance = float64(wallets[0].Balance)
|
||||||
}
|
}
|
||||||
return &domain.PopOKWinResponse{
|
return &domain.PopOKWinResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
|
|
@ -447,7 +447,7 @@ func (s *service) ProcessPromoWin(ctx context.Context, req *domain.PopOKWinReque
|
||||||
}, nil
|
}, 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 {
|
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)
|
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{
|
return &domain.PopOKWinResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
ExternalTrxID: fmt.Sprintf("%v", tx.ID),
|
ExternalTrxID: fmt.Sprintf("%v", tx.ID),
|
||||||
Balance: float64(wallets[0].Balance) / 100,
|
Balance: float64(wallets[0].Balance),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -543,7 +543,7 @@ func (s *service) ProcessCancel(ctx context.Context, req *domain.PopOKCancelRequ
|
||||||
wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID)
|
wallets, _ := s.walletSvc.GetWalletsByUser(ctx, claims.UserID)
|
||||||
balance := 0.0
|
balance := 0.0
|
||||||
if len(wallets) > 0 {
|
if len(wallets) > 0 {
|
||||||
balance = float64(wallets[0].Balance) / 100
|
balance = float64(wallets[0].Balance)
|
||||||
}
|
}
|
||||||
return &domain.PopOKCancelResponse{
|
return &domain.PopOKCancelResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
|
|
@ -602,7 +602,7 @@ func (s *service) ProcessCancel(ctx context.Context, req *domain.PopOKCancelRequ
|
||||||
return &domain.PopOKCancelResponse{
|
return &domain.PopOKCancelResponse{
|
||||||
TransactionID: req.TransactionID,
|
TransactionID: req.TransactionID,
|
||||||
ExternalTrxID: fmt.Sprintf("%v", cancelTx.ID),
|
ExternalTrxID: fmt.Sprintf("%v", cancelTx.ID),
|
||||||
Balance: float64(userWallets[0].Balance) / 100,
|
Balance: float64(userWallets[0].Balance),
|
||||||
}, nil
|
}, 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) {
|
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
|
now := time.Now().Format("02-01-2006 15:04:05") // dd-mm-yyyy hh:mm:ss
|
||||||
|
|
||||||
// Calculate hash: sha256(privateKey + time)
|
// Step 1: Construct payload without the hash
|
||||||
rawHash := s.config.PopOK.SecretKey + now
|
data := map[string]interface{}{
|
||||||
hash := fmt.Sprintf("%x", sha256.Sum256([]byte(rawHash)))
|
|
||||||
|
|
||||||
// Construct request payload
|
|
||||||
payload := map[string]interface{}{
|
|
||||||
"action": "gameList",
|
"action": "gameList",
|
||||||
"platform": s.config.PopOK.Platform,
|
"platform": s.config.PopOK.Platform,
|
||||||
"partnerId": s.config.PopOK.ClientID,
|
"partnerId": s.config.PopOK.ClientID,
|
||||||
"currency": currency,
|
"currency": currency,
|
||||||
"time": now,
|
"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 {
|
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
|
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))
|
req, err := http.NewRequestWithContext(ctx, "POST", s.config.PopOK.BaseURL+"/serviceApi.php", bytes.NewReader(bodyBytes))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error("Failed to create game list request", "error", err)
|
s.logger.Error("Failed to create game list request", "error", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/json")
|
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}
|
client := &http.Client{Timeout: 10 * time.Second}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|
@ -686,6 +700,7 @@ func (s *service) ListGames(ctx context.Context, currency string) ([]domain.PopO
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
// Step 7: Handle response
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
b, _ := io.ReadAll(resp.Body)
|
b, _ := io.ReadAll(resp.Body)
|
||||||
return nil, fmt.Errorf("PopOK game list failed with status %d: %s", resp.StatusCode, string(b))
|
return nil, fmt.Errorf("PopOK game list failed with status %d: %s", resp.StatusCode, string(b))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user