public async Task <ResultDto> CheckDirectDebitDetails(DirectDebitDetailsVm directDebitDetailsVm)
        {
            var bankAccountCheckerDetails = new BankAccountCheckerDto()
            {
                AccountNumber = directDebitDetailsVm.AccountNumber,
                SortCode      = directDebitDetailsVm.SortCode
            };
            var backAccountDetailsConfirmed = await _bankAccountCheckerProcess.CheckBankAccount(bankAccountCheckerDetails);

            _resultDto.IsSuccessful = false;
            if (backAccountDetailsConfirmed.ValidationResult == BankAccountValidationResult.AccountInvalid)
            {
                _resultDto.MessageForUser = BankAccountCheckerConstants.AccountInvalid;
                return(_resultDto);
            }
            if (backAccountDetailsConfirmed.ValidationResult == BankAccountValidationResult.ModulusCheckFailed)
            {
                _resultDto.MessageForUser = BankAccountCheckerConstants.ModulusCheckFailed;
                return(_resultDto);
            }
            if (backAccountDetailsConfirmed.ValidationResult == BankAccountValidationResult.SortCodeInvalid)
            {
                _resultDto.MessageForUser = BankAccountCheckerConstants.SortCodeInvalid;
                return(_resultDto);
            }

            _resultDto.IsSuccessful = true;
            return(_resultDto);
        }
        // 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(DirectDebitDetailsVm directDebitDetailsVm)
        {
            DirectDebitDetailsVmValidator validator = new DirectDebitDetailsVmValidator();
            ValidationResult result = validator.Validate(directDebitDetailsVm);

            return(result.IsValid);
        }
예제 #3
0
        // Generates cancel view required when click 'Cancel' on Direct Debit bank details page
        public IActionResult DirectDebitCancel(Guid id, DirectDebitDetailsVm directDebitDetailsVmPostedBack)
        {
            // Restore fields not included in form (see Cancel for explanation)
            var directDebitDetailsVm =
                DeserialiseModel <DirectDebitDetailsVm>(directDebitDetailsVmPostedBack.InitialState);

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

            // Carry state through
            directDebitDetailsVm.InitialState = directDebitDetailsVmPostedBack.InitialState;
            directDebitDetailsVm.PaymentOptionsFilledInState =
                directDebitDetailsVmPostedBack.PaymentOptionsFilledInState;

            // Place form field selections into restored VM
            _buildDirectDebitDetailsVmService.UpdateFieldsFromUserEntries(directDebitDetailsVm,
                                                                          directDebitDetailsVmPostedBack);

            // Construct model for Cancel view
            var cancelVm = new ReturnToFormVm
            {
                State                = SerialiseModel(directDebitDetailsVm),
                StateFieldName       = nameof(DirectDebitDetailsStateVm.FilledInState),
                StateType            = nameof(DirectDebitDetailsVm),
                ReturnControllerName = ControllerName,
                ReturnActionName     = nameof(DirectDebitChange)
            };

            return(View("PaymentCancel", cancelVm));
        }
예제 #4
0
 public void UpdateFieldsFromUserEntries(DirectDebitDetailsVm paymentOptionsToUpdate, DirectDebitDetailsVm paymentOptionsUserEntries)
 {
     paymentOptionsToUpdate.AcceptDirectDebitGuarantee = paymentOptionsUserEntries.AcceptDirectDebitGuarantee;
     paymentOptionsToUpdate.AccountHoldersName         = paymentOptionsUserEntries.AccountHoldersName;
     paymentOptionsToUpdate.AccountNumber = paymentOptionsUserEntries.AccountNumber;
     paymentOptionsToUpdate.SortCode      = paymentOptionsUserEntries.SortCode;
 }
        public void Validate_WhenModelIsInvalid_ReturnsFalse()
        {
            DirectDebitDetailsVm directDebitDetailsVm = new DirectDebitDetailsVm()
            {
            };

            Assert.IsFalse(_directDebitDetailsVmValidatorProcess.Validate(directDebitDetailsVm));
        }
        private async Task LogDiscountDirectDebitCancelled(DirectDebitDetailsVm directDebitDetailsVm)
        {
            var paymentOptionsVm = ConvertToPaymentOptionsVm(directDebitDetailsVm.PaymentOptionsFilledInState);

            if (paymentOptionsVm?.SelectedPlanSetupOption != null)
            {
                switch (paymentOptionsVm.SelectedPlanSetupOption.Value)
                {
                case PlanSetupOptions.AverageSetupValue:
                {
                    await _webActivityService.LogDiscountDirectDebitPaymentASVOptionCompleteCancelled(
                        paymentOptionsVm.LowellReference,
                        LoggedInUserId);

                    break;
                }

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

                    break;
                }

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

                    break;
                }
                }
            }
        }
 public void Initialise()
 {
     _validator            = new DirectDebitDetailsVmValidator();
     _directDebitDetailsVm = new DirectDebitDetailsVm()
     {
         AcceptDirectDebitGuarantee = true,
         AccountHoldersName         = "Mr Test",
         AccountNumber = "12345678",
         SortCode      = "123456"
     };
 }
        public void Validate_WhenModelIsValid_ReturnsTrue()
        {
            DirectDebitDetailsVm directDebitDetailsVm = new DirectDebitDetailsVm()
            {
                AccountHoldersName         = "abc",
                AccountNumber              = "12345678",
                SortCode                   = "123456",
                AcceptDirectDebitGuarantee = true
            };

            Assert.IsTrue(_directDebitDetailsVmValidatorProcess.Validate(directDebitDetailsVm));
        }
        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)
            });
        }
    }
}
 public void RaiseDirectDebitEvent_OptionsSelected(DirectDebitDetailsVm vm, string userId, string planType)
 {
     vm.GtmEvents.Add(new GtmEvent()
     {
         gtm_event             = GtmEvents.PaymentEvent,
         step                  = PaymentSteps.Step2PaymentOptionsSelected,
         payment_type          = "Direct Debit Plan",
         payment_amount        = vm.PaymentAmount,
         payment_detail        = vm.PaymentFrequency,
         discount_available    = vm.DiscountAvailable ? "Discount available" : "No discount available",
         balance_selected      = vm.DiscountSelected ? "Discounted Balance" : "Full Balance",
         plan_type             = planType,
         plan_status           = "New Plan",
         guid                  = String.IsNullOrEmpty(userId) ? null : userId,
         user_status           = String.IsNullOrEmpty(userId) ? "Not Logged In" : "Logged In",
         source_of_funds       = null,
         payment_option_chosen = ConvertPlanSetupOption(vm.SelectedPlanSetupOption)
     });
 }
예제 #11
0
        public async Task <IActionResult> DirectDebit(Guid id, DirectDebitDetailsVm directDebitDetailsVmPostedBack)
        {
            // Restore fields not included in form (see One-Off for explanation)
            var directDebitDetailsVm =
                DeserialiseModel <DirectDebitDetailsVm>(directDebitDetailsVmPostedBack.InitialState);

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

            // Round-trip stashed view model state
            directDebitDetailsVm.InitialState = directDebitDetailsVmPostedBack.InitialState;
            directDebitDetailsVm.PaymentOptionsFilledInState =
                directDebitDetailsVmPostedBack.PaymentOptionsFilledInState;

            _buildDirectDebitDetailsVmService.UpdateFieldsFromUserEntries(directDebitDetailsVm,
                                                                          directDebitDetailsVmPostedBack);

            ApplicationSessionState.LogSetUpPlanResult = true;
            return(await ProcessDirectDebitDetailsPost(id, directDebitDetailsVm));
        }
        public DirectDebitPlanOverviewVm Build(PaymentOptionsVm accountVm, DirectDebitDetailsVm directDebitDetailsVm)
        {
            // Should never be null, as validated with Fluent
            Debug.Assert(accountVm.DirectDebitAmount != null, "accountVm.DirectDebitPayment.Amount != null");

            int totalMonths = _directDebitTermCalculator.CalculateTermInMonths(
                accountVm.FullPaymentAmountDerived, accountVm.DirectDebitAmount.Value,
                accountVm.DirectDebitSelectedFrequency);
            int years  = totalMonths / 12;
            int months = totalMonths % 12;

            DirectDebitPlanOverviewVm directDebitPlanOverview = new DirectDebitPlanOverviewVm()
            {
                SortCode           = directDebitDetailsVm.SortCode,
                AccountNumber      = directDebitDetailsVm.AccountNumber,
                AccountHoldersName = directDebitDetailsVm.AccountHoldersName,
                ClientName         = accountVm.ClientName,
                LowellReference    = accountVm.LowellReference,
                PaymentAmount      = accountVm.DirectDebitAmount.Value,
                PaymentType        = AccountMessages.DirectDebit,
                StartDate          = accountVm.DirectDebitSelectedStartDate,
                Frequency          =
                    _directDebitFrequencyTranslator.TranslateClientScriptCompatibleValueToDescription(
                        accountVm.DirectDebitSelectedFrequency),
                GuaranteeRead = directDebitDetailsVm.AcceptDirectDebitGuarantee,
                PlanTotal     = accountVm.DiscountedBalancePreviouslyAccepted
                    ? accountVm.DiscountedBalance
                    : accountVm.OutstandingBalance,
                DiscountAccepted        = accountVm.DiscountAccepted,
                DiscountAmount          = accountVm.DiscountAmount,
                EmailAddress            = accountVm.DirectDebitEmailAddress,
                DiscountAvailable       = directDebitDetailsVm.DiscountAvailable,
                PaymentFrequency        = directDebitDetailsVm.PaymentFrequency,
                TermYears               = years,
                TermMonths              = months,
                SelectedPlanSetupOption = directDebitDetailsVm.SelectedPlanSetupOption
            };

            return(directDebitPlanOverview);
        }
예제 #13
0
        private async Task <IActionResult> ProcessDirectDebitDetailsPost(Guid lowellReferenceSurrogateKey,
                                                                         DirectDebitDetailsVm directDebitDetailsVmWithUserEntries)
        {
            if (!ModelState.IsValid)
            {
                Debug.Assert(directDebitDetailsVmWithUserEntries.InitialState != null,
                             "Initial state must be stashed to re-create view on round-trip");
                return(View(directDebitDetailsVmWithUserEntries));
            }

            //TODO: Change to async
            var result =
                await _directDebitPlanSetupService.CheckDirectDebitDetails(directDebitDetailsVmWithUserEntries);

            // Restore Payment Options from state embedded in Direct Debit VM
            PaymentOptionsVm paymentOptionsVm = DeserialiseModel <PaymentOptionsVm>(directDebitDetailsVmWithUserEntries.PaymentOptionsFilledInState);

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

            if (!result.IsSuccessful)
            {
                directDebitDetailsVmWithUserEntries.MessageForUser = result.MessageForUser;

                if (ApplicationSessionState.LogSetUpPlanResult)
                {
                    if (directDebitDetailsVmWithUserEntries.DiscountSelected)
                    {
                        await LogDiscountDirectDebitCompleteFailure(paymentOptionsVm);
                    }
                    else
                    {
                        await LogDirectDebitCompleteFailure(paymentOptionsVm);
                    }

                    ApplicationSessionState.LogSetUpPlanResult = false;
                }

                return(View(directDebitDetailsVmWithUserEntries));
            }

            DirectDebitPlanOverviewVm directDebitPlanOverview = _buildDirectDebitPlanOverviewVmService.Build(paymentOptionsVm, directDebitDetailsVmWithUserEntries);

            // Need to stash direct debit model, so that we can round-trip when 'change' options are selected on confirmation screen.
            Debug.Assert(!string.IsNullOrEmpty(directDebitDetailsVmWithUserEntries.PaymentOptionsFilledInState),
                         "Stashed model MUST contain stashed payment options model, so that it can be round-tripped back to Payment Options if choose to change that");

            directDebitPlanOverview.DirectDebitDetailsFilledInState =
                SerialiseModel(directDebitDetailsVmWithUserEntries);

            _gtmService.RaiseDirectDebitEvent_BankDetails(directDebitPlanOverview, LoggedInUserId, "Direct Debit Plan");

            if (directDebitDetailsVmWithUserEntries.DiscountSelected)
            {
                await LogDiscountDirectDebitDetailsEntered(paymentOptionsVm);
            }
            else
            {
                await LogDirectDebitDetailsEntered(paymentOptionsVm);
            }



            return(View("DirectDebitConfirm", directDebitPlanOverview));
        }