2026-08-12 14:04:30 +03:00
|
|
|
package rudder
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/url"
|
2026-08-26 18:30:28 +03:00
|
|
|
"strconv"
|
2026-08-12 14:04:30 +03:00
|
|
|
|
|
|
|
|
"hub.rudder.build/rudder/rudder-go-sdk/models"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type WalletService struct {
|
|
|
|
|
transport *transport
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type AdjustWalletParameters struct {
|
2026-08-13 08:47:14 +03:00
|
|
|
IdempotencyKey string
|
2026-08-26 18:30:28 +03:00
|
|
|
Items []models.BatchAdjustPlayerWalletsItem
|
2026-08-12 14:04:30 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-26 18:30:28 +03:00
|
|
|
func (s *WalletService) Adjust(ctx context.Context, parameters AdjustWalletParameters) ([]models.WalletDetails, error) {
|
|
|
|
|
body := models.BatchAdjustPlayerWalletsRequest{
|
2026-08-13 08:47:14 +03:00
|
|
|
IdempotencyKey: parameters.IdempotencyKey,
|
2026-08-26 18:30:28 +03:00
|
|
|
Items: parameters.Items,
|
2026-08-12 14:04:30 +03:00
|
|
|
}
|
|
|
|
|
|
2026-08-26 18:30:28 +03:00
|
|
|
var response models.BatchAdjustPlayerWalletsResponse
|
|
|
|
|
if err := s.transport.do(ctx, http.MethodPost, "/players/wallet/adjust", nil, body, &response); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return response.Wallets, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type WalletHistoryParameters struct {
|
|
|
|
|
Currency *string
|
|
|
|
|
Limit int
|
|
|
|
|
Cursor *string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *WalletService) History(ctx context.Context, playerID string, parameters WalletHistoryParameters) (*models.GetWalletHistoryResponse, error) {
|
|
|
|
|
query := url.Values{}
|
|
|
|
|
if parameters.Currency != nil {
|
|
|
|
|
query.Set("currency", *parameters.Currency)
|
|
|
|
|
}
|
|
|
|
|
if parameters.Limit > 0 {
|
|
|
|
|
query.Set("limit", strconv.Itoa(parameters.Limit))
|
|
|
|
|
}
|
|
|
|
|
if parameters.Cursor != nil {
|
|
|
|
|
query.Set("cursor", *parameters.Cursor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var response models.GetWalletHistoryResponse
|
|
|
|
|
if err := s.transport.do(ctx, http.MethodGet, "/players/"+url.PathEscape(playerID)+"/wallet/history", query, nil, &response); err != nil {
|
2026-08-12 14:04:30 +03:00
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return &response, nil
|
|
|
|
|
}
|