Exemple #1
0
        public IActionResult Cancel(Guid id, AmendDirectDebitVm amendDirectDebitVmPostedBack)
        {
            // Restore VM from state field, so that we get lists and all other fields required to build view
            var amendDirectDebitVm = DeserialiseModel <AmendDirectDebitVm>(amendDirectDebitVmPostedBack.InitialState);

            Debug.Assert(amendDirectDebitVm.InitialState == null,
                         "Serialisation Loop Detected - InitialState should be marked as JsonIgnore");

            // Carry state through
            amendDirectDebitVm.InitialState = amendDirectDebitVmPostedBack.InitialState;

            // Place form field selections into restored VM
            _buildAmendDirectDebitVmService.UpdateFieldsFromUserEntries(amendDirectDebitVm,
                                                                        amendDirectDebitVmPostedBack);

            // Construct model for Cancel view
            var cancelVm = new ReturnToFormVm
            {
                State                = SerialiseModel(amendDirectDebitVm),
                StateFieldName       = nameof(AmendDirectDebitStateVm.FilledInState),
                StateType            = nameof(AmendDirectDebitVm),
                ReturnControllerName = ControllerName,
                ReturnActionName     = nameof(Change)
            };

            return(View("PaymentCancel", cancelVm));
        }
Exemple #2
0
        // Simple check to see if model is valid
        // This is only used for final validation to detect account changes or tampering
        // therefore does not need to feed back errors to user
        public bool Validate(AmendDirectDebitVm directDebitVm)
        {
            AmendDirectDebitVmValidator validator = new AmendDirectDebitVmValidator();
            ValidationResult            result    = validator.Validate(directDebitVm);

            return(result.IsValid);
        }
 public void UpdateFieldsFromUserEntries(AmendDirectDebitVm amendDirectDebitToUpdate, AmendDirectDebitVm amendDirectDebitUserEntries)
 {
     amendDirectDebitToUpdate.PlanFrequency           = _directDebitFrequencyTranslator.TranslateClientScriptCompatibleValueToDescription(amendDirectDebitUserEntries.PlanFrequency);
     amendDirectDebitToUpdate.PlanStartDate           = amendDirectDebitUserEntries.PlanStartDate;
     amendDirectDebitToUpdate.DirectDebitAmount       = amendDirectDebitUserEntries.DirectDebitAmount;
     amendDirectDebitToUpdate.SelectedPlanSetupOption = amendDirectDebitUserEntries.SelectedPlanSetupOption;
 }
        public async Task <AmendDirectDebitVm> Build(IApplicationSessionState session, Guid lowellReferenceSurrogateKey, string caseflowUserId)
        {
            string lowellReference = session.GetLowellReferenceFromSurrogate(lowellReferenceSurrogateKey);
            AccountReferenceDto accountReferenceDto = new AccountReferenceDto {
                LowellReference = lowellReference
            };
            var currentDirectDebit = await _getCurrentDirectDebitProcess.GetCurrentDirectDebit(accountReferenceDto);

            IncomeAndExpenditureApiModel incomeAndExpenditureDto = await _apiGatewayProxy.GetIncomeAndExpenditure(lowellReference);

            var workingAccounts = 0;

            if (caseflowUserId != null)
            {
                List <AccountSummary> accounts = await _accountService.GetAccounts(caseflowUserId);

                workingAccounts = accounts.Count(a => !a.AccountStatusIsClosed);
            }

            PaymentOptionsDto paymentOptionsDto = await _apiGatewayProxy.GetPaymentOptions(accountReferenceDto);

            var obj = new AmendDirectDebitVm
            {
                LowellReference    = currentDirectDebit.LowellReference,
                ClientName         = currentDirectDebit.ClientName,
                OutstandingBalance = currentDirectDebit.OutstandingBalance,
                DirectDebitAmount  = null,
                PlanType           = currentDirectDebit.PlanType,
                EarliestStartDate  = currentDirectDebit.EarliestInstalmentDate,
                LatestStartDate    = currentDirectDebit.LatestPlanSetupDate,
                PlanStartDate      = currentDirectDebit.EarliestInstalmentDate,
                DiscountedBalance  = currentDirectDebit.DiscountedBalance,
                DiscountAmount     = currentDirectDebit.DiscountAmount,
                DiscountExpiry     = currentDirectDebit.DiscountExpiry,
                DiscountPercentage = currentDirectDebit.DiscountPercentage,
                DiscountedBalancePreviouslyAccepted = paymentOptionsDto.DiscountedBalancePreviouslyAccepted,
                Frequency                    = _buildFrequencyListProcess.BuildFrequencyList(currentDirectDebit.DirectDebitFrequencies),
                IandENotAvailable            = incomeAndExpenditureDto == null,
                IandELessThanOrIs12MonthsOld = (incomeAndExpenditureDto != null && incomeAndExpenditureDto.Created.AddMonths(12).Date >= DateTime.Now.Date),
                AverageMonthlyPayment        = _portalSetting.AverageMonthlyPaymentAmount,
                MonthlyDisposableIncome      = (incomeAndExpenditureDto == null ? 0 :
                                                (incomeAndExpenditureDto.DisposableIncome * (_portalSetting.MonthlyDisposableIncomePlanSetupPercentage / 100)))
            };

            obj.AccountCount = workingAccounts;

            if (workingAccounts > 1)
            {
                obj.MonthlyDisposableIncomePerAccount =
                    obj.MonthlyDisposableIncome / workingAccounts;
            }
            else
            {
                obj.MonthlyDisposableIncomePerAccount = obj.MonthlyDisposableIncome;
            }

            return(obj);
        }
Exemple #5
0
        private async Task LogAmendDirectDebitCompleteFailure(AmendDirectDebitVm paymentOptionsVm)
        {
            if (paymentOptionsVm.SelectedPlanSetupOption.HasValue)
            {
                switch (paymentOptionsVm.SelectedPlanSetupOption.Value)
                {
                case PlanSetupOptions.AverageSetupValue:
                {
                    await _webActivityService.LogAmendDirectDebitPaymentASVOptionCompleteFailed(
                        paymentOptionsVm.LowellReference,
                        LoggedInUserId);

                    break;
                }

                case PlanSetupOptions.DisposableIncome:
                {
                    await _webActivityService.LogAmendDirectDebitDIOptionCompleteFailed(
                        paymentOptionsVm.LowellReference,
                        LoggedInUserId);

                    break;
                }

                case PlanSetupOptions.OtherPaymentOffer:
                {
                    if (paymentOptionsVm.IandENotAvailable || !paymentOptionsVm.IandELessThanOrIs12MonthsOld)
                    {
                        await _webActivityService.LogAmendDirectDebitMyOfferOptionCompleteFailedWithNoIandE(
                            paymentOptionsVm.LowellReference,
                            LoggedInUserId);
                    }
                    else if (paymentOptionsVm.MonthlyDisposableIncome > 0)
                    {
                        await _webActivityService.LogAmendDirectDebitMyOfferOptionCompleteFailedWithPositiveIandE(
                            paymentOptionsVm.LowellReference,
                            LoggedInUserId);
                    }
                    else
                    {
                        await _webActivityService.LogAmendDirectDebitMyOfferOptionCompleteFailedWithNegativeIandE(
                            paymentOptionsVm.LowellReference,
                            LoggedInUserId);
                    }

                    break;
                }
                }
            }
        }
Exemple #6
0
        //
        // Private
        //
        private async Task <IActionResult> ProcessPost(Guid id, AmendDirectDebitVm amendDirectDebitVmPostedBack)
        {
            if (!ModelState.IsValid)
            {
                if (amendDirectDebitVmPostedBack.SelectedPlanSetupOption == PlanSetupOptions.AverageSetupValue ||
                    amendDirectDebitVmPostedBack.SelectedPlanSetupOption == PlanSetupOptions.DisposableIncome)
                {
                    if (amendDirectDebitVmPostedBack.DirectDebitAmount >
                        amendDirectDebitVmPostedBack.OutstandingBalance)
                    {
                        ModelState.Clear();
                        var initialVm = DeserialiseModel <AmendDirectDebitVm>(amendDirectDebitVmPostedBack.InitialState);
                        amendDirectDebitVmPostedBack.DirectDebitAmount = initialVm.DirectDebitAmount;
                        ModelState.AddModelError(nameof(AmendDirectDebitVm.SelectedPlanSetupOption),
                                                 $"{ValidationMessages.AmountGreaterThenAllowed}{amendDirectDebitVmPostedBack.OutstandingBalance}");
                    }
                }

                Debug.Assert(amendDirectDebitVmPostedBack.InitialState != null,
                             "Initial state must be stashed to re-create view on round-trip");
                return(View(amendDirectDebitVmPostedBack));
            }

            _gtmService.RaiseAmendDirectDebitEvent_DetailsSelected(amendDirectDebitVmPostedBack, LoggedInUserId);
            ApplicationSessionState.LogSetUpPlanResult = true;

            var totalMonths = _amendDirectDebitPlanService.CalculateTermInMonths(
                amendDirectDebitVmPostedBack.DerivedBalance, amendDirectDebitVmPostedBack.DirectDebitAmount.Value,
                amendDirectDebitVmPostedBack.PlanFrequency);
            var years  = totalMonths / 12;
            var months = totalMonths % 12;

            var amendDirectDebitConfirmVm = new AmendDirectDebitConfirmVm
            {
                // Stash filled in form, as other fields will not be in inputs on confirm page
                FilledInState = SerialiseModel(amendDirectDebitVmPostedBack),

                LowellReference             = amendDirectDebitVmPostedBack.LowellReference,
                ClientName                  = amendDirectDebitVmPostedBack.ClientName,
                OutstandingBalance          = amendDirectDebitVmPostedBack.OutstandingBalance,
                RegularAccountPaymentAmount = amendDirectDebitVmPostedBack.DirectDebitAmount.Value,
                PlanFrequency               = amendDirectDebitVmPostedBack.PlanFrequency,
                PlanStartDate               = amendDirectDebitVmPostedBack.PlanStartDate,
                TermYears  = years,
                TermMonths = months
            };

            return(View("Confirm", amendDirectDebitConfirmVm));
        }
        public void Validate_WhenModelIsValid_ReturnsTrue()
        {
            AmendDirectDebitVm amendDirectDebitVm = new AmendDirectDebitVm()
            {
                OutstandingBalance      = 20.0m,
                DirectDebitAmount       = 10.0m,
                PlanFrequency           = "*freq",
                EarliestStartDate       = new DateTime(2018, 10, 4),
                LatestStartDate         = new DateTime(2018, 10, 6),
                PlanStartDate           = new DateTime(2018, 10, 5),
                SelectedPlanSetupOption = PlanSetupOptions.AverageSetupValue
            };

            Assert.IsTrue(_amendDirectDebitVmValidatorProcess.Validate(amendDirectDebitVm));
        }
 public void RaiseAmendDirectDebitEvent_DetailsSelected(AmendDirectDebitVm vm, string userId)
 {
     vm.GtmEvents.Add(new GtmEvent()
     {
         gtm_event             = GtmEvents.PaymentEvent,
         step                  = PaymentSteps.Step2NewPaymentDetailsSelected,
         payment_type          = "Amended Direct Debit",
         payment_amount        = vm.DirectDebitAmount,
         payment_detail        = vm.PlanFrequency,
         discount_available    = "No discount available",
         balance_selected      = "Full Balance",
         plan_type             = "Regular Account",
         guid                  = userId,
         user_status           = String.IsNullOrEmpty(userId) ? "Not Logged In" : "Logged In",
         payment_option_chosen = ConvertPlanSetupOption(vm.SelectedPlanSetupOption)
     });
 }
        public async Task <bool> AmendDirectDebitPlan(IUserIdentity loggedInUser,
                                                      IApplicationSessionState applicationSessionState,
                                                      Guid lowellReferenceSurrogateKey,
                                                      AmendDirectDebitVm amendDirectDebitVmWithUserEntries,
                                                      string caseflowUserId)
        {
            // Must be a logged in user
            if (loggedInUser.IsLoggedInUser == false)
            {
                throw new ApplicationException("AmendDirectDebitPlan can only be used for a logged in user due to requiring email address.");
            }

            // Reload from CaseFlow
            AmendDirectDebitVm amendDirectDebitVm = await _buildAmendDirectDebitVmService.Build(applicationSessionState, lowellReferenceSurrogateKey, caseflowUserId);

            // Populate user entries, giving a clean model to validate
            _buildAmendDirectDebitVmService.UpdateFieldsFromUserEntries(amendDirectDebitVm, amendDirectDebitVmWithUserEntries);

            if (!_amendDirectDebitVmValidatorProcess.Validate(amendDirectDebitVm))
            {
                return(false);
            }

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

            var directDebitPaymentDto = new DirectDebitPaymentDto
            {
                Frequency        = _directDebitFrequencyTranslator.TranslateClientScriptCompatibleValueToDescription(amendDirectDebitVm.PlanFrequency),
                LowellReference  = amendDirectDebitVm.LowellReference,
                PaymentAmount    = amendDirectDebitVm.DirectDebitAmount.Value,
                StartDate        = amendDirectDebitVm.PlanStartDate.ToShortDateString(),
                PlanTotal        = amendDirectDebitVm.OutstandingBalance,
                DiscountAmount   = amendDirectDebitVm.DiscountAmount,
                DiscountAccepted = amendDirectDebitVm.DiscountedBalance < amendDirectDebitVm.OutstandingBalance,
                EmailAddress     = loggedInUser.EmailAddress,
                User             = loggedInUser.IsLoggedInUser ? "WebUser" : "WebAnon"
            };

            await _sendAmendDirectDebitPlanProcess.SendAmendDirectDebitPlanAsync(directDebitPaymentDto);

            return(true);
        }
        public void ValidStateTest()
        {
            AmendDirectDebitVm vm = new AmendDirectDebitVm()
            {
                ClientName              = "Test Client",
                EarliestStartDate       = DateTime.Now.AddDays(-14),
                LatestStartDate         = DateTime.Now.AddDays(180),
                PlanStartDate           = DateTime.Now.AddDays(15),
                DirectDebitAmount       = 12.34M,
                LowellReference         = "12345678",
                PlanType                = "Direct Debit",
                PlanFrequency           = "Testing...",
                OutstandingBalance      = 500,
                SelectedPlanSetupOption = PlanSetupOptions.OtherPaymentOffer
            };

            ValidationResult result = _validator.Validate(vm);

            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(0, result.Errors.Count);
        }
        public void PaymentAmountGreaterThanBalance()
        {
            AmendDirectDebitVm vm = new AmendDirectDebitVm()
            {
                ClientName              = "Test Client",
                EarliestStartDate       = DateTime.Now.AddDays(-14),
                LatestStartDate         = DateTime.Now.AddDays(180),
                PlanStartDate           = DateTime.Now.AddDays(15),
                DirectDebitAmount       = 500.50M,
                LowellReference         = "12345678",
                PlanType                = "Direct Debit",
                PlanFrequency           = "Testing...",
                OutstandingBalance      = 500,
                SelectedPlanSetupOption = PlanSetupOptions.AverageSetupValue
            };

            ValidationResult result = _validator.Validate(vm);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual($"{ValidationMessages.AmountGreaterThenAllowed}500", result.Errors[0].ErrorMessage);
        }
        public void PaymentAmountNegative()
        {
            AmendDirectDebitVm vm = new AmendDirectDebitVm()
            {
                ClientName              = "Test Client",
                EarliestStartDate       = DateTime.Now.AddDays(-14),
                LatestStartDate         = DateTime.Now.AddDays(180),
                PlanStartDate           = DateTime.Now.AddDays(15),
                DirectDebitAmount       = -12.34M,
                LowellReference         = "12345678",
                PlanType                = "Direct Debit",
                PlanFrequency           = "Testing...",
                OutstandingBalance      = 500,
                SelectedPlanSetupOption = PlanSetupOptions.DisposableIncome
            };

            ValidationResult result = _validator.Validate(vm);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(ValidationMessages.InvalidAmount, result.Errors[0].ErrorMessage);
        }
        public void PlanFrequencyEmpty()
        {
            AmendDirectDebitVm vm = new AmendDirectDebitVm()
            {
                ClientName              = "Test Client",
                EarliestStartDate       = DateTime.Now.AddDays(-14),
                LatestStartDate         = DateTime.Now.AddDays(180),
                PlanStartDate           = DateTime.Now.AddDays(15),
                DirectDebitAmount       = 55.50M,
                LowellReference         = "12345678",
                PlanType                = "Direct Debit",
                PlanFrequency           = "",
                OutstandingBalance      = 500,
                SelectedPlanSetupOption = PlanSetupOptions.OtherPaymentOffer
            };

            ValidationResult result = _validator.Validate(vm);

            Assert.IsFalse(result.IsValid);
            Assert.AreEqual(1, result.Errors.Count);
            Assert.AreEqual(ValidationMessages.NoFrequencySelected, result.Errors[0].ErrorMessage);
        }
Exemple #14
0
        public async Task <IActionResult> Index(Guid id, AmendDirectDebitVm amendDirectDebitVmPostedBack)
        {
            // Restore VM from state field, so that we get lists and all other fields required to build view
            var amendDirectDebitVm = DeserialiseModel <AmendDirectDebitVm>(amendDirectDebitVmPostedBack.InitialState);

            Debug.Assert(amendDirectDebitVm.InitialState == null,
                         "Serialisation Loop Detected - InitialState should be marked as JsonIgnore");


            // Place form field selections into restored VM
            _buildAmendDirectDebitVmService.UpdateFieldsFromUserEntries(amendDirectDebitVm,
                                                                        amendDirectDebitVmPostedBack);
            await LogAmendDirectDebitOptionsSelected(amendDirectDebitVm);

            // Carry state through
            amendDirectDebitVm.InitialState            = amendDirectDebitVmPostedBack.InitialState;
            ApplicationSessionState.LogSetUpPlanResult = true;

            await LogAmendDirectDebitDetailsEntered(amendDirectDebitVm);

            return(await ProcessPost(id, amendDirectDebitVm));
        }
        public void Validate_WhenModelIsInvalid_ReturnsFalse()
        {
            AmendDirectDebitVm amendDirectDebitVm = new AmendDirectDebitVm();

            Assert.IsFalse(_amendDirectDebitVmValidatorProcess.Validate(amendDirectDebitVm));
        }