Example #1
0
        public void Validate(Guid withdrawalId)
        {
            var withdrawal = _paymentRepository
                             .OfflineWithdraws
                             .Include(x => x.PlayerBankAccount)
                             .Single(x => x.Id == withdrawalId);

            var bankAccount =
                _paymentRepository.PlayerBankAccounts
                .Include(x => x.Player)
                .Include(x => x.Player.Brand)
                .FirstOrDefault(x => x.Id == withdrawal.PlayerBankAccount.Id);

            _configuration = _avcConfigurationQueries
                             .GetAutoVerificationCheckConfigurations()
                             .SingleOrDefault(
                x =>
                x.BrandId == bankAccount.Player.BrandId &&
                x.VipLevels.Select(o => o.Id).Contains(bankAccount.Player.VipLevelId) &&
                x.Currency == bankAccount.Player.CurrencyCode &&
                x.Status == AutoVerificationCheckStatus.Active);

            var eventCreated = DateTimeOffset.Now.ToBrandOffset(bankAccount.Player.Brand.TimezoneId);

            if (_configuration == null)
            {
                withdrawal.AutoVerificationCheckDate = DateTimeOffset.UtcNow;
                withdrawal.Status = WithdrawalStatus.Verified;

                _eventBus.Publish(new WithdrawalVerified(
                                      withdrawalId,
                                      withdrawal.Amount,
                                      eventCreated,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      WithdrawalStatus.Verified,
                                      "Automatic auto verification check succeeded!",
                                      withdrawal.TransactionNumber,
                                      "System")
                {
                    EventCreated = eventCreated
                });

                _paymentRepository.SaveChanges();
                return;
            }

            withdrawal.AutoVerificationCheckDate = DateTimeOffset.UtcNow;

            if (_configuration.HasWithdrawalExemption && PlayerIsAllowedForExemption(bankAccount.Player, withdrawal.AutoVerificationCheckDate))
            {
                ApplyExemptionForThatWithdrawalRequest(bankAccount.Player, withdrawalId, withdrawal);
                return;
            }

            base.Validate(_configuration, withdrawalId);

            ValidateTotalDepositAmount(withdrawalId, bankAccount.Player.Id);
            ValidatePlayersWinningsRules(withdrawalId, bankAccount.Player.Id);
            ValidatePaymentLevel(withdrawalId, bankAccount.Player);
            ValidateHasCompleteDocuments(withdrawalId, bankAccount.Player, bankAccount.Player.BrandId);
            ValidateHasOfflineWithdrawalExeption(withdrawalId, bankAccount.Player, withdrawal.AutoVerificationCheckDate);

            if (_withdrawalVerificationLogsQueues.HasFailedCriteras(withdrawalId, VerificationType.AutoVerification))
            {
                withdrawal.AutoVerificationCheckStatus = CommonVerificationStatus.Failed;
                withdrawal.Status = WithdrawalStatus.AutoVerificationFailed;

                eventCreated = DateTimeOffset.Now.ToBrandOffset(bankAccount.Player.Brand.TimezoneId);

                _eventBus.Publish(new WithdrawalUnverified(
                                      withdrawalId,
                                      withdrawal.Amount,
                                      eventCreated,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      WithdrawalStatus.Unverified,
                                      "Automatic auto verification check failed!",
                                      withdrawal.TransactionNumber,
                                      "System")
                {
                    EventCreated = eventCreated
                });
            }
            else
            {
                withdrawal.AutoVerificationCheckStatus = CommonVerificationStatus.Passed;
                withdrawal.Status = WithdrawalStatus.Verified;

                _eventBus.Publish(new WithdrawalVerified(
                                      withdrawalId,
                                      withdrawal.Amount,
                                      eventCreated,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      withdrawal.PlayerBankAccount.Player.Id,
                                      WithdrawalStatus.Verified,
                                      "Automatic auto verification check succeeded!",
                                      withdrawal.TransactionNumber,
                                      "System")
                {
                    EventCreated = eventCreated
                });
            }

            _paymentRepository.SaveChanges();
        }