public KycStatusResponse GetClientKycStatus(KycStatusRequest request) { var existingEntity = _readerKycStatuses.Get( KycProfileNoSqlEntity.GeneratePartitionKey(), KycProfileNoSqlEntity.GenerateRowKey(request.ClientId)); if (existingEntity != null) { return(new KycStatusResponse { ClientId = existingEntity.Profile.ClientId, Level = existingEntity.Profile.KycLevel, RequiredDocuments = KycLevelHelper.GetRequiredDocuments(existingEntity.Profile), RequiredVerifications = existingEntity.Profile.RequiredVerifications, DepositStatus = existingEntity.Profile.DepositStatus, TradeStatus = existingEntity.Profile.TradeStatus, WithdrawalStatus = existingEntity.Profile.WithdrawalStatus, VerificationInProgress = !string.IsNullOrEmpty(existingEntity.Profile.ActiveVerificationId) }); } var entity = _kycStatusService.GetKycStatusAsync(new KycStatusRequest() { ClientId = request.ClientId }).Result; return(entity); }
public KycStatusResponse(string brokerId, KycProfile profile) { BrokerId = brokerId; ClientId = profile.ClientId; Level = profile.KycLevel; RequiredDocuments = KycLevelHelper.GetRequiredDocuments(profile); RequiredVerifications = profile.RequiredVerifications; DepositStatus = profile.DepositStatus; WithdrawalStatus = profile.WithdrawalStatus; TradeStatus = profile.TradeStatus; VerificationInProgress = string.IsNullOrEmpty(profile.ActiveVerificationId); Pep = profile.Pep; Country = profile.Country; BlockingReason = profile.BlockingReason; }
public async Task <OperationResponse> StartVerification(StartVerificationRequest request) { try { _logger.LogInformation("Starting verification for client {clientId}", request.ClientId); var profile = await _repository.GetOrCreateProfile(request.ClientId); if (string.IsNullOrEmpty(profile.ApplicantId)) { _logger.LogWarning("Client {clientId} does not have applicant id. Check was started before uploading documents", profile.ClientId); return(new OperationResponse() { IsSuccess = false, Error = $"Client {request.ClientId} does not have applicant id" }); } if (profile.DepositStatus == KycOperationStatus.Blocked || profile.TradeStatus == KycOperationStatus.Blocked || profile.WithdrawalStatus == KycOperationStatus.Blocked) { _logger.LogWarning("Client {clientId} is blocked. Kyc verification not started", profile.ClientId); return(new OperationResponse() { IsSuccess = false, Error = $"Client {request.ClientId} is blocked" }); } if (!string.IsNullOrWhiteSpace(profile.ActiveVerificationId)) { _logger.LogWarning("Client {clientId} has active verification. New kyc verification not started", profile.ClientId); return(new OperationResponse() { IsSuccess = false, Error = $"Client {request.ClientId} has active verification" }); } if (profile.DepositStatus == KycOperationStatus.Allowed || profile.TradeStatus == KycOperationStatus.Allowed || profile.WithdrawalStatus == KycOperationStatus.Allowed) { _logger.LogWarning("Client {clientId} is already verified. Kyc verification not started", profile.ClientId); return(new OperationResponse() { IsSuccess = false, Error = $"Client {request.ClientId} is already verified" }); } var oldProfile = (KycProfile)profile.Clone(); var types = KycLevelHelper.GetVerificationsList(profile); var verificationId = await _httpService.StartVerification(profile.ApplicantId, types); profile.ActiveVerificationId = verificationId; await _statusSetter.UpdateProfileState(profile); await _repository.UpdateProfile(profile, "Verification started", "automatic", null); await _publisher.PublishAsync(new KycProfileUpdatedMessage() { ClientId = request.ClientId, OldProfile = oldProfile, NewProfile = profile }); await using var context = new DatabaseContext(_dbContextOptionsBuilder.Options); context.Verifications.Add(new Verification { VerificationId = verificationId, ClientId = profile.ClientId, VerificationTypes = String.Join(';', types), StartingTime = DateTime.UtcNow, }); await context.SaveChangesAsync(); return(new OperationResponse() { IsSuccess = true }); } catch (Exception e) { _logger.LogError(e, "When starting verification for clientId {clientId}", request.ClientId); return(new OperationResponse() { IsSuccess = false, Error = e.Message }); } }