public async Task <ISingleResponse <vmTransactionPrepareRequest> > PrepareTransactionRelatedRequestAsync(int currentUid) { var response = new SingleResponse <vmTransactionPrepareRequest>(); try { // Retrieve PaymentMethods list response.Model.PaymentMethods = await PaymentMethodRepository.GetListPaymentMethodAsync(); // Retrieve PaymentPayors list response.Model.PaymentPayors = await PaymentPayorRepository.GetListPaymentPayorAsync(currentUid); // Retrieve TransactionCategorys list response.Model.TransactionCategorys = await TransactionCategoryRepository.GetListTransactionCategoryAsync(); // Retrieve TransactionTypes list response.Model.TransactionTypes = await TransactionTypeRepository.GetListTransactionTypeAsync(); } catch (Exception ex) { response.SetError(ex); } return(response); }
public int Get(int page, int rows, string sidx, string sord) { try { PaymentMethodFilter filter = new PaymentMethodFilter { Page = page, Rows = rows, Sidx = sidx, Sord = sord }; var options = CreateNewContextOptions(); using (var db = new OrderContext(options)) { ProcessingTestHelper.PopulateDefaultOrderCtx(db); } using (var db = new OrderContext(options)) { IEnumerable <PaymentMethod> result = new List <PaymentMethod>(); var repository = new PaymentMethodRepository(db); Assert.DoesNotThrow(() => result = repository.Get(filter)); return(result.Count()); } } catch (Exception ex) { LogEventManager.Logger.Error(ex.Message, ex); throw; } }
public async Task <IResponse> AddPaymentMethodAsync(vmPaymentMethodCreateRequest newPaymentMethodRequest) { var response = new Response(); try { var duplicatePaymentMethod = await PaymentMethodRepository.GetSinglePaymentMethodByNameAsync(newPaymentMethodRequest.PaymentMethodName); if (duplicatePaymentMethod != null) { response.Message = ResponseMessageDisplay.Duplicate; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(PaymentMessageDisplay.PaymentMethodAlreadyExistedMessage, newPaymentMethodRequest.PaymentMethodName)); } else { var newPaymentMethod = _mapper.Map <vmPaymentMethodCreateRequest, PaymentMethod>(newPaymentMethodRequest); // Create new payment method await PaymentMethodRepository.AddPaymentMethodAsync(newPaymentMethod); response.Message = ResponseMessageDisplay.Success; } } catch (Exception ex) { response.SetError(ex); } return(response); }
public void Save() { try { var options = CreateNewContextOptions(); using (var db = new OrderContext(options)) { ProcessingTestHelper.PopulateDefaultOrderCtx(db); } using (var db = new OrderContext(options)) { var repository = new PaymentMethodRepository(db); var item = ProcessingTestHelper.GeneratePaymentMethod(); Assert.DoesNotThrow(() => repository.Save(item)); Assert.DoesNotThrow(() => repository.Delete(item)); Assert.Greater(item.Id, 0); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
/// <summary> /// Finds a user from the database and their associated registration if present /// </summary> /// <param name="id">The account ID of the user</param> /// <returns>A user object with populated registration</returns> public UserViewModel FindUser(int id) { var user = UserRepository.Find(id); //if the registration wasn't returned by the user repository then explicitly load from the //registration repository if (user.Registration == null) { user.Registration = RegistrationRepository.Find(user.AccountID); } //if the payment method wasn't returned by the user repository then explicitly load from the //registration repository if (user.PaymentMethod == null) { user.PaymentMethod = PaymentMethodRepository.Find(user.AccountID); } var viewModel = new UserViewModel(user); var openBooking = BookingRepository.FindByAccountId(user.AccountID) .FirstOrDefault(x => x.BookingStatus == Constants.BookingOpenStatus); if (openBooking != null) { viewModel.HasOpenBooking = true; viewModel.OpenBookingId = openBooking.BookingID; } return(viewModel); }
public void MakeTransferOrder() { try { var options = CreateNewContextOptions(); using (var db = new EntireMoneyProcessingContext(options)) { ProcessingTestHelper.PopulateDefaultMoneyCtx(db); } using (var db = new EntireMoneyProcessingContext(options)) { var repository = new SystemMoneyProcessing(db); // IocHelper.GetObject<ISystemMoneyProcessing>(db); var paymentRepository = new PaymentMethodRepository(db); //IocHelper.GetObject<IPaymentMethodRepository<int, DbContext, PaymentMethod, PaymentMethodFilter>>(db); var payment = paymentRepository.Get(new PaymentMethodFilter()).ToList() .Single(it => it.Code == "CREDITPAYMENT"); var userId = db.Set <User>().First().Id; Order result = null; Assert.DoesNotThrow(() => result = repository.MakeTransferOrder(userId, 500, new OperationType(), payment)); Assert.NotNull(result); } } catch (Exception ex) { LogEventManager.Logger.Error(ex); throw; } }
public async Task <IResponse> ToggleActivePaymentMethodAsync(int paymentMethodId, bool active) { var response = new Response(); try { var paymentMethodFromDB = await PaymentMethodRepository.GetSinglePaymentMethodByIDAsync(paymentMethodId); if (paymentMethodFromDB == null) { response.Message = ResponseMessageDisplay.NotFound; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(PaymentMessageDisplay.PaymentMethodNotFoundMessage)); } else { if (active) { await PaymentMethodRepository.ActivatePaymentMethodAsync(paymentMethodFromDB); } else { await PaymentMethodRepository.DeactivatePaymentMethodAsync(paymentMethodFromDB); } response.Message = ResponseMessageDisplay.Success; } } catch (Exception ex) { response.SetError(ex); } return(response); }
/// <summary> /// Constructor. /// </summary> /// <param name="shoppingService">Shopping service</param> /// <param name="addressRepository">Address repository</param> /// <param name="paymentMethodRepository">Payment method repository</param> /// <param name="shippingOptionRepository">Shipping option repository</param> /// <param name="countryRepository">Country repository</param> public CheckoutService(IShoppingService shoppingService, CustomerAddressRepository addressRepository, PaymentMethodRepository paymentMethodRepository, ShippingOptionRepository shippingOptionRepository, CountryRepository countryRepository) { mShoppingService = shoppingService; mPaymentMethodRepository = paymentMethodRepository; mShippingOptionRepository = shippingOptionRepository; mCountryRepository = countryRepository; mAddressRepository = addressRepository; }
public void Dispose() { Logger.Debug("UserService Disposed"); UserRepository?.Dispose(); RegistrationRepository?.Dispose(); BookingRepository?.Dispose(); PaymentMethodRepository?.Dispose(); }
public OrderPlacementManager() { _orderRepository = new OrderRepository(); _productRepository = new ProductRepository(); _countryRepository = new CountryRepository(); _paymentMethodsRepository = new PaymentMethodRepository(); _mapper = new OrderPlacementMapper(); }
public UnitOfWork(AppDbContext context) { _context = context; City = new CityRepository(_context); Region = new RegionRepository(_context); Bus = new BusRepository(_context); Fare = new FaresRepository(_context); AdminCity = new AdminCityRepository(_context); AdminRegion = new AdminRegionRepository(_context); Driver = new DriverRepository(_context); Status = new GenericRepository <Status, StatusDto>(_context); Route = new RouteRepository(_context); Schedule = new ScheduleRepository(_context); PaymentMethod = new PaymentMethodRepository(_context); }
public async Task <IListResponse <vmPaymentMethodListRequest> > GetListPaymentMethodAsync(int createdBy) { var response = new ListResponse <vmPaymentMethodListRequest>(); try { var listPaymentMethodFromDb = await PaymentMethodRepository.GetListPaymentMethodAsync(createdBy); response.Model = _mapper.Map <IEnumerable <PaymentMethod>, IEnumerable <vmPaymentMethodListRequest> >(listPaymentMethodFromDb); response.Message = ResponseMessageDisplay.Success; } catch (Exception ex) { response.SetError(ex); } return(response); }
public async Task <IResponse> UpdatePaymentMethodAsync(int paymentMethodID, vmPaymentMethodUpdateRequest updatePaymentMethodRequest) { var response = new Response(); try { var duplicatePaymentMethod = await PaymentMethodRepository.GetSinglePaymentMethodByNameAsync(updatePaymentMethodRequest.PaymentMethodName); if (duplicatePaymentMethod != null && duplicatePaymentMethod.PaymentMethodID != paymentMethodID) { response.Message = ResponseMessageDisplay.Duplicate; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(PaymentMessageDisplay.PaymentMethodAlreadyExistedMessage, updatePaymentMethodRequest.PaymentMethodName)); } else { var paymentMethodFromDB = await PaymentMethodRepository.GetSinglePaymentMethodByIDAsync(paymentMethodID); if (paymentMethodFromDB == null) { response.Message = ResponseMessageDisplay.NotFound; // Throw exception if duplicate existed throw new FamilyHubException(string.Format(PaymentMessageDisplay.PaymentMethodNotFoundMessage)); } else { _mapper.Map <vmPaymentMethodUpdateRequest, PaymentMethod>(updatePaymentMethodRequest, paymentMethodFromDB); await PaymentMethodRepository.UpdatePaymentMethodAsync(paymentMethodFromDB); response.Message = ResponseMessageDisplay.Success; } } } catch (Exception ex) { response.SetError(ex); } return(response); }
public SchemaRepositoryContainer() { #region Entity Repositories City = new CityRepository(); Cities_Archive = new Cities_ArchiveRepository(); Country = new CountryRepository(); Countries_Archive = new Countries_ArchiveRepository(); DeliveryMethod = new DeliveryMethodRepository(); DeliveryMethods_Archive = new DeliveryMethods_ArchiveRepository(); PaymentMethod = new PaymentMethodRepository(); PaymentMethods_Archive = new PaymentMethods_ArchiveRepository(); Person = new PersonRepository(); People_Archive = new People_ArchiveRepository(); StateProvince = new StateProvinceRepository(); StateProvinces_Archive = new StateProvinces_ArchiveRepository(); SystemParameter = new SystemParameterRepository(); TransactionType = new TransactionTypeRepository(); TransactionTypes_Archive = new TransactionTypes_ArchiveRepository(); #endregion // If not implemented this method is removed during compilation LoadCustomRepositories(); }
public PaymentMethodServices() { _paymentMethodRepository = new PaymentMethodRepository(); }
public PaymentMethodController(PaymentMethodRepository repository) { _repository = repository; }
public PaymentMethodService(PaymentMethodRepository repository) { _repository = repository; }
public PaymentMethodLogic() { _paymentRepository = new PaymentMethodRepository(); }
public void Init() { PaymentMethodRepository.Reset(); }
public AddPaymentMethodResponse AddPaymentMethod( AddPaymentMethodRequest request, int accountId) { //this class allows a user to create and edit their payment details var expiry = new DateTime(request.ExpiryYear, request.ExpiryMonth, DateTime.DaysInMonth(request.ExpiryYear, request.ExpiryMonth)); //find the user and validate if they exist var user = UserRepository.Find(accountId); if (user == null) { return new AddPaymentMethodResponse { Message = $"Account {accountId} does not exist", Success = false } } ; //validate that the user must be activated in the system first if (user.Status != Constants.UserActiveStatus) { return new AddPaymentMethodResponse { Message = "Only activated users can add payment methods", Success = false } } ; //validate that the card number entered and cvv is not empty if (string.IsNullOrEmpty(request.CardNumber) || string.IsNullOrEmpty(request.CardVerificationValue)) { return new AddPaymentMethodResponse { Message = "A credit card is required", Success = false } } ; request.CardNumber = request.CardNumber.Replace(" ", ""); //luhn check to validate that the entered card number is correct var sumOfDigits = request.CardNumber.Where( e => e >= '0' && e <= '9') .Reverse() .Select((e, i) => ((int)e - 48) * (i % 2 == 0 ? 1 : 2)) .Sum(e => e / 10 + e % 10); //if luhn check fails if (sumOfDigits % 10 != 0) { return new AddPaymentMethodResponse { Message = "The entered card number is invalid.", Success = false } } ; //if the card expiry exceeds the historic date if (DateTime.Now > expiry) { return new AddPaymentMethodResponse { Message = "The entered credit card has expired.", Success = false } } ; //calculate the card type string cardType; switch (request.CardNumber.Substring(0, 1)) { case "3": cardType = "AMEX"; break; case "4": cardType = "Visa"; break; case "5": cardType = "Mastercard"; break; default: cardType = "Mastercard"; break; } try { //if an existing payment method exists update the old one var existingPaymentMethod = PaymentMethodRepository.Find(accountId); if (existingPaymentMethod != null) { existingPaymentMethod.CardName = request.CardName; existingPaymentMethod.CardNumber = request.CardNumber; existingPaymentMethod.CardType = cardType; existingPaymentMethod.ExpiryMonth = request.ExpiryMonth; existingPaymentMethod.ExpiryYear = request.ExpiryYear; existingPaymentMethod.CardVerificationValue = request.CardVerificationValue; PaymentMethodRepository.Update(existingPaymentMethod); } else { //otherwise create a new payment method var payment = new PaymentMethod { AccountID = accountId, CardNumber = request.CardNumber, CardName = request.CardName, CardType = cardType, ExpiryMonth = request.ExpiryMonth, ExpiryYear = request.ExpiryYear, CardVerificationValue = request.CardVerificationValue }; PaymentMethodRepository.Add(payment); }; } catch (Exception e) { return(new AddPaymentMethodResponse { Message = $"Error in updating payment method. Error: {e}", Success = false }); } return(new AddPaymentMethodResponse { Success = true, Message = "Payment method has been successfull added!" }); }