public void UpdateBusinessMerchantDetails() { const int BUSINESS_ID = 1; var bankAccount = new BankAccount(); var merchantDetails = new MerchantDetails(); merchantDetails.Password = "******"; var businessDao = MockRepository.GenerateMock<IBusinessDao>(); var businessEventDao = MockRepository.GenerateMock<IBusinessEventDao>(); businessManager.BusinessDao = businessDao; businessManager.BusinessEventDao = businessEventDao; businessDao.Expect(x => x.CreateMerchantBankAccount(bankAccount)).Return(0); businessEventDao.Expect(z => z.Create(new BusinessEvent() { BusinessId = BUSINESS_ID })); businessDao.Expect(x => x.CreateMerchantDetails(merchantDetails)).Return(0); businessEventDao.Expect(z => z.Create(new BusinessEvent() { BusinessId = BUSINESS_ID })); businessManager.UpdateBusinessMerchantDetails(BUSINESS_ID, merchantDetails, bankAccount); businessDao.VerifyAllExpectations(); //Needs fixing to uncomment this: businessEventDao.VerifyAllExpectations(); }
/// <summary> /// Process MerchantDetails /// </summary> /// <param name="businessId">BusinessId</param> /// <param name="merchantDetails">MerchantDetails</param> /// <returns>true if processing of merchant details succeeds</returns> private bool ProcessMerchantDetails(long businessId, MerchantDetails merchantDetails) { if (merchantDetails.Id == default(int)) { int newMerchantDetailsId = default(int); // write merchant details record to table newMerchantDetailsId = businessDao.CreateMerchantDetails(merchantDetails); // write business event to event table businessEventDao.Create(new BusinessEvent { BusinessId = businessId, EventType = new EnumEntity { Code = BusinessEventTypesEnum.MerchantDetailsCreated.GetCode() }, Reference = newMerchantDetailsId.ToString() }); merchantDetails.Id = newMerchantDetailsId; return newMerchantDetailsId != default(int); } bool updateMerchantDetails = businessDao.ModifyMerchantDetails(merchantDetails); // write business event to event table businessEventDao.Create(new BusinessEvent { BusinessId = businessId, EventType = new EnumEntity { Code = BusinessEventTypesEnum.MerchantDetailsModified.GetCode() }, Reference = merchantDetails.Id.ToString() }); return updateMerchantDetails; }
/// <summary> /// Update Merchant Details /// </summary> /// <param name="businessId">businessId</param> /// <param name="merchantDetails">MerchantDetails</param> /// <param name="bankAccount">BankAccount</param> /// <returns>true if modification succeeds</returns> public bool UpdateBusinessMerchantDetails(long businessId, MerchantDetails merchantDetails, BankAccount bankAccount) { var updateMerchantDetailsResult = true; var updateMerchantAccountResult = true; var updateBusinessMerchantDetailsResult = true; var updateStatusCodeResult = true; using (var tx = new BusinessTransaction()) { if (merchantDetails.MerchantStatusCode == MerchantStatusEnum.EviivoMerchant.GetCode() || merchantDetails.MerchantStatusCode == MerchantStatusEnum.InterimMerchant.GetCode()) { var updateMerchantStatusCode = ProcessMerchantStatusCode(businessId,merchantDetails.MerchantStatusCode); tx.Commit(); return updateMerchantStatusCode; } // encrypt before persisting to database merchantDetails.Password = DesCrypto.TripleDESEncrypt(merchantDetails.Password); merchantDetails.PasswordExpiry = DateTime.Now.AddMonths(12); // update merchant status code updateStatusCodeResult = ProcessMerchantStatusCode(businessId, merchantDetails.MerchantStatusCode); // update or insert merchant details info updateMerchantDetailsResult = ProcessMerchantDetails(businessId, merchantDetails); // update or insert merchant bank account info only if merchant account is different from settlement account if (!merchantDetails.UseSettlementAccount) { updateMerchantAccountResult = ProcessBankAccount(businessId, bankAccount, BankAccountType.Merchant); } // update business table with merchant details and bank account updateBusinessMerchantDetailsResult = businessDao.UpdateBusinessMerchantDetails(businessId, merchantDetails.Id, bankAccount.Id); tx.Commit(); } return updateStatusCodeResult && updateBusinessMerchantDetailsResult && updateMerchantDetailsResult && updateMerchantAccountResult; }
public void UpdateBusinessMerchantDetails_ExpectSuccess() { using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData))) { const int BUSINESS_ID = 1; // Arrange var merchantDetails = new MerchantDetails() { MerchantId = "testmerchantId", PasswordExpiry = DateTime.Now.AddMonths(10), Is3DSecureAllowed = true, IsAmexAllowed = true, IsIvrAllowed = true, IsPaypalAllowed = true, Password = "******" }; int newMerchantDetailId = businessDao.CreateMerchantDetails(merchantDetails); var bankAccount = new BankAccount() { BankName = "testBankName", BankCode = "testBankCode", AccountName = "testAccountName", AccountNumber = "12345ACC", BIC = "BIC1234" }; int newBankAccountId = businessDao.CreateMerchantBankAccount(bankAccount); // Act bool result = businessDao.UpdateBusinessMerchantDetails(BUSINESS_ID, newMerchantDetailId, newBankAccountId); // Assert Assert.IsTrue(result); } }
public void ModifyMerchantDetails_ExpectSuccess() { using (new TestDataHelper(GetTestQuery(TestQuery.PopulateGetBusinessInformationTestData), GetTestQuery(TestQuery.CleanupUnitTestData))) { // Arrange var merchantDetails = new MerchantDetails() { MerchantId = "1234567", PasswordExpiry = DateTime.Now.AddMonths(10), Is3DSecureAllowed = true, IsAmexAllowed = true, IsIvrAllowed = true, IsPaypalAllowed = true, Password = "******", Id = 1 }; // Act bool result = businessDao.ModifyMerchantDetails(merchantDetails); //Assert Assert.IsTrue(result); } }
public void CreateMerchantDetailsTest_ExpectSuccess() { using (new TestDataHelper(GetTestQuery(TestQuery.PopulateBusinessesTestData), GetTestQuery(TestQuery.CleanupUnitTestData))) { // Arrange var merchantDetails = new MerchantDetails() { MerchantId = "testmerchantId", PasswordExpiry = DateTime.Now.AddMonths(10), Is3DSecureAllowed = true, IsAmexAllowed = true, IsIvrAllowed = true, IsPaypalAllowed = true, Password = "******" }; // Act int newMerchantDetailId = businessDao.CreateMerchantDetails(merchantDetails); // Assert Assert.IsTrue(newMerchantDetailId > 0, "Expect new business merchant detail to be created"); } }
/// <summary> /// Modify Merchant Details /// </summary> /// <param name="merchantDetails">MerchantDetails</param> /// <returns>true if modification succeeds</returns> public bool ModifyMerchantDetails(MerchantDetails merchantDetails) { const string SQL_UPDATE_MERCHANT_DETAILS = @"UPDATE [Business].[MerchantDetails] SET [MID] = @MID, [PasswordCrypt] = @PasswordCrypt, [PasswordExpiryDatetime] = @PasswordExpiryDatetime, [Is3DSecureAllowed] = @Is3DSecureAllowed, [IsPaypalAllowed] = @IsPaypalAllowed, [IsIvrAllowed] = @IsIvrAllowed, [IsAmexAllowed] = @IsAmexAllowed, [UpdatedByUserId] = @UpdatedByUserId WHERE Id = @Id"; var parameters = new List<SqlParameter> { DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.Id, merchantDetails.Id), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.MID, merchantDetails.MerchantId), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.PasswordCrypt, merchantDetails.Password), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.Is3DSecureAllowed, merchantDetails.Is3DSecureAllowed), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.IsAmexAllowed, merchantDetails.IsAmexAllowed), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.IsPaypalAllowed, merchantDetails.IsPaypalAllowed), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.IsIvrAllowed, merchantDetails.IsIvrAllowed), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.PasswordExpiryDatetime, merchantDetails.PasswordExpiry) }; AuditFieldsHelper.PopulateAuditFields(parameters); return DbHelper.ExecuteNonQueryCommand(SQL_UPDATE_MERCHANT_DETAILS, parameters: parameters) > 0; }
/// <summary> /// Create Merchant Details /// </summary> /// <param name="merchantDetails">MerchantDetails</param> /// <returns>Id of created merchant details</returns> public int CreateMerchantDetails(MerchantDetails merchantDetails) { const string SQL_CREATE_MERCHANT_DETAILS = @" INSERT INTO [Business].[MerchantDetails] ([MID] ,[PasswordCrypt] ,[PasswordExpiryDatetime] ,[Is3DSecureAllowed] ,[IsPaypalAllowed] ,[IsIvrAllowed ] ,[IsAmexAllowed] ,[UpdatedByUserId]) VALUES (@MID ,@PasswordCrypt ,@PasswordExpiryDatetime ,@Is3DSecureAllowed ,@IsPaypalAllowed ,@IsIvrAllowed ,@IsAmexAllowed ,@UpdatedByUserId) SET @Id = SCOPE_IDENTITY();"; var parameters = new List<SqlParameter> { DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.MID, merchantDetails.MerchantId), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.PasswordCrypt, merchantDetails.Password), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.PasswordExpiryDatetime, merchantDetails.PasswordExpiry), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.Is3DSecureAllowed, merchantDetails.Is3DSecureAllowed), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.IsPaypalAllowed, merchantDetails.IsPaypalAllowed), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.IsIvrAllowed, merchantDetails.IsIvrAllowed), DbHelper.CreateParameter(MerchantDetailsMapper.Parameters.IsAmexAllowed, merchantDetails.IsAmexAllowed) }; AuditFieldsHelper.PopulateAuditFields(parameters); SqlParameter outputKey; parameters.Add(outputKey = DbHelper.CreateParameterOut<int>(MerchantDetailsMapper.Parameters.Id, SqlDbType.Int)); try { DbHelper.ExecuteNonQueryCommand(SQL_CREATE_MERCHANT_DETAILS, parameters: parameters); } catch (SqlException exception) { throw new ExpectedResultException(ErrorFactory.CreateAndLogError(Errors.SRVEX30099, "BusinessDao.CreateMerchantDetails", additionalDescriptionParameters: (new object[] { exception.Message }), arguments: new object[] { merchantDetails.GetType().Name, merchantDetails.Id })); } if (outputKey.Value == DBNull.Value) { throw new PrimaryKeyNotSetException(ErrorFactory.CreateAndLogError(Errors.SRVEX30100, "BusinessDao.CreateMerchantDetails", additionalDescriptionParameters: (new object[] { merchantDetails.Id }))); } return DbHelper.ParameterValue<int>(outputKey); }