public async Task <PaymentHistoryResponse> GetPaymentHistory(PaymentHistoryRequest request) { Logger.Log("Logging request"); var routeToDirectTo = GetRoute(request.BankId); if (!string.IsNullOrEmpty(routeToDirectTo)) { var result = await CallExternal.GetHistoryResult(request, routeToDirectTo); return(new PaymentHistoryResponse { MaskedCardNumber = result.MaskedCardNumber, Status = result.Status }); } Logger.LogError("unknown route"); return(new PaymentHistoryResponse { Status = PaymentResponseStatus.Failed, MaskedCardNumber = string.Empty }); }
public async Task <Result <List <PaymentHistoryData> > > GetAgentHistory(PaymentHistoryRequest paymentHistoryRequest, AgentContext agent) { var validationResult = Validate(paymentHistoryRequest); if (validationResult.IsFailure) { return(Result.Failure <List <PaymentHistoryData> >(validationResult.Error)); } var accountHistoryQuery = from account in _edoContext.AgencyAccounts join auditLogEntry in _edoContext.AccountBalanceAuditLogs on account.Id equals auditLogEntry.AccountId join booking in _edoContext.Bookings on auditLogEntry.ReferenceCode equals booking.ReferenceCode where account.AgencyId == agent.AgencyId && auditLogEntry.UserId == agent.AgentId && auditLogEntry.UserType == UserTypes.Agent && auditLogEntry.Created <= paymentHistoryRequest.ToDate && auditLogEntry.Created >= paymentHistoryRequest.FromDate select new PaymentHistoryData(auditLogEntry.Created, auditLogEntry.Amount, JObject.Parse(auditLogEntry.EventData), account.Currency.ToString(), auditLogEntry.UserId, ToPaymentHistoryType(auditLogEntry.Type), PaymentMethods.BankTransfer, booking.AccommodationName, booking.MainPassengerName, booking.Id, booking.ReferenceCode); var cardHistoryQuery = from auditLogEntry in _edoContext.CreditCardAuditLogs join booking in _edoContext.Bookings on auditLogEntry.ReferenceCode equals booking.ReferenceCode where booking.AgencyId == agent.AgencyId && auditLogEntry.UserId == agent.AgentId && auditLogEntry.UserType == UserTypes.Agent && auditLogEntry.Created <= paymentHistoryRequest.ToDate && auditLogEntry.Created >= paymentHistoryRequest.FromDate select new PaymentHistoryData(auditLogEntry.Created, auditLogEntry.Amount, JObject.Parse(auditLogEntry.EventData), auditLogEntry.Currency.ToString(), auditLogEntry.UserId, ToPaymentHistoryType(auditLogEntry.Type), PaymentMethods.CreditCard, booking.AccommodationName, booking.MainPassengerName, booking.Id, booking.ReferenceCode); return((await accountHistoryQuery.ToListAsync()) .Union(await cardHistoryQuery.ToListAsync()) .OrderByDescending(h => h.Created) .ToList()); }
public async Task <ActionResult <PaymentHistoryResponse> > Get([FromBody] PaymentHistoryRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } var resp = await _paymentProcessService.GetPaymentHistory(request); return(Ok(resp)); }
public async Task <IActionResult> GetAgencyHistory([FromBody] PaymentHistoryRequest historyRequest) { var agent = await _agentContextService.GetAgent(); var(_, isFailure, response, error) = await _paymentHistoryService.GetAgencyHistory(historyRequest, agent); if (isFailure) { return(BadRequest(error)); } return(Ok(response)); }
private Result Validate(PaymentHistoryRequest paymentHistoryRequest) { return(GenericValidator <PaymentHistoryRequest> .Validate(setup => { setup.RuleFor(i => i.ToDate) .GreaterThanOrEqualTo(request => request.FromDate) .WithMessage($"{nameof(paymentHistoryRequest.ToDate)} must be greater then {nameof(paymentHistoryRequest.FromDate)}"); setup.RuleFor(i => (i.ToDate - i.FromDate).Days) .LessThanOrEqualTo(MaxRequestDaysNumber) .WithMessage( $"Total days between {nameof(paymentHistoryRequest.FromDate)} and {nameof(paymentHistoryRequest.ToDate)} should be less or equal {MaxRequestDaysNumber}"); }, paymentHistoryRequest)); }
public void Should_Be_Able_To_Get_History_From_Bank_One() { var externalCallMock = new Mock <ICallExternal>(); var loggerMock = new Mock <ILogger>(); Guid transId = Guid.NewGuid(); var expectedResult = new ExternalHistoryResult { Status = PaymentResponseStatus.Accepted, MaskedCardNumber = "54xxx-54654-xxxx" }; var req = new PaymentHistoryRequest { BankId = _bank1Id, PaymentResponseId = transId }; externalCallMock.Setup(x => x.GetHistoryResult(req, It.IsAny <string>())).Returns(Task.FromResult <IHistoryResult>(expectedResult)); var paymentProcessService = new PaymentProcessService(loggerMock.Object, externalCallMock.Object); //act var response = paymentProcessService.GetPaymentHistory(req).Result; //verify Assert.NotNull(response); Assert.Equal((PaymentResponseStatus)expectedResult.Status, response.Status); Assert.Equal(expectedResult.MaskedCardNumber, response.MaskedCardNumber); loggerMock.Verify(x => x.Log(It.IsAny <string>()), Times.Once); }
public Task <IHistoryResult> GetHistoryResult(PaymentHistoryRequest request, string clientEndpoint) { //call endpoint throw new NotImplementedException(); }