コード例 #1
0
        public Transaction AdjustBalances(AdjustmentParams adjustment)
        {
            Data.Main  += adjustment.MainBalanceAdjustment;
            Data.Bonus += adjustment.BonusBalanceAdjustment;
            Data.NonTransferableBonus += adjustment.NonTransferableBalanceAdjustment;

            if (Data.Bonus < 0 || Data.NonTransferableBonus < 0)
            {
                throw new RegoException("Insufficient funds");
            }

            var transaction = new Transaction(Data)
            {
                TotalAmount           = adjustment.MainBalanceAdjustment + adjustment.BonusBalanceAdjustment + adjustment.NonTransferableBalanceAdjustment,
                Type                  = GetTransactionType(adjustment.Reason),
                MainBalanceAmount     = adjustment.MainBalanceAdjustment,
                BonusBalanceAmount    = adjustment.BonusBalanceAdjustment,
                NonTransferableAmount = adjustment.NonTransferableBalanceAdjustment,
                RelatedTransactionId  = adjustment.RelatedTransactionId
            };

            Data.Transactions.Add(transaction);
            AddBonusWalletBalanceChangedEvent(transaction);

            return(transaction);
        }
コード例 #2
0
        public Transaction Cancel()
        {
            var wallet      = new Wallet(Wallet);
            var mainBalance = Wallet.Main;
            var adjustment  = new AdjustmentParams(AdjustmentReason.BonusCancelled);

            var transactionsDuringRollover = GetTransactionsDuringRollover();

            var betPlacedDuringRollover = transactionsDuringRollover
                                          .Where(tr => tr.Type == TransactionType.BetPlaced)
                                          .ToList();

            var realMoneyContribution        = Math.Abs(betPlacedDuringRollover.Sum(tr => tr.MainBalanceAmount));
            var betPlacedTotalDuringRollover = betPlacedDuringRollover.Sum(tr => tr.TotalAmount);

            var betWonTotalDuringRollover = transactionsDuringRollover
                                            .Where(tr => tr.Type == TransactionType.BetWon)
                                            .Sum(tr => tr.TotalAmount);

            var netWin = betWonTotalDuringRollover - betPlacedTotalDuringRollover;

            //only net losses should be adjusted
            if (netWin > 0)
            {
                netWin = 0m;
            }
            var mainBalanceAdjustment = realMoneyContribution + netWin;

            if (mainBalanceAdjustment > 0)
            {
                mainBalance += mainBalanceAdjustment;
                adjustment.MainBalanceAdjustment += mainBalanceAdjustment;
            }

            var bonusBalanceAdjustment = betWonTotalDuringRollover + Data.Amount;

            if (bonusBalanceAdjustment > 0)
            {
                var amountFromBonus = Math.Min(wallet.Data.Bonus, bonusBalanceAdjustment);
                adjustment.BonusBalanceAdjustment -= amountFromBonus;

                var amountFromNonWithdrawable = Math.Min(wallet.Data.NonTransferableBonus, bonusBalanceAdjustment - amountFromBonus);
                adjustment.NonTransferableBalanceAdjustment -= amountFromNonWithdrawable;

                var amountFromMain = Math.Min(mainBalance, bonusBalanceAdjustment - amountFromBonus - amountFromNonWithdrawable);
                adjustment.MainBalanceAdjustment -= amountFromMain;
            }

            Data.Contributions.Add(new RolloverContribution
            {
                Contribution = RolloverLeft,
                Type         = ContributionType.Cancellation
            });
            Data.ActivationState = ActivationStatus.Canceled;
            Data.RolloverState   = RolloverStatus.None;

            RevertRedemptionImplactOnStatistics();
            Data.UpdatedOn = SystemTime.Now.ToBrandOffset(Data.Bonus.Template.Info.Brand.TimezoneId);

            Events.Add(new RedemptionCanceled
            {
                AggregateId               = Data.Id,
                MainBalanceAdjustment     = adjustment.MainBalanceAdjustment,
                BonusBalanceAdjustment    = adjustment.BonusBalanceAdjustment,
                NonTransferableAdjustment = adjustment.NonTransferableBalanceAdjustment,
                UnlockedAmount            = Data.LockedAmount,
                CurrencyCode              = Data.Player.CurrencyCode
            });

            var transaction = wallet.AdjustBalances(adjustment);

            Events.AddRange(wallet.Events);
            IssueUnlock();

            return(transaction);
        }