Example #1
0
        public MakePaymentResult MakePayment(MakePaymentRequest request)
        {
            var result = new MakePaymentResult {
                Success = false
            };

            if (request == null)
            {
                return(result);
            }

            IAccountDataStore accountDataStore = _accountDataStoreFactory.BuildAccountDataStore();

            IValidator validator = _validatorFactory.BuildValidator(request);

            Account account = accountDataStore.GetAccount(request.DebtorAccountNumber);

            if (account == null || !validator.AccountCanMakePayment(account))
            {
                return(result);
            }

            account.Balance -= request.Amount;

            accountDataStore.UpdateAccount(account);

            result.Success = true;

            return(result);
        }