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); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var(_, debtorAccountNumber, amount, _, paymentScheme) = request; var(accountExists, account) = _accountDataStore.GetAccount(debtorAccountNumber); if (!accountExists) { return(InvalidAccountResult(debtorAccountNumber)); } var paymentValidator = PaymentSchemeValidators[paymentScheme]; var(isValid, validationMessage) = paymentValidator.IsRequestValidForPayment(request, account); if (!isValid) { return(AccountNotAllowedForPaymentResult(validationMessage)); } var newBalance = account.Balance - amount; _accountDataStore.UpdateAccount(account with { Balance = newBalance }); return(PaymentSuccessfulResult()); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var result = new MakePaymentResult(); Account account = _accountDataStore.GetAccount(request.DebtorAccountNumber); if (account != null) { IPaymentRequestValidator paymentRequestValidator = _paymentSchemeValidatorService.GetPaymentSchemeValidator(request.PaymentScheme); if (paymentRequestValidator == null) { result.Success = false; } else { result.Success = paymentRequestValidator.IsValid(account, request); } } if (result.Success) { account.Balance -= request.Amount; _accountDataStore.UpdateAccount(account); } return result; }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var account = _accountDataStore.GetAccount(request.DebtorAccountNumber); return(CanProcessRequest(request, account) ? ProcessRequest(request, account) : GetUnsuccessfulRequest()); }
public void GetAccount_Should_Return_An_Account() { var accountNumber = _fixture.Create <string>(); var account = _sut.GetAccount(accountNumber); Assert.IsNotNull(account); Assert.IsInstanceOf <Account>(account); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var account = _accountDataStore.GetAccount(request.DebtorAccountNumber); var result = _accountStateValidator.Validate(request, account); if (result.Success) { account.Balance -= request.Amount; _accountDataStore.UpdateAccount(account); } return(result); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { Account account = _accountDataStore.GetAccount(request.DebtorAccountNumber); MakePaymentResult result = _validationService.Validate(request.PaymentScheme, account, request); if (result.Success) { account.Balance -= request.Amount; _accountDataStore.UpdateAccount(account); } return(result); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { try { IAccountDataStore dataStore = accountRepository.GetDataStore(); Account debtorAccount = dataStore.GetAccount(request.DebtorAccountNumber); Account creditorAccount = dataStore.GetAccount(request.CreditorAccountNumber); if (debtorAccount == null) { throw new ArgumentException("Debtor account not found."); } else if (creditorAccount == null) { throw new ArgumentException("Creditor account not found."); } debtorAccount.Debit(request.Amount, request.PaymentScheme); creditorAccount.Credit(request.Amount, request.PaymentScheme); //Normally these two operations would be part of a transaction, e.g. the repository would implement the UnitOfWork pattern dataStore.UpdateAccount(debtorAccount); dataStore.UpdateAccount(creditorAccount); } catch (Exception ex) { //Normall we would the log error here with an abstraction of a logging component (ILogger etc) injected in this service return(new MakePaymentResult { Success = false }); } return(new MakePaymentResult { Success = true }); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var account = AccountDataStore.GetAccount(request.DebtorAccountNumber); var paymentRule = PaymentRule.GetPaymentRule(request.PaymentScheme); if (paymentRule.IsValid(account, request)) { account.Balance -= request.Amount; AccountDataStore.UpdateAccount(account); return(new MakePaymentResult() { Success = true }); } return(new MakePaymentResult()); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { Account account = _accountDataStore.GetAccount(request.DebtorAccountNumber); if (account == null) { return new MakePaymentResult() { Success = false } } ; var validationProcess = _validatePaymentFactory.CreateValidationProcess(request.PaymentScheme); if (validationProcess == null) { return new MakePaymentResult() { Success = false } } ; var isValid = validationProcess.ValidatePayment(account, request); var result = new MakePaymentResult(); if (isValid) { account.Balance -= request.Amount; //if data store update fails then we should return false //and reset the balance to the amount that was before deduction,in other words we need a transaction //but skipping for brevity _accountDataStore.UpdateAccount(account); result.Success = true; } return(result); } } }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var account = accountDataStore.GetAccount(request.DebtorAccountNumber); var result = new MakePaymentResult(); if (account == null || !account.ValidatePayment(request.PaymentScheme, request.Amount)) { return(result); } result.Success = true; account.Balance -= request.Amount; accountDataStore.UpdateAccount(account); return(result); }
/// <summary> /// Make Payment /// </summary> /// <param name="request">Payment Request</param> /// <returns>Payment Result</returns> public MakePaymentResult MakePayment(MakePaymentRequest request) { var result = new MakePaymentResult(); // Recover Account Account account = _accountDataStore.GetAccount(request.DebtorAccountNumber); // Check and Set Account Validity result.Success = AccountValidator.CheckAccountIsValid(account, request); if (result.Success) { // Calc & Set New Balance account.Balance = CalculateNewAccountBalance(account.Balance, request.Amount); // Update Account _accountDataStore.UpdateAccount(account); } return(result); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var validationResult = _validator.Validate(request); if (validationResult.Errors.Any()) { return new MakePaymentResult { Success = false } } ; var account = _accountDataStore.GetAccount(request.DebtorAccountNumber); var result = GetPaymentScheme(request).Process(account, request.Amount); if (result.Success) { _balanceService.DeductBalance(account, request.Amount); } return(result); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { if (request == null) { throw new ArgumentNullException(nameof(request)); } MakePaymentResult result = new MakePaymentResult(); Account account = _accountDataStore.GetAccount(request.DebtorAccountNumber); if (_paymentSchemeValidationHandler.IsPaymentValid(request, account)) { account.Balance -= request.Amount; _accountDataStore.UpdateAccount(account); result.Success = true; } else { result.Success = false; } return(result); }
public Account GetAccount(string accountNumber) { return(_accountDataStoreFactory.GetAccount(accountNumber)); }
public Account GetAccount(string accountNumber) { return(_dataStore.GetAccount(accountNumber)); }
public Account GetAccount(string requestDebtorAccountNumber) { return(_accountDataStore.GetAccount(requestDebtorAccountNumber)); }