Пример #1
0
        public void Can_log_withdrawal_created()
        {
            var @event = new WithdrawalCreated();

            _serviceBus.PublishMessage(@event);
            AssertAdminActivityLog(@event, AdminActivityLogCategory.Brand);
        }
Пример #2
0
        public void Consume(Interface.Commands.WithdrawRequestSubmit command)
        {
            var paymentRepository = _container.Resolve <IPaymentRepository>();
            var brandOperations   = _container.Resolve <IBrandOperations>();
            var serviceBus        = _container.Resolve <IServiceBus>();
            var withdrawalService = _container.Resolve <IWithdrawalService>();

            //move money out of Game service
            var player      = paymentRepository.Players.FirstOrDefault(x => x.Id == command.PlayerId);
            var gameBalance = brandOperations.FundOut(command.PlayerId, command.Amount, player.CurrencyCode, command.ReferenceCode);

            var bankAccount =
                paymentRepository.PlayerBankAccounts.Include(x => x.Player)
                .Include(x => x.Bank)
                .SingleOrDefault(x => x.Id == command.PlayerBankAccountId);

            bankAccount.EditLock = true;

            var withdrawal = new Data.OfflineWithdraw();

            withdrawal.Id = command.WithdrawId;
            withdrawal.PlayerBankAccount = bankAccount;
            withdrawal.TransactionNumber = command.ReferenceCode;
            withdrawal.Amount            = command.Amount;
            withdrawal.CreatedBy         = command.RequestedBy;
            withdrawal.Created           = command.Requested;
            withdrawal.Remarks           = command.Remarks;
            withdrawal.Status            = WithdrawalStatus.New;

            //lock money for withdrawal in our wallet
            var withdrawalLock = new WithdrawalLock
            {
                Id           = command.LockId,
                PlayerId     = command.PlayerId,
                WithdrawalId = command.WithdrawId,
                Amount       = command.Amount,
                Status       = Status.Active,
                LockedOn     = DateTimeOffset.Now.ToOffset(command.Requested.Offset),
                LockedBy     = command.RequestedBy
            };

            var eventCreated = DateTimeOffset.Now.ToOffset(command.Requested.Offset);

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                paymentRepository.OfflineWithdraws.Add(withdrawal);
                paymentRepository.WithdrawalLocks.Add(withdrawalLock);
                paymentRepository.SaveChanges();

                //raise WithdrawalCreated event
                var withdrawalCreatedEvent = new WithdrawalCreated(
                    command.WithdrawId,
                    command.Amount,
                    eventCreated,
                    command.PlayerId,
                    command.PlayerId,
                    WithdrawalStatus.New,
                    command.Remarks,
                    command.ReferenceCode,
                    command.ActorName)
                {
                    EventCreated   = eventCreated,
                    EventCreatedBy = command.ActorName,
                };

                serviceBus.PublishMessage(withdrawalCreatedEvent);

                scope.Complete();

                //TODO:AFTREGO-4131 implement behavior stated below:
                //there is still as small chance that some amount will be spent in Game subdomain
                //after we performed balance check and before money removed from Game balance
                //it means that we need to detect such situation by performing additional validations after WithdrawRequestSubmitted event
                //and automatically reject withdrawal request if some inconsistencies were found
            }
            withdrawalService.WithdrawalStateMachine(command.WithdrawId);
        }
Пример #3
0
 // Withdraw category
 public void Consume(WithdrawalCreated message)
 {
     _withdrawHandlers.Handle(message);
 }
Пример #4
0
 public void Handle(WithdrawalCreated @event)
 {
     AddActivityLog(AdminActivityLogCategory.Withdrawal, @event, @event.Username);
 }