public async Task <IBuildDirectDebitPlanOverviewVmValidationResult> ValidateAndBuild(
            IUserIdentity loggedInUser, IApplicationSessionState applicationSessionState, Guid lowellReferenceSurrogateKey,
            PaymentOptionsVm paymentOptionsVmWithUserEntries, DirectDebitDetailsVm directDebitDetailsVmWithUserEntries, string caseflowUserId)
        {
            //
            // Payment Options - reconstruct from CaseFlow, populate user entris  and validate clean
            //

            PaymentOptionsVm paymentOptionsVm = await _buildPaymentOptionsVmService.Build(loggedInUser, applicationSessionState, lowellReferenceSurrogateKey, caseflowUserId);

            _buildPaymentOptionsVmService.UpdateFieldsFromUserEntries(loggedInUser, paymentOptionsVm, paymentOptionsVmWithUserEntries);

            if (!_paymentOptionsVmValidatorProcess.Validate(paymentOptionsVm))
            {
                return new ValidationResult()
                       {
                           IsValid = false
                       }
            }
            ;

            //
            // Direct Debit Details - reconstruct from fresh payment options, populate user entris and validate clean
            //
            DirectDebitDetailsVm directDebitDetailsVm = _buildDirectDebitDetailsVmService.Build(paymentOptionsVm);

            _buildDirectDebitDetailsVmService.UpdateFieldsFromUserEntries(directDebitDetailsVm, directDebitDetailsVmWithUserEntries);

            if (!_directDebitDetailsVmValidatorProcess.Validate(directDebitDetailsVm))
            {
                return new ValidationResult()
                       {
                           IsValid = false
                       }
            }
            ;

            //
            // Return valid result with overview built clean
            //
            return(new ValidationResult()
            {
                IsValid = true,
                DirectDebitPlanOverviewVm = Build(paymentOptionsVm, directDebitDetailsVm)
            });
        }
    }
}
Ejemplo n.º 2
0
        public async Task <IActionResult> Index(Guid id)
        {
            var paymentOptionsVm = await _buildPaymentOptionsVmService.Build(
                LoggedInUser, ApplicationSessionState, id, GetCaseflowUserId());

            if (TempData.ContainsKey("GTMEvents"))
            {
                paymentOptionsVm.GtmEvents = JsonConvert.DeserializeObject <List <GtmEvent> >(TempData["GTMEvents"].ToString());
            }

            _gtmService.RaisePaymentEvent_PageVisited(paymentOptionsVm, LoggedInUserId, "Regular Account");

            // Save initial state in 'State' field, so that it can be reconstructed on postback
            // Field values lost due to a lack of hidden fields etc. will be retained this way
            paymentOptionsVm.InitialState = SerialiseModel(paymentOptionsVm);

            return(View(paymentOptionsVm));
        }
        // Checks the information entered by the user against CaseFlow afresh
        // If validation fails, returns false and OneOffPaymentReviewVm will be output as NULL
        // If successful, returns true and OneOffPaymentReviewVm will be output populated
        public async Task <IBuildOneOffPaymentReviewVmValidationResult> ValidateAndBuild(
            IUserIdentity loggedInUser, IApplicationSessionState applicationSessionState,
            Guid lowellReferenceSurrogateKey, PaymentOptionsVm paymentOptionsVmWithUserEntries, string caseflowUserId)
        {
            // Reload from CaseFlow
            PaymentOptionsVm paymentOptionsVm =
                await _buildPaymentOptionsVmService.Build(loggedInUser, applicationSessionState, lowellReferenceSurrogateKey, caseflowUserId);

            // Populate user entries, giving a clean model to validate
            _buildPaymentOptionsVmService.UpdateFieldsFromUserEntries(loggedInUser, paymentOptionsVm, paymentOptionsVmWithUserEntries);

            if (!_paymentOptionsVmValidatorProcess.Validate(paymentOptionsVm))
            {
                return new ValidationResult()
                       {
                           IsValid = false
                       }
            }
            ;

            // Ensure we are not using this - must use clean, validated model (defensive coding)
            // ReSharper disable once RedundantAssignment
            paymentOptionsVmWithUserEntries = null;

            var postDataXml = _verifonePaymentProviderService.CreatePayload(paymentOptionsVm);

            OneOffPaymentReviewVm vm = new OneOffPaymentReviewVm()
            {
                LowellReference         = paymentOptionsVm.LowellReference,
                ClientName              = paymentOptionsVm.ClientName,
                VerifoneUrl             = _verifoneSetting.ApiEndpoint,
                VerifonePostDataXml     = postDataXml,
                VerifoneTransactionGuid = paymentOptionsVm.VerifoneTransactionGuid.ToString(),
                UserID            = loggedInUser.UserId,
                PaidInFull        = paymentOptionsVm.SelectedPaymentOption == PaymentOptionsSelectionsVm.Values.FullPayment,
                DiscountAvailable = paymentOptionsVm.DiscountBalanceAvailable,
                DiscountSelected  = paymentOptionsVm.DiscountAccepted,
                PlanInPlace       = paymentOptionsVm.PlanInPlace,
                InArrears         = !String.IsNullOrEmpty(paymentOptionsVm.ArrearsMessage)
            };

            // Source payment information from appropriate nested object
            if (paymentOptionsVm.SelectedPaymentOption == PaymentOptionsSelectionsVm.Values.FullPayment)
            {
                vm.PaymentAmount = paymentOptionsVm.FullPaymentAmountDerived;

                vm.SourceOfFunds      = paymentOptionsVm.FullPaymentSelectedSourceOfFunds;
                vm.SourceOfFundsOther = paymentOptionsVm.FullPaymentSourceOfFundsOtherText;
                vm.PaidInFull         = true;
            }
            else if (paymentOptionsVm.SelectedPaymentOption == PaymentOptionsSelectionsVm.Values.PartialPayment)
            {
                Debug.Assert(paymentOptionsVm.PartialPaymentAmount != null, "paymentOptionsVmWithUserEntries.PartialPaymentAmount != null");

                vm.PaymentAmount      = paymentOptionsVm.PartialPaymentAmount.Value;
                vm.SourceOfFunds      = paymentOptionsVm.PartialPaymentSelectedSourceOfFunds;
                vm.SourceOfFundsOther = paymentOptionsVm.PartialPaymentSourceOfFundsOtherText;
            }
            else
            {
                throw new ApplicationException("Invalid SelectedPaymentOption");
            }

            return(new ValidationResult()
            {
                IsValid = true, OneOffPaymentReviewVm = vm
            });
        }
    }