internal async Task <TierUpgradeRequest> GetUpgradeRequestAsync(string clientId, string country) { IReadOnlyList <ITierUpgradeRequest> tierUpgradeRequests = await _tierUpgradeService.GetByClientAsync(clientId); var rejectedRequest = tierUpgradeRequests .OrderBy(x => x.Tier) .FirstOrDefault(x => x.KycStatus != KycStatus.Ok && x.KycStatus != KycStatus.Pending); var lastPendingRequest = tierUpgradeRequests .Where(x => x.KycStatus != KycStatus.Ok) .OrderByDescending(x => x.Tier) .FirstOrDefault(); var tier = rejectedRequest?.Tier ?? lastPendingRequest?.Tier ?? null; double limit = 0; if (tier != null) { LimitSettings limitSettings = await _limitsService.GetClientLimitSettingsAsync(clientId, tier.Value, country); limit = limitSettings?.MaxLimit ?? 0; } if (rejectedRequest != null) { return(new TierUpgradeRequest { Tier = rejectedRequest.Tier, Status = rejectedRequest.KycStatus.ToString(), SubmitDate = rejectedRequest.Date, Limit = limit }); } if (lastPendingRequest != null) { return(new TierUpgradeRequest { Tier = lastPendingRequest.Tier, Status = lastPendingRequest.KycStatus.ToString(), SubmitDate = lastPendingRequest.Date, Limit = limit }); } return(null); }
public async Task Handle(KycStatusChangedEvent evt) { Enum.TryParse(evt.NewStatus, out KycStatus status); var upgradeRequests = await _tierUpgradeService.GetByClientAsync(evt.ClientId); var request = upgradeRequests .OrderBy(x => x.Tier) .FirstOrDefault(x => x.KycStatus != KycStatus.Ok); var requestStatus = GetTierStatus(status); if (request != null && request.KycStatus != requestStatus) { await _tierUpgradeService.AddAsync(evt.ClientId, request.Tier, requestStatus, nameof(KycStatusChangedProjection)); } }
public async Task <IReadOnlyList <TierUpgradeRequestResponse> > GetByClientAsync(string clientId) { var result = await _tierUpgradeService.GetByClientAsync(clientId); return(_mapper.Map <List <TierUpgradeRequestResponse> >(result)); }