public async Task AddKycInfoAsync(KycInformation model) { if (model.PartnerId == Guid.Empty || model.AdminUserId == Guid.Empty) { _log.Warning("Request to add KycInfo with empty partner or admin id", context: model); return; } model.Timestamp = DateTime.UtcNow; model.KycStatus = KycStatus.Pending; await _kycInformationRepository.AddIfNotExistsAsync(model); }
public async Task <UpdateKycStatusErrorCode> UpdateKycInfoAsync(KycInformation model) { if (model.KycStatus == KycStatus.Rejected && string.IsNullOrEmpty(model.Comment)) { return(UpdateKycStatusErrorCode.CommentRequired); } var current = await _kycInformationRepository.GetByPartnerId(model.PartnerId); if (current == null) { return(UpdateKycStatusErrorCode.KycDoesNotExist); } model.Timestamp = DateTime.UtcNow; switch (current.KycStatus) { case KycStatus.Pending when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.InReview when model.KycStatus != KycStatus.Accepted && model.KycStatus != KycStatus.Rejected && model.KycStatus != KycStatus.RequiresData: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.Rejected when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.Rejected when model.KycStatus == KycStatus.InReview: _log.Warning("Returning KYC from Rejected to InReview", context: model); break; case KycStatus.Accepted when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.Accepted when model.KycStatus == KycStatus.InReview: _log.Warning("Returning KYC from Accepted to InReview", context: model); break; case KycStatus.RequiresData when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); } await _kycInformationRepository.UpdateAsync(model); return(UpdateKycStatusErrorCode.None); }
public async Task <UpdateKycStatusErrorCode> UpdateKycInfoAsync(KycInformation model) { if (model.KycStatus == KycStatus.Rejected && string.IsNullOrEmpty(model.Comment)) { return(UpdateKycStatusErrorCode.CommentRequired); } var current = await _kycInformationRepository.GetByPartnerId(model.PartnerId); if (current == null) { return(UpdateKycStatusErrorCode.KycDoesNotExist); } model.Timestamp = DateTime.UtcNow; switch (current.KycStatus) { case KycStatus.Pending when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.InReview when model.KycStatus != KycStatus.Accepted && model.KycStatus != KycStatus.Rejected && model.KycStatus != KycStatus.RequiresData: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.Rejected when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.Rejected when model.KycStatus == KycStatus.InReview: _log.Warning("Returning KYC from Rejected to InReview", context: model); break; case KycStatus.Accepted when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); case KycStatus.Accepted when model.KycStatus == KycStatus.InReview: _log.Warning("Returning KYC from Accepted to InReview", context: model); break; case KycStatus.RequiresData when model.KycStatus != KycStatus.InReview: return(UpdateKycStatusErrorCode.InvalidStatus); } await _kycInformationRepository.UpdateAsync(model); if (model.KycStatus != KycStatus.Accepted && model.KycStatus != KycStatus.Rejected) { return(UpdateKycStatusErrorCode.None); } var partner = await _partnerManagementClient.Partners.GetByIdAsync(model.PartnerId); if (partner == null) { _log.Warning("Missing partner when trying to send KYC notification", context: model.PartnerId); return(UpdateKycStatusErrorCode.None); } var admin = await _adminManagementClient.AdminsApi.GetByIdAsync( new GetAdminByIdRequestModel { AdminUserId = partner.CreatedBy.ToString() }); if (admin.Error != AdminUserResponseErrorCodes.None || admin.Profile == null) { _log.Warning("Missing admin when trying to send KYC notification", context: new { PartnerAdminId = partner.CreatedBy }); return(UpdateKycStatusErrorCode.None); } if (model.KycStatus == KycStatus.Accepted) { await _notificationsService.NotifyKycApprovedAsync(admin.Profile.AdminUserId, admin.Profile.Email, admin.Profile.FirstName, partner.Name); } else { await _notificationsService.NotifyKycRejectedAsync(admin.Profile.AdminUserId, admin.Profile.Email, admin.Profile.FirstName, partner.Name, model.Comment); } return(UpdateKycStatusErrorCode.None); }