public async Task <DigitalAccountTransactionModel> InsertAsync(DigitalAccountTransactionModel digitalAccountTransaction) { DigitalAccountTransactionModel transaction = await _digitalAccountTransactionRepository.InsertAsync(digitalAccountTransaction); _bus.Publish <ITransactionEvent>(new { transaction.Id }).GetAwaiter().GetResult(); return(transaction); }
public async Task <IActionResult> GetTransactionByIdAsync([Required] int transactionId) { DigitalAccountTransactionModel transaction = await _digitalAccountTransactionBusiness.GetByIdAsync(transactionId); TransactionResponseDTO response = _mapper.Map <TransactionResponseDTO>(transaction); return(Ok(response)); }
public async Task <DigitalAccountTransactionModel> InsertAsync(DigitalAccountTransactionModel digitalAccountTransaction) { var newDigitalAccountTransaction = await _appDbContext.DigitalAccountTransactions.AddAsync(digitalAccountTransaction); await _appDbContext.SaveChangesAsync(); return(newDigitalAccountTransaction.Entity); }
public async Task <DigitalAccountTransactionModel> UpdateAsync(DigitalAccountTransactionModel digitalTransactionAccount) { var digitalTransactionAccountUpdate = _appDbContext.DigitalAccountTransactions.Update(digitalTransactionAccount); await _appDbContext.SaveChangesAsync(); return(digitalTransactionAccountUpdate.Entity); }
public async Task <IActionResult> CreateTransactionTransferAsync([FromBody] TransactionTransferRequestDTO transactionRequest) { DigitalAccountTransactionModel transaction = _mapper.Map <DigitalAccountTransactionModel>(transactionRequest); DigitalAccountTransactionModel transactionResponse = await _digitalAccountTransactionBusiness.CreateTransactionTransferAsync(transaction); TransactionResponseDTO response = _mapper.Map <TransactionResponseDTO>(transactionResponse); return(Ok(response)); }
public async Task <DigitalAccountTransactionModel> GetByIdAsync(int transactionId) { DigitalAccountTransactionModel transaction = await _digitalAccountTransactionRepository.GetByIdAsync(transactionId); if (transaction == null) { throw new KeyNotFoundException("Transação não localizada"); } return(transaction); }
private async Task EffectedTransation(DigitalAccountTransactionModel transaction) { DigitalAccountModel digitalAccount = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccountId); digitalAccount.Balance = transaction.Type == TransactionTypeEnum.Output ? (digitalAccount.Balance - transaction.Value) : (digitalAccount.Balance + transaction.Value); await _digitalAccounBusiness.UpdateAsync(digitalAccount); await UpdateStatusAsync(transaction, TransactionStatusEnum.Effected); }
private async Task <DigitalAccountTransactionModel> ProcessCustomerSenderDepositTransactionAsync(DigitalAccountTransactionModel transaction) { DigitalAccountModel digitalAccountSender = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccountSender.Id); DigitalAccountTransactionModel transactionSender = await ProcessCustomerSenderTransactionAsync(transaction, TransactionOperationEnum.Deposit, digitalAccountSender); transactionSender.DigitalAccount = digitalAccountSender; return(transactionSender); }
private async Task <DigitalAccountTransactionModel> ProcessCustomerSenderTransferTransactionAsync(DigitalAccountTransactionModel transaction) { DigitalAccountModel digitalAccountSender = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccountSender.Id); await ValidRequestCustomerIdWithCustomerTokenAsync(digitalAccountSender.CustomerId); DigitalAccountTransactionModel transactionSender = await ProcessCustomerSenderTransactionAsync(transaction, TransactionOperationEnum.Transfer, digitalAccountSender); transactionSender.DigitalAccount = digitalAccountSender; return(transactionSender); }
public async Task <DigitalAccountTransactionModel> CreateTransactionTransferAsync(DigitalAccountTransactionModel transaction) { DigitalAccountTransactionModel transactionSender = await ProcessCustomerSenderTransferTransactionAsync(transaction); DigitalAccountModel digitalAccount = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccount.Id); transaction = await CreateTransactionAsync(transaction, TransactionTypeEnum.Input, TransactionOperationEnum.Transfer, transaction.DigitalAccount.Id, transaction.DigitalAccountSender.Id); transaction.DigitalAccount = digitalAccount; transaction.DigitalAccountSender = transactionSender.DigitalAccount; return(transaction); }
private async Task <DigitalAccountTransactionModel> ProcessCustomerSenderTransactionAsync(DigitalAccountTransactionModel transaction, TransactionOperationEnum operation, DigitalAccountModel digitalAccountSender) { await CheckExceededLimitTransctionAsync(transaction.Value, digitalAccountSender.TransferLimitTransaction); await ValidTransactionIfAccountSenderAndRecipientEqualsAsync(transaction.DigitalAccountSender.Id, transaction.DigitalAccount.Id); await CheckExceededDigitalAccountDailyLimitTransctionAsync(transaction.DigitalAccountSender.Id, transaction.Value, digitalAccountSender); DigitalAccountTransactionModel transactionSender = await CreateTransactionAsync(transaction, TransactionTypeEnum.Output, operation, transaction.DigitalAccountSender.Id, transaction.DigitalAccount.Id); return(transactionSender); }
private async Task <DigitalAccountTransactionModel> CreateTransactionAsync(DigitalAccountTransactionModel transaction, TransactionTypeEnum type, TransactionOperationEnum operation, int customerRecipientId, int?customerSenderId) { DigitalAccountTransactionModel newTransaction = new DigitalAccountTransactionModel() { Value = transaction.Value, DigitalAccountId = customerRecipientId, DigitalAccountSenderId = customerSenderId, Type = type, Operation = operation, Status = TransactionStatusEnum.Pending }; transaction = await InsertAsync(newTransaction); return(transaction); }
public async Task ConsistQueueAsync(int transactionId) { DigitalAccountTransactionModel transaction = await _digitalAccountTransactionRepository.GetByIdAsync(transactionId); bool limitAttemptExceeded = false; if (transaction.DigitalAccountSenderId.HasValue) { limitAttemptExceeded = await CheckExceededLimitAttemptToIntervalTransactionAsync(transaction.DigitalAccountSenderId.Value); } if (transaction.DigitalAccountSenderId.HasValue && limitAttemptExceeded) { await GenerateRollbackTransation(transaction); } else { await EffectedTransation(transaction); } }
public void GetById_Success_ReturnDigitalAccountTransaction(int id) { DigitalAccountTransactionModel digitalAccountTransactionResult = new DigitalAccountTransactionModel() { Id = id, Operation = TransactionOperationEnum.Deposit, Type = TransactionTypeEnum.Input, DigitalAccountId = 1, DigitalAccountSenderId = 2, Status = TransactionStatusEnum.Pending, Value = 100m, CreatedDate = DateTime.Now }; _digitalAccountTransactionRepositoryMock.Setup(repository => repository.GetByIdAsync(id)).ReturnsAsync(() => digitalAccountTransactionResult); DigitalAccountTransactionModel result = _digitalAccountTransactionBusiness.GetByIdAsync(id).Result; Assert.IsNotNull(result); Assert.AreEqual(id, result.Id); _digitalAccountTransactionRepositoryMock.Verify(x => x.GetByIdAsync(id), Times.Once); }
public void Insert_Success() { DigitalAccountTransactionModel digitalAccountTransaction = new DigitalAccountTransactionModel() { Operation = TransactionOperationEnum.Deposit, Type = TransactionTypeEnum.Input, DigitalAccountId = 1, DigitalAccountSenderId = 2, Status = TransactionStatusEnum.Pending, Value = 100m, }; DigitalAccountTransactionModel digitalAccountTransactionResult = new DigitalAccountTransactionModel() { Id = 1, Operation = TransactionOperationEnum.Deposit, Type = TransactionTypeEnum.Input, DigitalAccountId = 1, DigitalAccountSenderId = 2, Status = TransactionStatusEnum.Pending, Value = 100m, CreatedDate = DateTime.Now }; _digitalAccountTransactionRepositoryMock.Setup(repository => repository.InsertAsync(digitalAccountTransaction)).ReturnsAsync(() => digitalAccountTransactionResult); DigitalAccountTransactionModel result = _digitalAccountTransactionBusiness.InsertAsync(digitalAccountTransaction).Result; Assert.IsNotNull(result); Assert.IsNotNull(result.Id); Assert.IsNotNull(result.CreatedDate); Assert.NotZero(result.Id); _digitalAccountTransactionRepositoryMock.Verify(x => x.InsertAsync(digitalAccountTransaction), Times.Once); }
public async Task <DigitalAccountTransactionModel> UpdateAsync(DigitalAccountTransactionModel digitalAccountTransaction) { return(await _digitalAccountTransactionRepository.UpdateAsync(digitalAccountTransaction)); }
private async Task GenerateRollbackTransation(DigitalAccountTransactionModel transaction) { await UpdateStatusAsync(transaction, TransactionStatusEnum.Denied); }
public async Task <DigitalAccountTransactionModel> GetByIdAsync(int transactionId) { DigitalAccountTransactionModel transaction = await _digitalAccountTransactionRepository.GetByIdAsync(transactionId); return(transaction); }
public async Task <DigitalAccountTransactionModel> UpdateStatusAsync(DigitalAccountTransactionModel digitalAccountTransaction, TransactionStatusEnum status) { digitalAccountTransaction.Status = status; digitalAccountTransaction.ReleaseDate = DateTime.Now; return(await _digitalAccountTransactionRepository.UpdateAsync(digitalAccountTransaction)); }
public async Task <DigitalAccountTransactionModel> CreateTransactionDepositAsync(DigitalAccountTransactionModel transaction) { if (transaction.DigitalAccountSender != null) { await ProcessCustomerSenderDepositTransactionAsync(transaction); } DigitalAccountModel digitalAccount = await _digitalAccounBusiness.GetByIdAsync(transaction.DigitalAccount.Id); transaction = await CreateTransactionAsync(transaction, TransactionTypeEnum.Input, TransactionOperationEnum.Deposit, digitalAccount.Id, transaction.DigitalAccountSender?.Id); transaction.DigitalAccount = digitalAccount; return(transaction); }