private List <TransactionItemDTO> GetTransactionItemDTOs() { List <TransactionItemDTO> transactionDTOs = new List <TransactionItemDTO>(); TransactionItemDTO transactionDTO = new TransactionItemDTO() { AccountId = GetAccountIdByUser("9999"), TransactionAmount = 10000, UserId = "9999", PAccountId = "53126231237", TransactionProviderType = 1, TransactionType = 1 }; TransactionItemDTO transactionDTOSecond = new TransactionItemDTO() { AccountId = GetAccountIdByUser("9999"), TransactionAmount = 5000, UserId = "9999", PAccountId = "53126231237", TransactionProviderType = 1, TransactionType = 1 }; transactionDTOs.Add(transactionDTO); transactionDTOs.Add(transactionDTOSecond); return(transactionDTOs); }
public OnePayTransaction SaveTransaction(TransactionItemDTO transaction, bool status) { try { _transaction = new OnePayTransaction(); _transaction.TransactionId = "T" + RandomNumerGenerator.GetRandomNumber(10); _transaction.TransactionComment = "Transaction from OnePay for AccountId"; _transaction.TransactionAmount = transaction.TransactionAmount; _transaction.UserId = transaction.UserId; _transaction.AccountId = transaction.AccountId; _transaction.PaccountId = transaction.PAccountId; _transaction.TransactionTypeId = transaction.TransactionType; _transaction.TransactionStatusId = (status) ? (int)TransactionStatusTypes.Successful : (int)TransactionStatusTypes.Declined; _transaction.TransactionProvideTypeId = transaction.TransactionProviderType; _transaction.Timestamp = DateTime.Now.ToString(); if (_transaction != null) { _context.OnePayTransaction.Add(_transaction); _context.SaveChanges(); } } catch (AppException ex) { throw new AppException("Transaction not successful", ex.Message); } return(_transaction); }
public decimal ReCalculateTotal(TransactionItemDTO transaction) { decimal totalAmount = CalculateTotal(transaction.UserId); var modifiedTotalAmount = totalAmount - GetMonthlyCyclePaymentsOfAccount(transaction.PAccountId, transaction.UserId) + transaction.TransactionAmount; return(modifiedTotalAmount); }
public IActionResult GetModifiedDue([FromBody] TransactionItemDTO itemDTO) { decimal dueAmount = 0; if (itemDTO != null) { dueAmount = _onePayService.CalculateModifiedTotalAmount(itemDTO); } if (dueAmount < itemDTO.TransactionAmount) { return(BadRequest(new { message = $"Amount should be more than {itemDTO.TransactionAmount}" })); } else { return(Ok(dueAmount)); } }
public decimal CalculateModifiedTotalAmount(TransactionItemDTO transactionDTO) { decimal modifiedTotalAmount = 0; var businessProduct = _businessProductService.GetById(transactionDTO.UserId, transactionDTO.PAccountId); bool canBeModified = CanModifyBalance(businessProduct, transactionDTO.TransactionAmount); if (canBeModified) { modifiedTotalAmount += ReCalculateTotal(transactionDTO); } else { return(0); } return(modifiedTotalAmount); }
public void ExecuteTransaction(TransactionItemDTO transaction, UserAccount userAccount, BusinessProduct bProduct, User user) { bool debitStatus, creditStatus = false; debitStatus = DebitAmount(userAccount.UserId, transaction.AccountId, transaction.TransactionAmount); if (debitStatus) { creditStatus = CreditAmount(userAccount.UserId, transaction.PAccountId, transaction.TransactionAmount); OnePayTransaction transactionObj = null; //call transaction service try { transactionObj = _transactionService.SaveTransaction(transaction, creditStatus); } catch (AppException ex) { throw new AppException("Transaction Not Successful", ex.Message); } if (transactionObj.TransactionId != null) { EndTransaction(transactionObj, user); } } }