Ejemplo n.º 1
0
        public async Task <GlobalTransactionResult> TransactAsync(GlobalTransactionDto model)
        {
            if (!ValidationUtil.IsObjectValid(model))
            {
                return(GlobalTransactionResult.GeneralFailure);
            }

            var account = await this.bankAccountService
                          .GetByIdAsync <BankAccountConciseServiceModel>(model.SourceAccountId);

            // check if account exists and recipient name is accurate
            if (account == null)
            {
                return(GlobalTransactionResult.GeneralFailure);
            }

            // verify there is enough money in the account
            if (account.Balance < model.Amount)
            {
                return(GlobalTransactionResult.InsufficientFunds);
            }

            // contact the CodexApi to execute the transfer
            var submitDto = Mapper.Map <CodexApiSubmitTransactionDto>(model);

            submitDto.SenderName            = account.UserFullName;
            submitDto.SenderAccountUniqueId = account.UniqueId;

            bool remoteSuccess = await this.ContactCodexApiAsync(submitDto);

            if (!remoteSuccess)
            {
                return(GlobalTransactionResult.GeneralFailure);
            }

            // remove money from source account
            var serviceModel = new TransactionCreateServiceModel
            {
                Amount      = -model.Amount,
                Source      = account.UniqueId,
                Description = model.Description,
                AccountId   = account.Id,
                DestinationBankAccountUniqueId = model.DestinationBankAccountUniqueId,
                SenderName      = account.UserFullName,
                RecipientName   = model.RecipientName,
                ReferenceNumber = submitDto.ReferenceNumber
            };

            bool success = await this.TransactionService.CreateTransactionAsync(serviceModel);

            return(!success ? GlobalTransactionResult.GeneralFailure : GlobalTransactionResult.Succeeded);
        }
Ejemplo n.º 2
0
        public async Task <GlobalTransactionResult> TransactAsync(GlobalTransactionDto model)
        {
            if (!ValidationUtil.IsObjectValid(model))
            {
                return(GlobalTransactionResult.GeneralFailure);
            }

            // TODO: Remove this check or the one in PaymentsController
            var account = await this.bankAccountService
                          .GetByUniqueIdAsync <BankAccountConciseServiceModel>(model.DestinationBankAccountUniqueId);

            if (account == null)
            {
                return(GlobalTransactionResult.GeneralFailure);
            }

            if (account.Balance < model.Amount)
            {
                return(GlobalTransactionResult.InsufficientFunds);
            }

            var serviceModel = new TransactionCreateServiceModel
            {
                Amount      = -model.Amount,
                Source      = account.UniqueId,
                Description = model.Description ?? String.Empty,
                AccountId   = account.Id,
                DestinationBankAccountUniqueId = model.DestinationBankAccountUniqueId,
                SenderName      = account.UserFullName,
                RecipientName   = model.RecipientName,
                ReferenceNumber = ReferenceNumberGenerator.GenerateReferenceNumber()
            };

            bool success = await this.transactionService.CreateTransactionAsync(serviceModel);

            return(!success ? GlobalTransactionResult.GeneralFailure : GlobalTransactionResult.Succeeded);
        }