public async Task <IActionResult> SmsConfirmCode([FromBody] SmsConfirmCodeRequest model) { SmsRequestResult result = await _confirmationCodesService.RequestSmsCode(new SmsCodeRequest { ClientId = model.ClientId, PhoneNumber = model.Phone, Operation = model.Operation }); return(Ok(new SmsConfirmationResponse { Status = result.Status })); }
public async Task <SmsRequestResult> RequestSmsCode(SmsCodeRequest request) { var callLimitsResult = await _callTimeLimitsService.ProcessCallLimitsAsync(request.ClientId, request.Operation); if (callLimitsResult.Status != CallLimitStatus.Allowed) { return(SmsRequestResult.FailedResult(callLimitsResult.Status)); } var smsSettings = await _clientAccountService.GetSmsAsync(request.ClientId); //if there were some precedent calls in prev. 5 mins - we should try another SMS provider var useAlternativeProvider = callLimitsResult.CallDates.Any() ? !smsSettings.UseAlternativeProvider : smsSettings.UseAlternativeProvider; await _clientAccountService.SetSmsAsync(request.ClientId, useAlternativeProvider); ISmsVerificationCode smsCode; //todo: refactor if if (request.IsPriority) { var expDate = DateTime.UtcNow.AddSeconds(_supportToolsSettings.PriorityCodeExpirationInterval); smsCode = await _smsVerificationCodeRepository.CreatePriorityAsync(request.PartnerId, request.PhoneNumber, expDate); } else { smsCode = await _smsVerificationCodeRepository.CreateAsync(request.PartnerId, request.PhoneNumber, _deploymentSettings.IsProduction); } await _smsRequestProducer.SendSmsAsync(request.PartnerId, request.PhoneNumber, new SmsConfirmationData { ConfirmationCode = smsCode.Code }, smsSettings.UseAlternativeProvider); return(SmsRequestResult.SuccessResult(smsCode.Code)); }