示例#1
0
        public Guid ApplyForBonus(DepositBonusApplication model)
        {
            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var validationResult = _bonusQueries.GetValidationResult(model);
                if (validationResult.IsValid == false)
                {
                    throw new RegoException(validationResult.Errors.First().ErrorMessage);
                }

                var player           = _repository.GetLockedPlayer(model.PlayerId);
                var redemptionParams = new RedemptionParams
                {
                    TransferAmount           = model.Amount,
                    TransferExternalId       = model.DepositId,
                    TransferWalletTemplateId = player.Data.Brand.WalletTemplates.Single(wt => wt.IsMain).Id
                };
                var bonusId    = model.BonusId ?? _repository.GetLockedBonus(model.BonusCode).Data.Id;
                var redemption = RedeemBonus(model.PlayerId, bonusId, redemptionParams);
                redemption.Events.ForEach(_eventBus.Publish);
                scope.Complete();

                return(redemption.Data.Id);
            }
        }
示例#2
0
        private void HandlePositiveTurnover(GameActionEventBase @event, IBonusRepository repository, Wallet wallet, Transaction transaction)
        {
            var eventBus      = _container.Resolve <IEventBus>();
            var bonusCommands = _container.Resolve <BonusCommands>();

            var player = repository.GetLockedPlayer(@event.PlayerId);
            var redemptionsWithActiveRollover = player.GetRedemptionsWithActiveRollover(wallet.Data.Template.Id);
            var turnoverLeftToDistribute      = @event.Turnover;

            foreach (var redemption in redemptionsWithActiveRollover)
            {
                var handledAmount = redemption.FulfillRollover(turnoverLeftToDistribute, transaction);
                turnoverLeftToDistribute -= handledAmount;

                if (redemption.RolloverLeft == 0m)
                {
                    redemption.CompleteRollover();
                    bonusCommands.WageringFulfilled(redemption);
                }

                if (turnoverLeftToDistribute == 0m)
                {
                    if (redemption.WageringThresholdIsMet(wallet.TotalBalance) &&
                        // Check if rollover is still Active, 'cos it can become Completed several lines before
                        redemption.Data.RolloverState == RolloverStatus.Active)
                    {
                        redemption.ZeroOutRollover(transaction);
                        bonusCommands.WageringFulfilled(redemption);
                    }

                    redemption.Events.ForEach(eventBus.Publish);
                    break;
                }

                redemption.Events.ForEach(eventBus.Publish);
            }

            player.Data.AccumulatedWageringAmount += @event.Turnover;
            if (player.CompletedReferralRequirements())
            {
                var referrer = repository.GetLockedPlayer(player.Data.ReferredBy.Value);
                bonusCommands.ProcessFirstBonusRedemptionOfType(referrer, BonusType.ReferFriend);
                player.CompleteReferralRequirements();
            }
        }
        public FirstDepositApplicationValidator(IBonusRepository repository)
        {
            RuleFor(m => m)
            .Must(m => repository.Players.Any(p => p.Id == m.PlayerId))
            .WithMessage(ValidatorMessages.PlayerDoesNotExist)
            .DependentRules(rules =>
            {
                rules.RuleFor(m => m)
                .Must(m =>
                {
                    var bonus = repository.GetLockedBonusOrNull(m.BonusCode);

                    if (bonus != null)
                    {
                        if (bonus.Data.Template.Info.TemplateType != BonusType.FirstDeposit &&
                            bonus.Data.Template.Info.Mode != IssuanceMode.AutomaticWithCode &&
                            bonus.Data.Template.Info.Mode != IssuanceMode.ManualByPlayer)
                        {
                            return(false);
                        }

                        return(true);
                    }

                    return(false);
                })
                .WithMessage(ValidatorMessages.BonusDoesNotExist)
                .WithName("BonusCode")
                .DependentRules(dependentRules =>
                {
                    string error = null;
                    dependentRules.RuleFor(m => m)
                    .Must(m =>
                    {
                        var bonus  = repository.GetLockedBonusOrNull(m.BonusCode);
                        var player = repository.GetLockedPlayer(m.PlayerId);
                        var errors = bonus.QualifyFor(player, QualificationPhase.Redemption,
                                                      new RedemptionParams {
                            TransferAmount = m.DepositAmount
                        }).ToArray();
                        if (errors.Any())
                        {
                            error = errors.First();
                            return(false);
                        }

                        return(true);
                    })
                    .WithMessage("{0}", application => error)
                    .WithName("BonusCode");
                });
            });
        }
示例#4
0
        private void HandleNegativeTurnover(GameActionEventBase @event, IBonusRepository repository, Transaction transaction)
        {
            var eventBus = _container.Resolve <IEventBus>();

            var player           = repository.GetLockedPlayer(@event.PlayerId);
            var bonusRedemptions = player.GetRedemptionsWithActiveRollover()
                                   .Where(br => br.Data.Contributions.Select(c => c.Transaction.Id).Contains(transaction.RelatedTransactionId.Value));

            foreach (var bonusRedemption in bonusRedemptions)
            {
                bonusRedemption.FulfillRollover(@event.Turnover, transaction);
                bonusRedemption.Events.ForEach(eventBus.Publish);
            }
        }
示例#5
0
        internal Data.Bonus[] GetQualifiedBonuses(Guid playerId, BonusType type, RedemptionParams redemptionParams = null)
        {
            var player = _repository.GetLockedPlayer(playerId);

            return(GetQualifiedBonuses(player, type, redemptionParams));
        }