Esempio n. 1
0
        private async ValueTask HandleEvents(ClientProfileUpdateMessage message)
        {
            try
            {
                _logger.LogInformation("Received profile update message for client {clientId}", message.NewProfile.ClientId);
                var profile = await _repository.GetOrCreateProfile(message.NewProfile.ClientId);

                var oldProfile = (KycProfile)profile.Clone();

                if (profile.PhoneVerified != message.NewProfile.PhoneConfirmed)
                {
                    profile.PhoneVerified = message.NewProfile.PhoneConfirmed;

                    await _statusSetter.UpdateProfileState(profile);

                    await _repository.UpdateProfile(profile, "Phone verification state update", "automatic", null);

                    await _publisher.PublishAsync(new KycProfileUpdatedMessage()
                    {
                        ClientId   = profile.ClientId,
                        OldProfile = oldProfile,
                        NewProfile = profile
                    });
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "When handling message from client profile service for client {clientId}", message.NewProfile.ClientId);
                throw;
            }
        }
        public async Task <OperationResponse> UploadDocument(UploadDocumentRequest request)
        {
            try
            {
                _logger.LogInformation("Uploading documents with type {type} for client {clientId}", request.Type, request.ClientId);
                var profile = await _repository.GetOrCreateProfile(request.ClientId);

                if (string.IsNullOrEmpty(profile.ApplicantId))
                {
                    _logger.LogInformation("Creating applicant id for client {clientId}", request.ClientId);
                    profile.ApplicantId = await _httpService.CreateApplicantId(request.ClientId);

                    await _repository.UpdateProfile(profile, "Created applicant id", "automatic", null);
                }

                var existingDocumentId = profile.Documents.FirstOrDefault(t => t.Type == request.Type)?.DocumentId;

                var(documentId, file1, file2) = await _httpService.UploadDocument(profile.ApplicantId, request.FileSide1,
                                                                                  request.FileSide2,
                                                                                  request.Type, request.FileType, existingDocumentId);

                await using var context = new DatabaseContext(_dbContextOptionsBuilder.Options);
                var document = new KycDocument()
                {
                    DocumentId    = documentId,
                    ClientId      = profile.ClientId,
                    Type          = request.Type,
                    FileId1       = file1,
                    FileId2       = file2,
                    Verified      = false,
                    DeclineReason = string.Empty
                };
                await context.UpsertAsync(new[] { document });

                context.AuditLogs.Add(KycAuditLog.Create(document, "Document upload", "automatic", null));
                await context.SaveChangesAsync();

                return(new OperationResponse()
                {
                    IsSuccess = true
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "When uploading document for clientId {clientId}", request.ClientId);
                return(new OperationResponse()
                {
                    IsSuccess = false,
                    Error = e.Message
                });
            }
        }
Esempio n. 3
0
        public async ValueTask <KycStatusResponse> GetKycStatusAsync(KycStatusRequest request)
        {
            var kycModel = await _repository.GetOrCreateProfile(request.ClientId);

            return(new KycStatusResponse(Program.Settings.DefaultBrokerId, kycModel));
        }