Skip to main content

Generated from package comments and exported declarations. Edit the Go source, not this file.

adminadjustments

import "codeberg.org/hemanta212/playgo/api/adminadjustments"

Package adminadjustments defines the public contract for super-admin wallet corrections.

Corrections follow a deliberate two-step shape: preview, then execute. The preview computes the exact balance effects and any blockers, so a human sees the consequences before committing. The execute call then sends back the expected balances along with an idempotency key.

Those expected balances are what make the operation safe. If anything changed between preview and execute, the command fails instead of acting on a stale picture. A rejection here is the guard working, not an obstacle to route around.

Implementations preserve accounting invariants across ledger debits, reward clawbacks, optional off-app deposit reversal metadata, and immutable audit records. A deposit reversal must match the source payment exactly, because an approximate reversal is just a second discrepancy.

Variables​

var (
ErrInvalidRequest = errors.New("admin adjustments: invalid request")
ErrNotFound = errors.New("admin adjustments: player or source payment not found")
ErrInsufficientBalance = errors.New("admin adjustments: insufficient balance")
ErrBalanceChanged = errors.New("admin adjustments: balance changed since preview")
ErrSourceMismatch = errors.New("admin adjustments: items do not exactly reverse the source deposit")
ErrConflict = errors.New("admin adjustments: conflict")
)

Reasons is why an admin takes money or freeplay away from a player: each code and the phrase its audit text starts with.

var Reasons = reasoncode.Vocabulary{
"credited_by_mistake": "Credited by mistake",
"duplicate_payment": "Duplicate payment",
"deposit_reversed": "Deposit reversed or charged back",
"promotion_abuse": "Promotion abuse",
"test_cleanup": "Test cleanup",
"player_request": "Player request",
"other": "Other",
}

type Adjustment​

type Adjustment struct {
ID uuid.UUID `json:"id"`
PlayerID uuid.UUID `json:"player_id"`
ActorID uuid.UUID `json:"actor_id"`
SourcePaymentID *uuid.UUID `json:"source_payment_id,omitempty"`
Reference string `json:"reference"`
Reason string `json:"reason"`
CurrencyCode string `json:"currency_code"`
LedgerTransactionID *uuid.UUID `json:"ledger_transaction_id,omitempty"`
RewardEventID *uuid.UUID `json:"reward_event_id,omitempty"`
PaymentReversed bool `json:"payment_reversed"`
Items []Item `json:"items"`
CreatedAt time.Time `json:"created_at"`
Replayed bool `json:"replayed"`
}

type Blocker​

type Blocker struct {
Code string `json:"code"`
Message string `json:"message"`
Resource *Resource `json:"resource,omitempty"`
}

type ExecuteCommand​

type ExecuteCommand struct {
ActorID uuid.UUID
PlayerID uuid.UUID
EntireWallet bool `json:",omitempty"`
SourcePaymentID *uuid.UUID
Reference string
// ReasonCode comes from Reasons; Note is optional except for other.
ReasonCode string
Note string
// Reason is the audit text the service composes from ReasonCode and
// Note; any caller-supplied value is replaced.
Reason string `json:"-"`
Items []ItemInput
IdempotencyKey string
}

type Item​

type Item struct {
Resource Resource `json:"resource"`
Unit Unit `json:"unit"`
Amount int64 `json:"amount"`
BalanceBefore int64 `json:"balance_before"`
BalanceAfter int64 `json:"balance_after"`
Available bool `json:"available"`
}

type ItemInput​

type ItemInput struct {
Resource Resource
Amount int64
ExpectedBalance int64
}

type Preview​

type Preview struct {
PlayerID uuid.UUID `json:"player_id"`
SourcePaymentID *uuid.UUID `json:"source_payment_id,omitempty"`
SourceReference *string `json:"source_reference,omitempty"`
Items []Item `json:"items"`
Blockers []Blocker `json:"blockers"`
Executable bool `json:"executable"`
ExactDepositReversal bool `json:"exact_deposit_reversal"`
}

type PreviewCommand​

type PreviewCommand struct {
ActorID uuid.UUID
PlayerID uuid.UUID
EntireWallet bool `json:",omitempty"`
SourcePaymentID *uuid.UUID
Items []ItemInput
}

type Resource​

type Resource string
const (
ResourceCash Resource = "cash"
ResourceWithdrawableCash Resource = "withdrawable_cash"
ResourceFreeplay Resource = "freeplay"
ResourceXP Resource = "xp"
ResourceDiamonds Resource = "diamonds"
ResourceSpinTokens Resource = "spin_tokens"
)

type Service​

type Service interface {
Preview(context.Context, PreviewCommand) (Preview, error)
Execute(context.Context, ExecuteCommand) (Adjustment, error)
}

type Unit​

type Unit string
const (
UnitCents Unit = "cents"
UnitPoints Unit = "points"
UnitTokens Unit = "tokens"
)

Generated by gomarkdoc