示例#1
0
        public async Task <InitiateKycResponseModel> InitiateKycAsync(InitiateKycRequestModel requestModel)
        {
            var kycEntity = await _kycRepository.AddAsync(new KycEntity(requestModel.UserId, KycStatus.Initiated));

            var mrzSubmitRequest  = _mapper.Map <MrzSubmitRequest>(requestModel);
            var mrzSubmitResponse = _mrzProcessor.ProcessMrzFile(mrzSubmitRequest);

            kycEntity.Status = KycStatus.Queued;
            await _kycRepository.UpdateAsync(kycEntity);

            var responseModel = _mapper.Map <InitiateKycResponseModel>(requestModel);

            responseModel.KycId     = kycEntity.Id;
            responseModel.MrzTaskId = mrzSubmitResponse.TaskId;

            // Send Kafka Message
            var kafkaMessage = new KafkaMessage <string, InitiateKycResponseModel>
            {
                Key         = Guid.NewGuid().ToString(),
                Value       = responseModel,
                MessageType = nameof(InitiateKycResponseModel)
            };

            await _initiateKycProducer.ProduceAsync(kafkaMessage);

            return(responseModel);
        }
示例#2
0
        public async Task <ActionResult <InitiateKycResponse> > Initiate([FromForm] IFormFile file)
        {
            var userId = HttpContext.User.GetUserId();

            if (userId == null)
            {
                throw new UnauthorizedAccessException("'sub' claim is missing in token.");
            }

            var kycFolderPath = Path.Combine(Environment.CurrentDirectory, "kyc-documents");

            Directory.CreateDirectory(kycFolderPath);
            var path = Path.Combine(kycFolderPath, file.FileName);

            using (var fileStream = System.IO.File.Create(path))
            {
                await file.CopyToAsync(fileStream);
            }

            var model = new InitiateKycRequestModel
            {
                UserId   = userId.Value,
                FileName = file.FileName,
                FilePath = path
            };

            var result = await _kycService.InitiateKycAsync(model);

            var response = _mapper.Map <InitiateKycResponse>(result);

            return(Ok(response));
        }