public async Task <string> ProcessSubmission(MappingEntity mappingEntity, string form, string sessionGuid) { if (_submissionServiceConfiguration.FakeSubmission) { _pageHelper.SaveCaseReference(sessionGuid, "123456"); return("123456"); } var reference = string.Empty; var currentPage = mappingEntity.BaseForm.GetPage(_pageHelper, mappingEntity.FormAnswers.Path); var submitSlug = currentPage.GetSubmitFormEndpoint(mappingEntity.FormAnswers, _environment.EnvironmentName.ToS3EnvPrefix()); _gateway.ChangeAuthenticationHeader(string.IsNullOrWhiteSpace(submitSlug.AuthToken) ? string.Empty : submitSlug.AuthToken); var response = await _gateway.PostAsync(submitSlug.URL, mappingEntity.Data); if (!response.IsSuccessStatusCode) { throw new ApplicationException($"SubmitService::ProcessSubmission, An exception has occurred while attempting to call {submitSlug.URL}, Gateway responded with {response.StatusCode} status code, Message: {JsonConvert.SerializeObject(response)}"); } if (response.Content != null) { var content = await response.Content.ReadAsStringAsync() ?? string.Empty; reference = JsonConvert.DeserializeObject <string>(content); } _pageHelper.SaveCaseReference(sessionGuid, reference); return(reference); }
private void HandlePopulatedCloseCaseEvent(EventCase model) { var selectCaseEvent = _eventTypeConfiguration.PopulatedCloseCaseEvent.FirstOrDefault(_ => string.Equals(_.Type, model.Classification.Type, StringComparison.OrdinalIgnoreCase)); if (selectCaseEvent == null) { return; } _gateway.ChangeAuthenticationHeader(selectCaseEvent.AuthToken); _gateway.PostAsync(selectCaseEvent.Endpoint, model); }
public async Task <string> ProcessPaymentResponse(string form, string responseCode, string reference) { var sessionGuid = _sessionHelper.GetSessionGuid(); var mappingEntity = await _mappingService.Map(sessionGuid, form); if (mappingEntity is null) { throw new Exception($"PayService:: No mapping entity found for {form}"); } var currentPage = mappingEntity.BaseForm.GetPage(_pageHelper, mappingEntity.FormAnswers.Path); var paymentInformation = await GetFormPaymentInformation(form); var postUrl = currentPage.GetSubmitFormEndpoint(mappingEntity.FormAnswers, _hostingEnvironment.EnvironmentName.ToS3EnvPrefix()); var paymentProvider = GetFormPaymentProvider(paymentInformation); if (string.IsNullOrWhiteSpace(postUrl.CallbackUrl)) { throw new ArgumentException("PayService::ProcessPaymentResponse, Callback url has not been specified"); } _gateway.ChangeAuthenticationHeader(postUrl.AuthToken); try { paymentProvider.VerifyPaymentResponse(responseCode); await _gateway.PostAsync(postUrl.CallbackUrl, new { CaseReference = reference, PaymentStatus = EPaymentStatus.Success.ToString() }); _pageHelper.SavePaymentAmount(sessionGuid, paymentInformation.Settings.Amount); return(reference); } catch (PaymentDeclinedException) { await _gateway.PostAsync(postUrl.CallbackUrl, new { CaseReference = reference, PaymentStatus = EPaymentStatus.Declined.ToString() }); throw new PaymentDeclinedException("PayService::ProcessPaymentResponse, PaymentProvider declined payment"); } catch (PaymentFailureException) { await _gateway.PostAsync(postUrl.CallbackUrl, new { CaseReference = reference, PaymentStatus = EPaymentStatus.Failure.ToString() }); throw new PaymentFailureException("PayService::ProcessPaymentResponse, PaymentProvider failed payment"); } catch (Exception ex) { _logger.LogError(ex, "The payment callback failed"); throw new Exception(ex.Message); } }
public async Task <List <BenefitsClaimSummary> > GetBenefits(string personReference) { var cacheResponse = await _cacheProvider.GetStringAsync($"{personReference}-{ECacheKeys.Benefits}"); if (!string.IsNullOrEmpty(cacheResponse)) { return(JsonConvert.DeserializeObject <List <BenefitsClaimSummary> >(cacheResponse)); } var sessionId = await _sessionProvider.GetSessionId(personReference); var url = _queryBuilder .Add("docid", "hbsel") .Add("sessionId", sessionId) .Build(); var body = new FormUrlEncodedContent(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("claimsts", "All") }); var response = await _gateway.PostAsync(url, body); var content = await response.Content.ReadAsStringAsync(); var parsedResponse = _xmlParser.DeserializeXmlStringToType <BenefitsClaimsSummaryResponse>(content, "HBSelectDoc"); var claimSummary = parsedResponse.Claims.Summary; claimSummary.ForEach(_ => _.PersonName = parsedResponse.PersonName); _ = _cacheProvider.SetStringAsync($"{personReference}-{ECacheKeys.Benefits}", JsonConvert.SerializeObject(claimSummary)); return(claimSummary); }
public async Task <string> PaymentSubmission(MappingEntity mappingEntity, string form, string sessionGuid) { if (_submissionServiceConfiguration.FakePaymentSubmission) { return("123456"); } var currentPage = mappingEntity.BaseForm.GetPage(_pageHelper, mappingEntity.FormAnswers.Path); var postUrl = currentPage.GetSubmitFormEndpoint(mappingEntity.FormAnswers, _environment.EnvironmentName.ToS3EnvPrefix()); if (string.IsNullOrEmpty(postUrl.URL)) { throw new ApplicationException($"SubmitService::PaymentSubmission, No submission URL has been provided for FORM: { form }, ENVIRONMENT: { _environment.EnvironmentName }"); } if (string.IsNullOrWhiteSpace(postUrl.AuthToken)) { _gateway.ChangeAuthenticationHeader(string.Empty); } else { _gateway.ChangeAuthenticationHeader(postUrl.AuthToken); } var response = await _gateway.PostAsync(postUrl.URL, mappingEntity.Data); if (!response.IsSuccessStatusCode) { throw new ApplicationException($"SubmitService::PaymentSubmission, An exception has occurred while attempting to call {postUrl.URL}, Gateway responded with {response.StatusCode} status code, Message: {JsonConvert.SerializeObject(response)}"); } if (response.Content is not null) { var content = await response.Content.ReadAsStringAsync(); if (string.IsNullOrWhiteSpace(content)) { throw new ApplicationException($"SubmitService::PaymentSubmission, Gateway {postUrl.URL} responded with empty reference"); } return(JsonConvert.DeserializeObject <string>(content)); } throw new ApplicationException($"SubmitService::PaymentSubmission, An exception has occured when response content from {postUrl} is null, Gateway responded with {response.StatusCode} status code, Message: {JsonConvert.SerializeObject(response)}"); }
private async Task ValidateRecaptcha(ActionExecutingContext context, string token) { var request = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("secret", _configuration.AuthToken), new KeyValuePair <string, string>("response", token) }); var response = await _gateway.PostAsync(_configuration.ApiVerificationEndpoint, request, false); if (response.Content is null) { AddModelError(context, "Unable To Read Response From Server"); _logger.LogWarning("ValidateReCaptchaAttribute:: ValidateReCaptcha:: Unable To Read Response From Server"); } else if (!response.IsSuccessStatusCode) { AddModelError(context, "Invalid reCaptcha"); _logger.LogWarning("ValidateReCaptchaAttribute:: ValidateReCaptcha:: Invalid reCaptcha"); } }
public async Task Process(List <IAction> actions, FormSchema formSchema, string formName) { var answers = new List <Answers>(); var sessionGuid = _sessionHelper.GetSessionGuid(); var mappingData = await _mappingService.Map(sessionGuid, formName); foreach (var action in actions) { var response = new HttpResponseMessage(); var submitSlug = action.Properties.PageActionSlugs.FirstOrDefault(_ => _.Environment.ToLower().Equals(_environment.EnvironmentName.ToS3EnvPrefix().ToLower())); if (submitSlug == null) { throw new ApplicationException("RetrieveExternalDataService::Process, there is no PageActionSlug defined for this environment"); } var entity = _actionHelper.GenerateUrl(submitSlug.URL, mappingData.FormAnswers); if (!string.IsNullOrEmpty(submitSlug.AuthToken)) { _gateway.ChangeAuthenticationHeader(submitSlug.AuthToken); } if (entity.IsPost) { response = await _gateway.PostAsync(entity.Url, mappingData.Data); } else { response = await _gateway.GetAsync(entity.Url); } if (!response.IsSuccessStatusCode) { throw new ApplicationException($"RetrieveExternalDataService::Process, http request to {entity.Url} returned an unsuccessful status code, Response: {JsonConvert.SerializeObject(response)}"); } if (response.Content == null) { throw new ApplicationException($"RetrieveExternalDataService::Process, response content from {entity.Url} is null."); } var content = await response.Content.ReadAsStringAsync(); if (string.IsNullOrWhiteSpace(content)) { throw new ApplicationException($"RetrieveExternalDataService::Process, Gateway {entity.Url} responded with empty reference"); } answers.Add(new Answers { QuestionId = action.Properties.TargetQuestionId, Response = JsonConvert.DeserializeObject <string>(content) }); } mappingData.FormAnswers.Pages.FirstOrDefault(_ => _.PageSlug.ToLower().Equals(mappingData.FormAnswers.Path.ToLower())).Answers.AddRange(answers); await _distributedCache.SetStringAsync(sessionGuid, JsonConvert.SerializeObject(mappingData.FormAnswers), CancellationToken.None); }
public async Task <HttpResponseMessage> PostAsync(MappingEntity mappingEntity, SubmitSlug submitSlug) => await _gateway.PostAsync(submitSlug.URL, mappingEntity.Data, submitSlug.Type, submitSlug.AuthToken);