Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        public async Task Process(List <IAction> actions, FormSchema formSchema, string formName)
        {
            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("ValidateService::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);
                }

                response = await _gateway.GetAsync(entity.Url);

                if (!response.IsSuccessStatusCode)
                {
                    throw new ApplicationException($"ValidateService::Process, http request to {entity.Url} returned an unsuccessful status code, Response: {JsonConvert.SerializeObject(response)}");
                }
            }
        }
Exemplo n.º 5
0
        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)}");
        }
        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);
        }