public MakePaymentResult MakePayment(MakePaymentRequest request) { var dataStoreType = ConfigurationManager.AppSettings["DataStoreType"]; Account account = null; if (dataStoreType == "Backup") { var accountDataStore = new BackupAccountDataStore(); account = accountDataStore.GetAccount(request.DebtorAccountNumber); } else { var accountDataStore = new AccountDataStore(); account = accountDataStore.GetAccount(request.DebtorAccountNumber); } var result = new MakePaymentResult(); CheckPaymentScheme(request, account, result); ProcessPayment(request, dataStoreType, account, result); return(result); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var creator = new AccountDataStoreCreator(_configurationService); var account = creator.Create(request.DebtorAccountNumber); var validator = SchemeValidatorFactory.GetValidator(account, request); var result = validator.Validate(); if (result.Success) { account.Balance -= request.Amount; if (account.Location == AccountLocation.Backup) { var accountDataStore = new BackupAccountDataStore(); accountDataStore.UpdateAccount(account); } else { var accountDataStore = new AccountDataStore(); accountDataStore.UpdateAccount(account); } } return(result); }
public Account Create(string debtorAccountNumber) { if (_dataStoreType == "Backup") { var accountDataStore = new BackupAccountDataStore(); return(accountDataStore.GetAccount(debtorAccountNumber)); } else { var accountDataStore = new AccountDataStore(); return(accountDataStore.GetAccount(debtorAccountNumber)); } }
public IDataStore Create(string dataStoreType) { IDataStore datastore = null; if (dataStoreType == "Backup") { datastore = new BackupAccountDataStore(); } else { datastore = new AccountDataStore(); } return(datastore); }
public IDataStore CreateDataStore(string storeType) { IDataStore accountDataStore = null; if (storeType == "Backup") { accountDataStore = new BackupAccountDataStore(); } else { accountDataStore = new AccountDataStore(); } return(accountDataStore); }
public virtual Account Get(MakePaymentRequest request) { var dataStoreType = Config.DataStoreType; Account account = null; if (dataStoreType == "Backup") { var accountDataStore = new BackupAccountDataStore(); account = accountDataStore.GetAccount(request.DebtorAccountNumber); } else { var accountDataStore = new AccountDataStore(); account = accountDataStore.GetAccount(request.DebtorAccountNumber); } return(account); }
public void PaymentBacsAccountNull_ReturnsFalse() { var moq = new Mock <AccountFactory>(); var accountDataStore = new BackupAccountDataStore(); MakePaymentRequest request = new MakePaymentRequest(); request.PaymentScheme = PaymentScheme.Bacs; Account account = null; moq.Setup(x => x.Get(request)).Returns(account); IPaymentService service = new PaymentService(moq.Object); var result = service.MakePayment(request); Assert.IsTrue(result.Success == false); }
public void ProcessPayment(MakePaymentRequest request, string dataStoreType, Account account, MakePaymentResult result) { if (result.Success) { account.Balance -= request.Amount; if (dataStoreType == "Backup") { var accountDataStore = new BackupAccountDataStore(); accountDataStore.UpdateAccount(account); } else { var accountDataStore = new AccountDataStore(); accountDataStore.UpdateAccount(account); } } }
public void PaymentBacs_BacsNotAllowed_AccountDefined_ReturnsFalse() { var moq = new Mock <AccountFactory>(); var accountDataStore = new BackupAccountDataStore(); MakePaymentRequest request = new MakePaymentRequest(); request.PaymentScheme = PaymentScheme.Bacs; var account = accountDataStore.GetAccount(request.DebtorAccountNumber); account.AllowedPaymentSchemes = AllowedPaymentSchemes.FasterPayments | AllowedPaymentSchemes.Chaps; moq.Setup(x => x.Get(request)).Returns(account); IPaymentService service = new PaymentService(moq.Object); var result = service.MakePayment(request); Assert.IsTrue(result.Success == false); }
public virtual IAccountDataStore GetAccountDataStore() { IAccountDataStore accountDataStore = null; var dataStoreType = _appConfig.GetValueByKey("DataStoreType"); switch (dataStoreType) { case "Backup": { accountDataStore = new BackupAccountDataStore(); break; } default: { accountDataStore = new AccountDataStore(); break; } } return(accountDataStore); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { var dataStoreType = ConfigurationManager.AppSettings["DataStoreType"]; Account account = null; if (dataStoreType == "Backup") { var accountDataStore = new BackupAccountDataStore(); account = accountDataStore.GetAccount(request.DebtorAccountNumber); } else { var accountDataStore = new AccountDataStore(); account = accountDataStore.GetAccount(request.DebtorAccountNumber); } var result = new MakePaymentResult(); switch (request.PaymentScheme) { case PaymentScheme.Bacs: if (account == null) { result.Success = false; } else if (!account.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.Bacs)) { result.Success = false; } break; case PaymentScheme.FasterPayments: if (account == null) { result.Success = false; } else if (!account.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.FasterPayments)) { result.Success = false; } else if (account.Balance < request.Amount) { result.Success = false; } break; case PaymentScheme.Chaps: if (account == null) { result.Success = false; } else if (!account.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.Chaps)) { result.Success = false; } else if (account.Status != AccountStatus.Live) { result.Success = false; } break; } if (result.Success) { account.Balance -= request.Amount; if (dataStoreType == "Backup") { var accountDataStore = new BackupAccountDataStore(); accountDataStore.UpdateAccount(account); } else { var accountDataStore = new AccountDataStore(); accountDataStore.UpdateAccount(account); } } return(result); }
public MakePaymentResult MakePayment(MakePaymentRequest request) { Account account = accountFactory.Get(request); var result = new MakePaymentResult(); switch (request.PaymentScheme) { case PaymentScheme.Bacs: if (account == null) { result.Success = false; } else if (!account.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.Bacs)) { result.Success = false; } break; //missing success true? case PaymentScheme.FasterPayments: if (account == null) { result.Success = false; } else if (!account.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.FasterPayments)) { result.Success = false; } else if (account.Balance < request.Amount) { result.Success = false; } break; //missing success true? case PaymentScheme.Chaps: if (account == null) { result.Success = false; } else if (!account.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.Chaps)) { result.Success = false; } else if (account.Status != AccountStatus.Live) { result.Success = false; } break; //missing success true? } if (result.Success) { account.Balance -= request.Amount; var dataStoreType = Config.DataStoreType; if (dataStoreType == "Backup") { var accountDataStore = new BackupAccountDataStore(); accountDataStore.UpdateAccount(account); } else { var accountDataStore = new AccountDataStore(); accountDataStore.UpdateAccount(account); } } return(result); }