public void AddTransfer(
            Core.Brand.Interface.Data.Brand brand,
            Guid playerId,
            Guid walletTemplateId,
            IPaymentRepository repository,
            double timeShiftInDays = 0)
        {
            var transferFund = new TransferFund
            {
                Id                = Guid.NewGuid(),
                Amount            = 1,
                CreatedBy         = playerId.ToString(),
                Created           = DateTimeOffset.Now.ToBrandOffset(brand.TimezoneId) + TimeSpan.FromDays(timeShiftInDays),
                TransferType      = TransferFundType.FundIn,
                WalletId          = walletTemplateId.ToString(),
                Status            = TransferFundStatus.Approved,
                TransactionNumber = "TF000000000"
            };

            repository.TransferFunds.Add(transferFund);
            repository.SaveChanges();
        }
Ejemplo n.º 2
0
        public async Task <string> AddFund(TransferFundRequest request)
        {
            var validationResult = await _validationService.Validate(request);

            var transferFund      = new TransferFund();
            var transactionNumber = GenerateTransactionNumber();

            using (var scope = CustomTransactionScope.GetTransactionScope())
            {
                var requestWalletId       = new Guid(request.WalletId);
                var requestWalletTemplate = _brandQueries.GetWalletTemplate(requestWalletId);
                var mainWalletTemplate    = _brandQueries.GetWalletTemplates(requestWalletTemplate.Brand.Id).Single(wt => wt.IsMain);
                var timezoneId            = requestWalletTemplate.Brand.TimezoneId;

                _repository.TransferFunds.Add(transferFund);
                transferFund.Id                = Guid.NewGuid();
                transferFund.TransferType      = request.TransferType;
                transferFund.TransactionNumber = transactionNumber;
                transferFund.Amount            = request.Amount;
                transferFund.WalletId          = request.WalletId;
                transferFund.CreatedBy         = request.PlayerId.ToString();
                transferFund.Created           = DateTimeOffset.Now.ToBrandOffset(timezoneId);
                transferFund.Remarks           = transferFund.Remarks = !validationResult.IsValid ? validationResult.ErrorMessage : string.Empty;
                transferFund.Status            = validationResult.IsValid ? TransferFundStatus.Approved : TransferFundStatus.Rejected;
                transferFund.BonusCode         = request.BonusCode;

                if (validationResult.IsValid)
                {
                    var sourceWalletId = request.TransferType == TransferFundType.FundIn
                        ? mainWalletTemplate.Id
                        : requestWalletId;
                    var destinationWalletId = request.TransferType == TransferFundType.FundIn
                        ? requestWalletId
                        : mainWalletTemplate.Id;

                    //_walletCommands.TransferFunds(request.PlayerId, sourceWalletId, destinationWalletId, request.Amount, transactionNumber);
                    if (request.BonusId.HasValue || string.IsNullOrWhiteSpace(request.BonusCode) == false && transferFund.Status == TransferFundStatus.Approved)
                    {
                        await _bonusApiProxy.ApplyForBonusAsync(new FundInBonusApplication
                        {
                            PlayerId  = request.PlayerId,
                            BonusId   = request.BonusId,
                            BonusCode = request.BonusCode,
                            Amount    = request.Amount,
                            DestinationWalletTemplateId = destinationWalletId
                        });
                    }

                    transferFund.DestinationWalletId = destinationWalletId;
                }

                _eventBus.Publish(new TransferFundCreated
                {
                    PlayerId                     = new Guid(transferFund.CreatedBy),
                    TransactionNumber            = transferFund.TransactionNumber,
                    Amount                       = transferFund.Amount,
                    Remarks                      = transferFund.Remarks,
                    BonusCode                    = transferFund.BonusCode,
                    DestinationWalletStructureId = transferFund.DestinationWalletId,
                    Type        = transferFund.TransferType,
                    Status      = transferFund.Status,
                    Description = string.Format("Transaction #{0}", transferFund.TransactionNumber)
                });
                _repository.SaveChanges();
                scope.Complete();
            }

            if (!validationResult.IsValid)
            {
                throw new ArgumentException(validationResult.ErrorMessage);
            }

            return(transactionNumber);
        }