Example #1
0
        public async Task <IActionResult> DirectDebitComplete(Guid id,
                                                              DirectDebitDetailsStateVm directDebitDetailsStateVm)
        {
            var directDebitDetailsVm =
                DeserialiseModel <DirectDebitDetailsVm>(directDebitDetailsStateVm.FilledInState);
            var paymentOptionsVm =
                DeserialiseModel <PaymentOptionsVm>(directDebitDetailsVm
                                                    .PaymentOptionsFilledInState);

            Debug.Assert(directDebitDetailsVm.InitialState == null,
                         "Serialisation Loop Detected - a previous step must have serialised a model that already contains InitialState");
            Debug.Assert(paymentOptionsVm.InitialState == null,
                         "Serialisation Loop Detected - a previous step must have serialised a model that already contains InitialState");

            //
            // IMPORTANT: Validates models again versus CaseFlow, to ensure no tamper or state changes since
            // started process of entering payment information
            //
            DirectDebitPlanOverviewVm directDebitPlanOverview;

            {
                var result = await _buildDirectDebitPlanOverviewVmService.ValidateAndBuild(
                    LoggedInUser, ApplicationSessionState, id, paymentOptionsVm, directDebitDetailsVm, GetCaseflowUserId());

                if (result.IsValid == false)
                {
                    return(View("ValidationFailed"));
                }

                directDebitPlanOverview = result.DirectDebitPlanOverviewVm;
                directDebitPlanOverview.UserLoggedIn = !string.IsNullOrEmpty(LoggedInUserId);
            }

            if (ApplicationSessionState.LogSetUpPlanResult)
            {
                if (directDebitDetailsVm.DiscountSelected)
                {
                    await LogDiscountDirectDebitCompleteSuccess(paymentOptionsVm);
                }
                else
                {
                    await LogDirectDebitCompleteSuccess(paymentOptionsVm);
                }

                await _directDebitPlanSetupService.CreateDirectDebitPlan(directDebitPlanOverview);

                _gtmService.RaiseDirectDebitEvent_PlanSetUp(directDebitPlanOverview, LoggedInUserId,
                                                            "Direct Debit Plan");
                ApplicationSessionState.LogSetUpPlanResult = false;
            }

            return(View(directDebitPlanOverview));
        }